Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 465 Vote(s) - 3.6 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ basics part 1

#1
Before I begin i'd like to say this is 100% MINE i am just transferring it from SF


Hey all, here is a basics tutorial for c++:

_________________________________
The basic syntax

c++ may seem like a scary language but in reality, its just like any other programming language, it has a main function and a proper syntax. For example, the most basic program in c++ is:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


see! not so bad Laugh... Lets look at this piece by piece,



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

this is needed so that you can perform the basic functions of a program (print, if statements, input, etc.)



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


std is the standard 'namespace' in c++, this is also used in every program so that the basic functions of a program can be performed.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


this is the main method, in java this would be public static void main(String[] args). As you can see, this function uses brackets to show where the code should go, these are called body-brackets, all your code should be inside the body brackets of functions.In addition, you can see the 'return 0;' inside this code brackets, this tells the compiler that whenever it gets to there that the code is finished and it should terminate the program with status report '0'. a ';' is placed at the end of the line to tell the compiler that there will be no more code on that line. The return statement IS NOT NEEDED in all programs.
_________________________________
Hello World!

c++ is like any normal programming language, it has a printing function, an input function, arrays, lists, etc. However, the first thing we will be learning is the printing function for c++:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


the above code will print out "Hello World!!". In this line of code, 'cout' means "console-out" and << is telling the compiler that after the print statement (cout), text will need to be read. Futhermore, "endl" means 'end line' which creates a new line, you can also do this in the line of code with '\n':

Code:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


both will come out with the following in your command prompt:

uoirghjeiogjwepigAutoGeneratedCommandPromptText4ryghurgijrg
Hello World!!

press any key to continue...
_________________________________
comments



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


A comment is a line within the code that the compiler does not read, it is made for the creator and any other people who should happen to see the source code. Comments are mainly used to explain what a line of code/ block of code does. For Example:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

_________________________________
variables

Just like every programming language, c++ has some basic variables these are:

string - a line of text
int - a whole number
double - a number with decimals
float - an extremly long number with decimals
char - a single charachter, such as 'a' or '!'


All of these can be used together in the following way:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

this will print out:

Code:
Hello, my name is Daniel and I am 15 and it is 7.59 o'clock!

this is because, we used the << operator to append (add) all the variables we created to the original string of text in front of the cout statement.
_________________________________
math

like anything in life, math is a large part of programming. In c++ the math operators are:

+ || addition
- || subtraction
* || multiplication
/ || division
% || get the remainder of something
< || less then
> || greater than
<= || less then or equal to
>= || greater than or equal to


this can used to make a simple calculator:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


you can also do this within the print statement:



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

_________________________________
user input

User input is basically the user entering a string or a number and it/them being set as integers to be used in another time. To do this we use the 'cin' operator which means console-in.

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


this program will print out whatever name you specified. As you can see, instead of << like we use in cout, for cin we use >> and then the variable name.
_________________________________
calculator

Now we will be making a basic addition calculator program with user input.



Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

_________________________________

That is all for part 1, in part 2 I will be covering loops, if statements and recursion.

I hope you liked this tutorial!
Reply

#2
Holy hell! Who created these languages and why do they have to be like this?

It looked like a good guide anyway if I knew what I was reading.
Reply

#3
It's better than the lower levels.

Oh, you want to print "hi" in ASM on Windows?

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply

#4
Nice tutorial, Keep it up. And indeed low level programing languages such as ASM are a lot more complex than C++ in my opinion.
Reply

#5
I wouldn't say more complex, because it's fairly straightforward what every operation does, but certainly more tedious.
Reply

#6
Fair tutorial, however it could prove to be more useful to new programmers if you'd explain things better.

For example,
Quote:
Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


std is the standard 'namespace' in c++, this is also used in every program so that the basic functions of a program can be performed.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


You neglect to explain what a namespace actually is or what the 'using' keyword actually indicates to the compiler. In addition to this, to access the functions in the 'std' namespace, one does not have to declare 'using namespace std'.


You can access the functions, objects and whatnot simply by doing this:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


I just feel as if that is worthy of a small mention, at least.


Also,
Quote:Just like every programming language, c++ has some basic variables these are:

string - a line of text
int - a whole number
double - a number with decimals
float - an extremly long number with decimals
char - a single charachter, such as 'a' or '!'


You should not have mentioned the string object before getting to the subject of arrays (since a string is basically an array of characters). It would have been a lot better for the new programmers to learn about characters, arrays then arrays of characters before making use of C++'s string class. In addition to that, there are a number of differences in functionality between C-style strings and C++ style strings. These differences are very important for the readers to understand and become aware of.

C-style string:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



Making use of the C++ string class:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.




Also, you probably should have mentioned the range and size of each basic data type. Probably throw in some better descriptions as well...

Just a very simple example of what I think you should have displayed to the newbie programmers:
Quote:char - This data type can hold a single character of size 1 byte.

int - This data type can hold an integer of size 4 bytes. An integer stored in a variable of this data type can be as small as -2147483648 to as large as 2147483647.

bool - This data type can hold a boolean value of size 1 byte. A boolean is a logical data type which can only contain two values: true or false.

... etc.

I'm not going to list all of the basic data types that a beginner should be familiar with, so I'll direct anyone reading this to a couple of useful links:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.




In conclusion, I found the tutorial was pretty alright. Just required a lot more explanation. Not only that, but by making a basic C++ tutorial you should always assume that your readers are complete beginners unless you specify otherwise.
Reply

#7
I like it i might want to learn coding ill keep this tutorial in mind!
Reply

#8
Quote:(09-14-2013, 12:30 AM)Aristotle Wrote:

[To see links please register here]

-snip-

Beat me to it.

Also, what the fuck are these comments?


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Use something like:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Or:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

Reply

#9
Quote:
Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

this is needed so that you can perform the basic functions of a program (print, if statements, input, etc.)

Ahh, no... :S Basic functions of a program, printf, if statements, input, etc...? It has nothing to do with if statements.

Quote:string - a line of text
int - a whole number
double - a number with decimals
float - an extremly long number with decimals
char - a single charachter, such as 'a' or '!'

Is this implying that float is used for larger precision than double??? And string, a line of text? :S


Quote:(09-14-2013, 12:37 AM)Cyanide and Cynicism Wrote:

[To see links please register here]

Beat me to it.

Also, what the fuck are these comments?


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Use something like:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


Or:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

What does it matter? You're doing the same thing as what he wrote, and the first qualifies as a comment just as much as the double slash variation, it's preference.
Reply

#10
Quote:(09-19-2013, 03:15 AM)cxS Wrote:

[To see links please register here]

What does it matter? You're doing the same thing as what he wrote, and the first qualifies as a comment just as much as the double slash variation, it's preference.

Because it looks gross.
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through