C++ tutorial
2 posters
Page 1 of 1
C++ tutorial
Hello guys I learn a lot from Bucky Roberts - TheNewBoston.
I prefer him because He explains all stuff very clearlly and few times (every time is different,that everybody could understand ).
Also I am posting tutorial for basic C++, for understand of the code and few variables explanations (Also from TheNewBoston, but posting who don't like videos )
C++ Basic Tutorial
Downloading the best program.
First of all you need a programming language editor like dev-c++, microsoft C++, Code::Blocks. The last editor I mentioned is the simpliest and the best, because ex. microsoft C++ is almost the same as Code::Blocks, just uses more free space and installs few more programs (usless for beginners).So you can download Code::Blocks . With this program you can write with C++ C languages
Understanding the Code
When we start the program and create new console application, there will be a file main.cpp created,so click it twice.
Now you see:
The second thing you see is a blink/free line.That is needed for a cleaner code that you can understand it, you can delete it or put them more, millions,thousands...The same is with the Tabs.
This is the programs function.The functions is needed to computer to do.
The Main() is needed for computer to understand from what to start. Int is some type of data we will be working with (first just with intigers).
{
} between them you need to write a statment/instruction. like :
open car doors;
sit in the car;
start the engine;
drive to the poin;
stop the engin; and the last is
get out of the car; now you have a fully working function
So the
now, the cout means output stream object, it puts information to PC.With cout we use <<. This is called stream insertion operator,this is needed to take the words and print it out on PC screen.
We write all words in the "", to computer understand the words, and the endl is end line or go to the next line and ends with ; like I told you. (Also end line could be used in the "" with the words by writing ex "Hello world \n" the \n means new line. so it is the same as endl) also if you write text next to the endl you would get an error.
And return 0 this means when you run it that everything above it is running fine, and 0 means you are good to go, the main runs fine.
Also about comments you can add a comment like first writing
Variables
Variables basically are just place orders.Thats all they are! For the start ex.
First of all to work with the variables in c++ you need to yous a data base,so we will use a simple DB for the start.That is int (integer, with it we can write numbers like 7,6,28.).So it should look like this:
So now c++ knows that car is value of 7. and now if you write cout<< car; and build it will show only number 7.So the whole code:
Building and running the program
The easiest part is building a program and running, when you finish writing a code you need to press a green arrow,pinion and then it will start the building and running progress.If everything is alright, a black screen will pop out.Ex. if you did a automatic calculate,how i showed to you, then it will write just a number that is calculated.
But if there are an error, nothing will pop out.First the program will show why it couldn't start (reason) in the logs & others window down the program.
Ex. This is a bad code.
why? Because i mised this ; after the words "enter a number \n". And the program will show you this:
my computer stuff\main.cpp|12|error: expected ';' before 'cin'|.
||=== Build finished: 1 errors, 0 warnings ===|
So the you need to fix it and build it again, and after that it works!
Here is how to build a program.
P.S. who wants to. Calculator code, try to understand it and make it by yourself.Also cin >> (input stream object) is operator to take the information from PC.
I prefer him because He explains all stuff very clearlly and few times (every time is different,that everybody could understand ).
Also I am posting tutorial for basic C++, for understand of the code and few variables explanations (Also from TheNewBoston, but posting who don't like videos )
C++ Basic Tutorial
Downloading the best program.
First of all you need a programming language editor like dev-c++, microsoft C++, Code::Blocks. The last editor I mentioned is the simpliest and the best, because ex. microsoft C++ is almost the same as Code::Blocks, just uses more free space and installs few more programs (usless for beginners).So you can download Code::Blocks . With this program you can write with C++ C languages
Understanding the Code
When we start the program and create new console application, there will be a file main.cpp created,so click it twice.
Now you see:
- Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
- Code:
#include <iostream>
The second thing you see is a blink/free line.That is needed for a cleaner code that you can understand it, you can delete it or put them more, millions,thousands...The same is with the Tabs.
- Code:
using namespace std;
- Code:
int main()
{
cout << "Hello world!" << endl;
return 0;
}
This is the programs function.The functions is needed to computer to do.
The Main() is needed for computer to understand from what to start. Int is some type of data we will be working with (first just with intigers).
{
} between them you need to write a statment/instruction. like :
- Code:
cout << "Hello world!" << endl;
return 0;
open car doors;
sit in the car;
start the engine;
drive to the poin;
stop the engin; and the last is
get out of the car; now you have a fully working function
So the
- Code:
cout << "Hello world!" << endl
- Code:
return 0;
now, the cout means output stream object, it puts information to PC.With cout we use <<. This is called stream insertion operator,this is needed to take the words and print it out on PC screen.
We write all words in the "", to computer understand the words, and the endl is end line or go to the next line and ends with ; like I told you. (Also end line could be used in the "" with the words by writing ex "Hello world \n" the \n means new line. so it is the same as endl) also if you write text next to the endl you would get an error.
And return 0 this means when you run it that everything above it is running fine, and 0 means you are good to go, the main runs fine.
Also about comments you can add a comment like first writing
- Code:
/* words words words and ending like this*/
Variables
Variables basically are just place orders.Thats all they are! For the start ex.
- Code:
#include <iostream>
using namespace std;
int main()
{
x = car
I love x
return 0;
}
- Code:
#include <iostream>
using namespace std;
int main()
{
x = 8;
12 + x;
return 0;
}
First of all to work with the variables in c++ you need to yous a data base,so we will use a simple DB for the start.That is int (integer, with it we can write numbers like 7,6,28.).So it should look like this:
- Code:
#include <iostream>
using namespace std;
int main()
{
int car = 7; /*after int you need to name your variable, then add an equel sign and a value*/
return 0;
}
So now c++ knows that car is value of 7. and now if you write cout<< car; and build it will show only number 7.So the whole code:
- Code:
#include <iostream>
using namespace std;
int main()
{
int car = 7; /*after int you need to name your variable*/
cout<< car;
return 0;
}
- Code:
#include <iostream>
using namespace std;
int main()
{
int a = 7;
int b = 8;
int sum = a + b;
cout << sum;
return 0;
}
Building and running the program
The easiest part is building a program and running, when you finish writing a code you need to press a green arrow,pinion and then it will start the building and running progress.If everything is alright, a black screen will pop out.Ex. if you did a automatic calculate,how i showed to you, then it will write just a number that is calculated.
But if there are an error, nothing will pop out.First the program will show why it couldn't start (reason) in the logs & others window down the program.
Ex. This is a bad code.
- Code:
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int sum;
cout << "Enter a number \n"
cin >> a;
cout << "Enter another number \n";
cin >> b;
sum = a + b;
cout << "The sum of these numbers are/is" << sum <<endl;
cout << sum;
return 0;
}
why? Because i mised this ; after the words "enter a number \n". And the program will show you this:
my computer stuff\main.cpp|12|error: expected ';' before 'cin'|.
||=== Build finished: 1 errors, 0 warnings ===|
So the you need to fix it and build it again, and after that it works!
Here is how to build a program.
P.S. who wants to. Calculator code, try to understand it and make it by yourself.Also cin >> (input stream object) is operator to take the information from PC.
- Code:
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int sum;
cout << "Enter a number \n";
cin >> a;
cout << "Enter another number \n";
cin >> b;
sum = a + b;
cout << "The sum of these numbers are/is" << sum <<endl;
cout << sum;
return 0;
}
KristisGTR- Posts : 7
Join date : 2011-07-25
Age : 32
Location : Lithuania
Fighters
Info: 3rd Recruit
HP:
(100/100)
Lv.:
(6/100)
Re: C++ tutorial
Fixed your html code, My site runs on real text size
[size=150] is [size=18] on here
Great tutorial
[size=150] is [size=18] on here
Great tutorial
Re: C++ tutorial
Thanks man
KristisGTR- Posts : 7
Join date : 2011-07-25
Age : 32
Location : Lithuania
Fighters
Info: 3rd Recruit
HP:
(100/100)
Lv.:
(6/100)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|