Search This Blog

Friday 2 November 2012

Basics

Comments:  Comments are for Programmer, he writes it in order to make his code understandable (since the code becomes complex often). C++ Compiler Ignores comments.
//Write the comment after two consective forward slashes (if your coomment is in single line)
/*Comments are written
in this way when they
occupy more than 1 line in C++ Compiler.*/


Output:

cout<<"Write here (within the inverted commas)whatever you want to see on the Screen when your Program Runs.";


cout<<"Write here whatever you want to see on the Screen when your Program Runs. "<< a; /*Prints the sentence within inverted commas as it is and then Prints the value stored in variable 'a'.*/
Usefull things for output:





Example:cout<<"\n\t I love \n\n";



Input: Prompts user to Enter Data.

cin>>Variable_Name;
Data can be entered in more than one variable:
cin>>first>>SeCond>>fifth;
(When your Program Runs) User enters something and Presses ENTER or SPACEBAR, whatever he writes before pressing Enter will be stored in variable named 'first'. User will again be prompted, he enters something and presses ENTER or SPACEBAR, that will be stored in variable named 'SeCond'. Similarly in variable fifth, the third value entered by the user will be stored.
NOTE: C++ is very strict in its CaSE  ==> 'You' & 'you' are two different variables.


Setw: Specify Number of Spaces.

In order to use this feature of C++, you'll have to include a header file in the beginning of your program source code.
#include<iomanip>
Then with in the program you can use Setw anywhere.

cout<<"I want"<<setw(20)<<"$";Note: $ sign is mixed with "Press any..."




How to seperate dollar sign from mixing to rest of line?
Simple, cout<<"I want"<<setw(20)<<"$\n\n";




This command needs small extra practice.


Setprecision: How many digits should appear after point (.) .

Also see the output by replacing fixed with scientific to know the difference.









No comments:

Post a Comment