Pshyotic

C++ Tutorial - Learn how to program on cracked.to

Recommended Posts

I will work to answer this thread every day in this same thread with a new tutorial, so everything will happen in this topic and there will not be another topic open.


 

Hello everyone, here we are in the new tutorial of the C ++ programming language.

 

 

 

DON'T FORGET TO LEAVE LIKE 

heart5.png

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

 

 

PART 1.

 

 

[hide]

What you definitely need as far as the theory is concerned is the following:

1.What is programming?

-Programming is how to write instructions to a computer what to do and how to do it and run in one of the programming languages. Programming is art and craft in creating computer programs. Creating a program contains elements of design, art, science, mathematics as well as engineering. The person who creates the program is called the developer.

 

2.What are the variables ?

-Variable (or variable) is a unit given or information in a computer program that can change the value during program execution. The opposite term is a constant or invariable representing a unit given, that is, information that does not change during the execution of the program. (We will speak more about variables in example later where will I give you one explanation and simplify this definition.)

 

3.What is compiler ?

-The language translator (including translator, translator, program translator, program translator, compiler, and colloquially often compiler) is a computer program that reads the program written in the original language and translates it into the equivalent program in the target (most commonly used) language .

 

So, we should now go on basic thing about C++ .

We have to know types of variable in C++ (which are also known as Data types and they are very important in every single programming lang.).

 

 

And probably you will wonder now, what will these numbers mean to me and what's all this on this picture.

So here is one explanation about variables:

 

How do I understand variables?

Imagine that you have one box in which we put our things and of course they occupy a certain space on our waist, floor and the like. So the variables in it include a certain data and that variable occupies a certain part of the computer memory.

I turn back to the picture, these numbers you see, they actually represent how much a particular type of data takes memory and we have to be very careful when we use that variable. For example, the type of int (integer) data has 16 bits and can crawl numbers such as 0,1,2,3,4,5,6,7,8,9,10,11 ... and so on enter the number: 50439412321342 program will collapse and it is called overflow, and it happens very often to new developers, so every type of data has a certain maximum number that it can go to.

What if one integrer type variables joined 12.99? The program would not collapse however it would have been that if you would print that variable in our console, only number 12 would be printed without this residue, 99 ... Wondering why?

Again, it is a matter of data type, the type of data integer (int) does not have the scope to save the number with a decimal comma, because there are types of data such as float, double etc. but we will talk about it a little later. For now, before catching any serious programming, it's enough to remember the type of data: int and float or double.

 

Now let's go to the concrete example that all of us programmers have passed (or at least most of us when we are learning a new programming language).

 

//first c++ program
#include 
using namespace std;

int main() 
{
   cout << "Hello, World!";
   return 0;
}

 

So let's go and analyze this code. 

//first c++ program

These are actually comments and they do not play any role in the compiler, which means the compiler does not see them and circumvent them and goes to our code. Programmers use them to include short explanations or observations on the code or program. In this case, it is a brief introductory description of the program.

 

#include

What does this actually do #include ?

Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case, the directive #include , instructs the preprocessor to include a section of the standard C ++ code known as header iostream, which allows to perform standard input and output operations such as writing the output of this program ) to the screen.

 

It actually include (the same meaning), the iostream header (or the input / output stream library that serves us to perform the cout actions and the steps we will touch a little later). So this line of code tells our pre-processor to include that library (look it up where we installed our program, compiler ... eg CodeBlocks, Visual Studio etc ...). 

How can you also understand this is the following example.

 

I believe that you all played Counter Strike 1.6, and when you enter the server, note that those lines are full and you see that something is reading something and that the game is "loaded" without the download, that some programmer forgot to type #include , you probably would not have a weapon in your hands. So also here in this program, without  #include you would have left without your "weapon" ie without your text and I would get you an error or BUG.

 

Without this line of code our cout << "Hello, World!"; it would not work and get what every programmer hates most and what every nightmare programmer is, and that's BUG. What will cause BUG? Well just because there is no input / output stream library ... What are the libraries? Libraries are actually (in programming) certain codes written by people that we should not always have to write a code for printing / entering data and similar things. Just imagine how hard it would be to write it all over again just to print some text in the console. That's why some programmers have deprived us of this tedious job by writing that code and giving us this library that is automatically installed with each program you use to write the program. 

 

 

 

using namespace std; 

In C ++ there are a set of functions that are needed by many users and are regularly delivered with the program. A set of all such standard functions is called a common library called the standard library. The functions of the standard library are not located in one library but are located in various libraries but are all, agreed, marked with an additional name std. This is not necessary for us to write, but then we will add more writing, so without using namespace std; this code looked like this:

 

#include 

int main()
{
 std::cout << "Hello World!";
}

 

Here, you do not seem to look very tired here, but imagine that your code has 200 lines of code and you have to write "std::"

 

int main()

{

Now let's go back to the first part of the code.

int main ()

{

which could look like:

int main () {

Just to say there are no differences between these two, but there are some developers in the code as in the first case, and some like everything else is a taste and of course none of these is wrong and will not affect your code. This line initiates the declaration of a function. Essentially, a function is a group of code statements that are given a name: in this case, this gives the name "main" to the group of code statements that follow. Functions will be discussed in detail in a later chapter, but essentially, their definition is introduced with a succession of type (int), a name (main) and a pair of parentheses (()), optionally including parameters.

The function named main is a special function in all C ++ programs; it is the function called when the program is run. The execution of all C ++ programs begins with the main function, regardless of where the function is actually located within the code.

 

Next, we'll get the parameters but the "function" that looks like this without any code inside it:

int main()
{

}

This function MUST have each code, because that's what you see MAIN FUNCTION. We will also have some functions later on, so I'll explain you more later.

{ and } .

The open brace ( { ) at line 5 indicates the beginning of the main function definition, and the closing brace ( } ) at line 7, indicates its end. Everything between these braces is the function's body that defines what happens when the main is called. All functions use braces to indicate the beginning and end of their definitions.

 

cout<<"Hello, World!";

This line is a C ++ statement. A statement is an expression that can actually produce some effect. It is the meat of a program, specifying its actual behavior. Statements are executed in the same order that they appear within a function's body.

 

The insertion operator (<<), which indicates that what follows is inserted cout. Finally, a sentence within quotes ("Hello world!") is the content inserted in the standard output.

 

Notice that the statement ends with a semicolon (;). This character marks the end of the statement, just as the period ends in a sentence in English. All C ++ statements must end with a semicolon character. One of the most common syntax errors in C ++ is forgetting to end an statement with a semicolon.

 

int main () { cout << "Hello World!"; }

Also, this code we could write and so, however, as you see it and not very straightforward. Yet neatness is all.

 

return 0;

returns 0, a common way to say "if you have reached this point, no error has occurred"

 

And that's actually it. 

Another thing as far as the comments are concerned. You have this kind of comment:

//Bla Bla Bla

and a comment ("//") means that as long as we type in the current line any compiler will ignore it.

However if we write

// Bla Bla Bla (and then skip to the next row and write anything else, the compiler will make a mistake (BUG)).

 

The second type of comment is:

/ * * /

In this type of commentary you can write everything you want wherever you want in / * * / and until you exit * /, the compiler will not flash.

Example of correct comment:

/ *

Bajsifa

dfkogsd

daslpfadfdfdfdf

* /

 

 

An example of incorrect comment

/ * Bajsifa * /

dfkogsd

daslpfadfdfdfdfd

 

After this you get a mistake in the compilation.

 

That would be all for this tutorial. If I forgot something I would ask the developers to add that. [/hide]

 

[align=center]That would be all for this tutorial.

 

I hope you enjoyed and of course learned something new.[/align]

Share this post


Link to post
Share on other sites

Hello everyone, here we are in the new tutorial of the C ++ programming language.

[align=center]

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

please contact PM (Private Messages) or answer here on my topic so I can help you.[/align]

 

PART 2.

 

[hide]

Okay here we begin with another stuffs. Now we will talk about variables again as well as see a small program later.

 

 

As I have already mentioned, we use int data type for whole numbers:

 

int - we use for whole numbers as I said.

 

Float and double - we use for numbers with decimal leftovers (The difference between float and double is of course the memory occupied)

Char and string - We use for just some words or letters or text, and now I'll just write a few examples where we initialize the variable, declare it and assign the value (declare and define it). So the variables that we (the developers) set for the value and do not let the user enter the variable value of the keypad, we call INICIALIZATION.

 

Example of declaring and inicialization of variables of different data types:

int a==3;
float b==2.0;
double c=2.124352;
char=='a'; 
string=="Here is going some text";

 

 

I am sure that you saw this char=='a'; 

char type is always mentioned with these characters ( ' ' ) because it is a single character, unlike the words we write

between quotation marks " ", the words are in c ++ - in string(s) and we will talk about string(s) later.

 

What I've forgotten to mention in the last tutorial is actually the name of the variable, the name of the variable can be the way you want to give the variable name, try to give the names exactly as this variable is used to make it easier for you to enter the code. It is important that you enter the name of the variable that you gave her the name when you declared it, so in capital letters, because the compiler is all different.

Selecting the names of the variables is that you can not use the keywords of the c ++ language itself (commands and the rest that refers to the constituent part of the language itself) and try not to work in spaces rather than say my_variable and so on.One benefit is that if you use a C ++ language, it will become blue in the program where you write the code so that you can easily notice it.

 

You will now be able to see down one code to do addition of two numbers:

 

#include 
using namespace std;

int main()
{
      int num1 = 4;
      int num2=3;
      int sum;
      c=x+y;  //here we did addition
      cout<<"Sum of num1 and num2 is : "<     system("PAUSE");
    return 0;

}

 

Okay so I told you that is probably better to use descriptive variables name so I did too. We did declaration and inicialization on beggining, after that we declared new variable and her name is sum (And point of this is that everything needs variable, sounds scary but it's not... you'll learn).

After that we wrote formula, to give instructions to our computer what will he should do with our variables and he did addition. As you can see there is: sum=num1+num2;

 

 

What is the most important thing and need explanation (I won't begginers get confused) is that cout<< 

Okay, so whenever we want to print something on console we have to write this cout<< , after this if you want some text you need to add this ( "  " ) , and betwen these two you need to input your text. We could did this code without any text printing on console, just sum of this two numbers and that would look like: 

 

cout<

 

[color=#3333cc][b]And printing in the first code would be as follows:[/b][/color]

[b][color=#3399ff]Sum of num1 and num2 is: 7[/color][/b]

 

 

[color=#99cc33][b]What you have noticed on ending is probably [/b][/color][color=#99cc33][b]this:[/b][/color][color=#99cc33][b] [/b][/color][color=#33ffff]<

"[color=#33ffff]<< endl;[/color]" [color=#ff3333]tells the compiler that whatever the next one is printed in the console needs (and will be) printed in a new line. [/color]

 

[color=#3333cc][b]You should try to copy the first code in this reply and paste him in your code editor and after printing sum of our two sums, add new line in our code and print something like:[/b][/color]

 

[color=#33ffff]cout<<"Blaaah"; [/color]

[color=#33ffff]cout<<"NewLine";[/color]

 

[color=#3333cc][b]and output now will be:[/b][/color]

 

[color=#3399ff][b]Sum of num1 and num2 is: 7[/b][/color]

[color=#3399ff][b]BlaaahNewLine[/b][/color]

 

[color=#ff3333]and this is reason why we add "[/color][color=#33ffff]<

[/hide]

 

 

 

[center][size=x-large][font=roboto, sans-serif][color=#3333cc]That would be all for this tutorial.[/color][/font][/size][/center]

[center][size=medium][font=roboto, sans-serif][color=#3333cc]I hope you enjoyed and of course learned something new.[/color][/font][/size][/center]

Share this post


Link to post
Share on other sites

Hello everyone, here we are in the new tutorial of the C ++ programming language.

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

Also the link from which you can download Code :: Blocks and Visual Studio:

Code::Blocks: http://codeblocks.org/downloads

 

DON'T FORGET TO LEAVE LIKE <3

SO LET'S GO BACK ON OUR TUTORIAL 

 

PART 3:

 

[hide]

 

So far, we have met orders:  cout<< and <

What is it actually <<, this is actually one of the characters (operator) that the data goes to the exit under the command cout - meaning the output.

Similarly, the <

 

Today we will do a new command, and that's  cin>>

 

 

1.What does that command actually do?

It serves us to enter data from the screen through the keyboard and then of course prints with the command cout.

However, we do not write like cin<<, because this (<<) operator serves for the data flow from the computer (memory) to the screen and we have to first input the data from the keyboard and then just print it.

 

But for cin we use operator >> (of course with the cin command):

cin>>num1;

 

Just like that and again you should notice that ; on the end of this line.

 

And we will print him on console screen with command:

cout<

 

[center][color=#ff3333]Just to don't make you confused, you could write this line of code like ( [/color][color=#33ffff]cout<


[center][color=#3333cc]***Try more variations and test it yourself***[/color][/center]

 
 
[color=#ff3333]All we mentioned is in the [/color][color=#33ffff][/color][color=#ff3333] (standard I / O) header of which we talked about in the first tutorial.[/color]
 

[center][color=#3333cc]Do yo[/color][color=#3333cc]u remember the code from the last tutorial (part 2)?[/color][color=#3333cc] In which we wrote a program in which we did addition of two numbers, but we have initialized the variables in that last code.[/color][/center]

 

[center][color=#3333cc]Are you for modifying a code slightly and allowing the user to enter the number itself? If your answer is yes, keep reading...  [/color]:ezy:[color=#aaaaaa] [/color][/center]

 
 
[code]#include 

using namespace std;

int main()


{

     int num1;
     int num2;
     int sum;
     cout<<"Enter first number : "<      cin>>num1;

     cout<
     cout<<"Enter second number :";
     cin>>b;

     cout<
     sum=num1+num2;
     cout<<"Sum of number1 and number2 is : "<
     system ("PAUSE");
     return 0;

  }

Share this post


Link to post
Share on other sites

Nice moving :)

I will be following, and in the future, do some games in C++ for us :D

Just 1 advice, use better colours, 1 colour for questions and so on :)

Share this post


Link to post
Share on other sites

Nice moving :)

I will be following, and in the future, do some games in C++ for us :D

Just 1 advice, use better colours, 1 colour for questions and so on :)

 

@TheCrazy Fixed and edited. Thanks for advice <3 I hope it's much better now.

Share this post


Link to post
Share on other sites

Nice moving :)

I will be following, and in the future, do some games in C++ for us :D

Just 1 advice, use better colours, 1 colour for questions and so on :)

 

@TheCrazy Fixed and edited. Thanks for advice <3 I hope it's much better now.

 

Change the red colour and it will be perfect :D

Don't use strong colours like red , use smooth, like.... this one! 

Share this post


Link to post
Share on other sites

Hello everyone, here we are in the new tutorial of the C ++ programming language.

[align=center]I did not posted anything for about 4 days, so it's time.

[/align]

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

 

PART 4.

 

 

 

[hide]

 

Okay, so with the previous code we can also do multiplying, dividing and subtractation. You should try to do this.

So, for multiply operator is:  *   (of course it is lmao) 

      for dividing operator is:  / 

      for subtractation  operator is: -

 

CODE:

#include 

using namespace std;

int main()


{

    int num1;
    int num2;
    int sum;
    cout<<"Enter first number : "<     cin>>num1;

    cout<
    cout<<"Enter second number :";
    cin>>b;

    cout<
    sum=num1*num2;  //Here we changed + in *
    cout<<"Sum of this two numbers is : "<
    system ("PAUSE");
    return 0;

 }

 

Try to change cout<<"Sum of this two numbers is : "<

cout<

 

[color=#3333cc][b]What happend ? [/b][/color]

[color=#33ffff]Okay, so we just printed variable num1 which is entered by user and after that added  [/color][color=#ff3333]" * "[/color][color=#33ffff] (we already knew that [/color][color=#33ffff]the operation that the user is going to do is multiply so we putted [/color][color=#ff3333]*[/color][color=#33ffff] (sign for multiply) in [/color][color=#ff3333]" * "[/color][color=#33ffff] which means, that will always show [/color][color=#ff3333]*[/color][color=#33ffff] after printing value of first variable and after value of variable [/color][color=#33cc33]num2[/color][color=#33ffff]. After this we putted sign of equalation[/color][color=#33ffff] ( [/color][color=#ff3333]=[/color] [color=#33ffff]) (do not let this confuse you, now we just print the equality on the screen and we didn't join value in the code, so whenever we add value to a variable we put [/color][color=#ff3333]==[/color][color=#33ffff]) and output in console will be:[/color]

 

 

[color=#3399ff]Enter first number: 4  //(I just give an example, the user could enter any other number).[/color]

[color=#3399ff]Enter second number: 2  //again example[/color]

[color=#3399ff]4 * 2 = 8    //That is final output when he did multiplying[/color]

 

[color=#33ffff]So that is what I wanted to show you what you can do also.[/color]

[color=#33ffff]Also for programmers who have not Windows, the command for [/color][color=#33cc33]system("pause"); [/color][color=#33ffff]   is:[/color]

[color=#33ffff]You first must have declared one variable on begin:  example: [/color]

[color=#33cc33]char pause;[/color]

[color=#33ffff]and on the end of program you have to put:[/color]

[color=#33cc33]cin>>pause;[/color][color=#33ffff]   everything other is same.[/color]

 

 

[color=#33ffff]For residual numbers (for example, 3.34) you will need to use another type of data, such as [/color][color=#ff3333]float[/color][color=#33ffff] or [/color][color=#ff3333]double[/color][color=#33ffff], just change all int's into [/color][color=#ff3333]float[/color][color=#33ffff] or [/color][color=#ff3333]double[/color][color=#33ffff]. [/color]

 

[center][b][color=#3333cc]I still do not want to bother you with data types and theory, but if you want  I can write the theory or if any of my colleagues[size=medium][font=arial, sans-serif] [/font][/size]programmers want to do it, feel free, it will be my glad.[/color][/b][/center]

 

 

[/hide]

[center][color=#3333cc][size=x-large][font=roboto, sans-serif]That would[/font][/size][/color][color=#3333cc][size=x-large][font=roboto, sans-serif] be all for this tutorial.[/font][/size][/color][/center]

 

[center][color=#3333cc][font=roboto, sans-serif]I hope you enjoyed and of course learned something new.[/font][/color][/center]

Share this post


Link to post
Share on other sites

excellent, but it would be even more with other colors

Share this post


Link to post
Share on other sites

I've been coding in C++ for a few years now, but it's always nice to check out tutorials. You can always learn something new, and if not you can refresh the knowledge. Thanks for sharing OP!

Share this post


Link to post
Share on other sites

Thanks for this Bro

Share this post


Link to post
Share on other sites

lets see what i can learn

Share this post


Link to post
Share on other sites

Thank you <3

Share this post


Link to post
Share on other sites

:feelsgood: :feelsgood: :feelsgood: :feelsgood: :feelsgood: :feelsgood: :feelsgood: :feelsgood: :feelsgood: :fine: :fine: :fine: I will work to answer this thread every day in this same thread with a new tutorial, so everything will happen in this topic and there will not be another topic open.


 

Hello everyone, here we are in the new tutorial of the C ++ programming language.

 

 

 

DON'T FORGET TO LEAVE LIKE 

heart5.png

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

 

 

PART 1.

 

 

[/align]

 

[align=center]That would be all for this tutorial.

 

I hope you enjoyed and of course learned something new.[/align]

 

Share this post


Link to post
Share on other sites

I will work to answer this thread every day in this same thread with a new tutorial, so everything will happen in this topic and there will not be another topic open.


 

Hello everyone, here we are in the new tutorial of the C ++ programming language.

 

 

 

DON'T FORGET TO LEAVE LIKE 

heart5.png

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

 

 

PART 1.

 

 

[/align]

 

[align=center]That would be all for this tutorial.

 

I hope you enjoyed and of course learned something new.[/align]

 

 

I hope its a great tutorial

Share this post


Link to post
Share on other sites

cool, needed it

Share this post


Link to post
Share on other sites

jogiinsploit

Share this post


Link to post
Share on other sites

Thanks a lot bro

Share this post


Link to post
Share on other sites

I will work to answer this thread every day in this same thread with a new tutorial, so everything will happen in this topic and there will not be another topic open.


 

Hello everyone, here we are in the new tutorial of the C ++ programming language.

 

 

im interested

DON'T FORGET TO LEAVE LIKE 

heart5.png

 

If you have any questions about some of the previous tutorials or questions for this tutorial, 

 

please contact PM (Private Messages) or answer here on my topic so I can help you.

 

 

 

PART 1.

 

 

[/align]

 

[align=center]That would be all for this tutorial.

 

I hope you enjoyed and of course learned something new.[/align]

 

Share this post


Link to post
Share on other sites

thanks buddy but need more effort

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.