C++ Tutorial

  Sample Program 1

#include<iostream.h>
#include<conio.h>

void main(){
clrscr();
cout<<"Hello World";
}

This is a simple program in C++. Output of it is Hello World.

Lines with a hash symbol (#) are called preprosessor. Use to compile your program.

IOSTREAM.H - is used for cout and cin
CONIO.H - is used to call the function clrscr();

main() - is the main function of the program. All the contents of the main function will be executed by the program.
clrscr() - is used to clear the screen
cout - is used to display text or things you want to be displayed in the screen.

Sample Program 2: With Input

#include<iostream.h>

void main(){
string name;
cout<<"Enter your name: ";
cin>>name;
}

Explanation:
Datatypes - are used to declare variables and functions. There are 6 datatypes, these include:
1. int - it is use to declare variable that has integer value ex: 2
2. float - it is use to declare variable that has value that has decimal ex: 2.3
3. double - same as float
4. string - it is use to declare variable that has string of characters ex: Hello
5. char - it is use to declare a variable that can contains single character ex: a
6. void - it is use to declare a function that will not return a value.

Note: Datatypes above from 1-5 are also use in declaring a function that returns a value.

Variables are used for assigning values depending on its datatype. In the above example,

string name; --> the one that is in bold (string) is what you call datatype, while the one that is italicized is what you call the variable.

Variable name can store string of characters like "Kenneth Burgos". Variables can be name in any ways you want.

Ex:
float pay; --> can store values with decimal places such as 3.45, 6.23
char letter; --> can store single character like 'A','B'

Value of datatype char is in single quote while value of datatype string is in double quote.
Ex: 'A' - char        "World" - string

Note: Declaring and assigning of value in a variable can happen at the same time. For example,

char letter='C';
string fname="Jason";
int num=1;
float val1=3.45;
double val2=6.7;

In the above example you can see that the program will output:
Enter your name: _

Then after that you have to input your name. You will see now on your screen:
Enter your name: Jason Burgos

If you have question ken, just text me sa aking tm or sun... isave mo ung number na bigay ni dayan ha.