Friday 19 August 2011

BASIC COMMANDS IN C++.

BASIC COMMANDS

In this post i will tell you the meanings of some simple commands we generally use in C++. Like cout, cin and etc.

So now if you are a beginner it will help you a lot :

           
NOTE :-
Whenever you start programming in C++ you always need to include the header files. And after that when you start a program you will type void main() and then you will put curly brackets ({,}) and all your program will come under these brackets. Every line you write you have to terminate it using semi colon (;).

Basic commands of C++ are:
  1. cout :- This command starts with << and the thing which you want to be printed shoul be in double Qoutes("") . This command is used to print on the screen and its information is stored in iostream.h header file. Eg: cout<<"Hello";
  2. cin :- This command starts with >> and is used to take input from the user, the information the user gives is stored in a variable like 'a' which we have to initialize in the int/char/float its information is also stored in iostream.h header file. Eg: cin>>a;
  3. clrscr() :- this is a command to clear the screen its information is stored in iostream.h header file.
  4. getch() :- this command is used to stop the screen to see the results and if you do not type this command the result screen will open and will close it will not stop. Its information is saved in conio.h
  5. int :- this command is used to initialize the variable to store integers (-1, -2, 0, 1, 2).
  6. float :- this command is just like int but it stores numbers and decimals also (1.25, 2.5).
  7. char :- this command is just like the above two but it can store characters also (a, b, c).
  
 here is an example by using the above written commands :

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

void main()
{
clrscr();
float a,b,c,d,e,f,h;
cout<<endl<<endl<<"  enter first number ";
cin>>a;
cout<<endl<<endl<<"  enter second number ";
cin>>b;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
cout<<endl<<endl<<"  By adding the result is = "<<c;
cout<<endl<<endl<<"  By subtracting the result is = "<<d;
cout<<endl<<endl<<"  By multiplying the result is = "<<e;
cout<<endl<<endl<<"  By dividing the result is = "<<f;
getch();
clrscr();
cout<<"\n\n  Tell a number to square it ";
cin>>h;
cout<<"\n\n  the square is = "<<h*h;
getch();
clrscr();
cout<<endl<<endl<<"  You liked it ";
cout<<endl<<endl<<"  I am sure that you liked it ";
cout<<"\n\n  Thanks for using this calculator.... ";
getch();
clrscr();
cout<<"\n\n  This calculator is made by ";
cout<<"\n\n  SAHARSH GUPTA ";
getch();
}

I used float in this program because the results may not be in integers they can be in decimals also.
These are the basic commands of C++ and if you want any other help in programming then please tell us.
Enjoy programming. !!

by Saharsh and Siddharth

1 comment:

back to top