Post: [C++] Basic's of [C++]
04-23-2011, 03:20 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Hey guys

Im here to teach the people of nextgenupdate the basic's of c++

I will update this thread as i learn more stuff .


I do no that Drackos has a basics of c++ thread .

But it is only 15 % through at the moment so i thought while people are waiting for him to update it i will make one to keep you updated .

If you are having any problems please just message me i will do my best to help

[edit] Guide will take longer due to internet problems ( stupid virgin ) [edit]
[multipage=Setting up your compiler]

For This guide i will be using devcpp

Download it from here

You must login or register to view this content.

install it then load it up

goto file -> New source file

then press ctrl+s then save your soucre file somewhere

to compile your program all you have to do is press ctrl + 9
[multipage=Basic Program]

    #include <iostream>

using namespace std;

int main()
{
cout << "Hello world "<<endl;
system("pause");
return 0;
}


You have propaly just looked at this and gone :S

I will now explain it to you step by step

    #include <iostream>

What this does is it includes the header 'iostream' into your program this allows you to do the basic function's like 'cout'


    using namespace std;

Using namespace std; lets the compiler know that you are using the functions which are in your header 'iostream'


    int main()


This is the funciton name and type
'int' standing for integer this tells the compiler that you are going to be returning a number at the end of the function .

main - is the name of the function .

    {

This tells the compiler that it is the start of the function

    cout << "Hello world "<<endl;


This use's the function 'cout' which is in the header which we included

The " mark's where the start of the text is and the other " marks the end of the text

endl this end's the line .

    ;


This tells the compiler it is the end of the function which we used .

    system("pause");


this is another function which is from a built in header ( already include by your compiler )
    return 0;


Rember that are function is a int well because it is a int we have to return a integer .

     } 


this tells the compiler it is the end of our function

This is the most easy program to make

Comment marks are ways to wright text in your program's
source code with out it effecting your program to do this it is as simple as doing this
     // then wright your text here 

once you press enter to go to a new line u have to put some more comment marks


[multipage=Varibles]

Part 1 Using varibles

    int Myvarible;


This is how you define a varible

Varibles are used in most every program

just think of any game where you have health there is a varible for the health

A varible is a way to store information e.g a integer

int is the type of varible

myvarible is the name you can put anything in there (except numbers ).

    #include <iostream>
using namespace std;

int main()
{
int myvarible;
myvarible = 12;
cout << " Hello the integer in myvarible = "<<myvarible <<endl;
system("pause");
return 0;
}


As you can see most of this is the same as the basic program in page 2

i will only explain the things which have been added

    int myvarible;


This is the declartion of the varible .

    myvarible = 12;


This is setting the varible myvarible to the integer 12

    cout << " Hello the integer in myvarible = "<<myvarible <<endl;


the point which we are intrested in is

    <<myvarible<<endl;


This is displaying what ever is in myvarible not the name of the varible

Go and compile this and a box should pop up saying

Hello the integer in myvarible = 12

Part 2 Add varibles together

Okay so know you know how to display varibles it is time to add two varibles together

So lets say i have 3 varibles

    int Num1;
int Num2;
int Sum;


So lets say i put a integer in Num1 varible and Num2 varible

    Num1 = 12;
Num2 = 20;


In c++ it is the easy to add to varibles together it is a simple as this

    Num1 + Num2 = Sum; 


Num1 + Num2 = Sum;
So this is the same as
12 + 20 = 32
so now to display it all it is

    cout << "Num1 add Num2 = " <<Sum<<endl;


Build the program yourself using the basic hello world program and the stuff which you have learnt form this tutorial .

Part 3 User input

So lets say we were going to make a program for over 16's

We need to make them to enter there age we can use varibles to do so .

To get started let declare a varible called userage and lets make it a integer

    int userage;


so now we have our varible we need to user to input a vaule

    cout << "Please Enter your age"<<endl;
cin >> userage;


So here we can see that we are using cout to output text to the screen .

cin is a new function to you.

wat cin does is it lets the user input data to the program .

so
    cin>>userage;

This is letting the user enter a number from there keypad
and then the number will be then stored into the varible userage

Now we need to tell the compiler we want to test if the varible userage is higher than 16 to do this we use a statement called a if statement .

it is used like the following

    if(userage > 16)
{
cout << " You are allowed to use this program"<<endl;
}else{
cout << "Get off this program it is only for over 16's"<<endl;
}


As you can see it is like a function

The next tutorial i will explain more about if statments

compile this and test it out .

    #include <iostream>
using namespace std;
int main()
{
int userage;
cout << "Please enter your age "<<endl;
cin >>userage;
if(userage > 16)
{
cout << "You are allowed to use the program "<<endl;
}else{
cout << "You arnt allowed on this program "<<endl;
}
system("pause");
return 0;


[multipage=Arrays]
I am not very keen on arrays but i will try and do my best on it



You must login or register to view this content.
Last edited by ii LeDgEnz x ; 04-24-2011 at 06:14 PM.
04-27-2011, 11:11 AM #20
Originally posted by xNCK View Post
Yeah, sure, lol. :fa:

Why use beeps? If you use ASCII character 7, you won't need to include the shitty windows.h, you don't have to write more code and your code works on other operating systems.


Shhh its cooler k? :mad::mad:
04-29-2011, 05:02 AM #21
schnzrs
Do a barrel roll!
Originally posted by xNCK View Post
How to give your ears AIDS.
    #include <iostream>
using namespace std;

int main()
{
for (;Winky Winky
{
cout << (char)7 << endl;
}
}

Since I know you are learning Python, you can do this name thing in Python SO easy.
    while 1: print chr(7)
04-29-2011, 05:35 AM #22
vSaBoTeuR x
< ^ > < ^ >
Originally posted by schnzrs View Post
Since I know you are learning Python, you can do this name thing in Python SO easy.
    while 1: print chr(7)


Yeah, I know, but can't you do an infinite loop with for in Python?

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo