First know the BASIC concepts COMPUTER प्रोग्रामिंग | HIGH LEVEL LANGUAG...

WHAT IS C++?

            C++ is an object-oriented programming language.  It was developed by Bjarne Stroustrap at AT&T Bell Laboratories, USA in the early 1980’s.  It is an extension of C.  The name C++ comes from the C increment operator ++, thereby suggesting that C++ is an augmented (incremented) version of C.  All C programs also run with C++.  The major important facilities that C++ adds on to C are classes, inheritance, function overloading, and operator overloading.

Program Features

            Like C, the C++ program is a collection of functions.  Execution begins at the functions main ().  Every C++ program must have a main ( ) function.  All the codes/statements are written in lowercase letters.  Each statement is terminated with a semicolon(;).  The compiler ignores carriage returns and white spaces.  The header file iostream.h should be included at the beginning of all programs that use input/output statements as follows :-

            # include <iostream.h>

Common Header Files,

(i)         iostream.h  - contains function prototypes for standard input and standard output functions.

(ii)        math.h -  contains function prototypes for math library functions.
(iii)       stdio.h  -  standard input/output library functions.
(iv)       stdlib.h  - contains function prototypes for conversion of numbers to text, text to numbers, random numbers etc.
(v)        string.h  - C-style string processing functions
(vi)       conio.h  - console input/output functions.
(vii)      ctype.h  - functions to last characters for certain properties, converting lowercase letters to uppercase and vice versa.
(viii)           graphic.h  - functions used in graphics.
(ix)               Time.h  - functions for manipulating time and date.
(x)                 Iomanip.h  - formatting steams of data.
  
COMMENTS

Double slash (//) is used at the start of any single line comment.  Note that there is no closing symbol.  For example :
//  This is an example of
//c++ program to illustrate
// some of its features.
/* and */ are used at the beginning and end of a multi line comments.  For example the above comments can be written as

/*    This is an example of
       c++ program to illustrate
      some of its features.
*/

// can not be used within a program line, but /*….*/ can be used as shown below :

for (int i=0; i<n,/* loops n times */i++)

DATA TYPES

Data type
Range from
Range To
Precision
Bytes of memory
Char, signed char
-128
17
-
1
Unsigned char
0
255
-
1
int
Short int
Signed int
-32,768 (=215)
32,767
-
2
Unsigned int
Unsigned short int
0
65,535
-
2
Long int
Signed long int

-2,147,483,648 (=231)
2,147,483,647
-
4
Unsigned long int
0
4,294,967,295
-
4
Float
-38
        3.4 x 10
38
         3.4 x 10
7
4
Double
-308
        1.7 x 10
308
         1.7 x 10
15
8
Long double
-4932
    3.4 x 10
4932
     1.1 x 10 
19
10






            All variables must be declared before they are used in the program.   Similarly any variable declared must be used in the program.
Examples :-
Int x;
Int x,y,sum=0;
Flot number1,number2, sum;

Two normal uses of void are :
(i)         To specify the return type of a function when it is not returning any value.
(ii)               To indicate an empty argument list to a function.
Example :- void func1 (void);

Output Operator

            The statement
cout<<”C++ is better than C.”;

Causes the string in quotation marks to be displayed on the screen.  The identifier cout (pronounced as ‘c out’) is an object that represents the standard output stream in c++.  Here the standard output stream represents the screen.  It is also possible to redirect the output to other output devices.
           
The operator << is called the ‘insertion’ or ‘put to’ operator.  It inserts or sends the contents of the text or variable on its to the object on its left.  If x is a variable, then the following statement will display its contents :-
Cout << x;

The operator << can be used for different purposes.  This concept is known as operator overloading, an important aspect or polymorphism.

Input Operator

The statement
cin>> x;
Is an input statement and causes the program to wait for the user to type in a number.  The number keyed in is placed in the variable x.  The identifier cin 9pronounced ‘C in”) is an object in c++ that corresponds to standard input stream.  Here this stream represents the keyboard.

            The operator >> is known as ‘extraction’ or ‘get from’ operator.  It extracts (or takes) the value from the keyboard and assigns it to the variable on its right.  Like <<, the operator >> can also be overloaded.

Cascading Of I/O Operators

            Insertion operator << can be used repeatedly for printing results.  The statement
Cout<<”um= “<<sum <<”\n”;
<<”\average = “ <<average<<”\n”;

First sends the string “sum = “ to cout and then sends the value of sum.  Then it sends the new line character so that next output “Average = “ and the value of average will be printed in the new line.

To print output in two lines we could also use the following statements :

Cout<<”sum = “ << sum;
Cout<<”average = “ << average;

We can also cascade input operator >> as shown below :
Cin>> number1, number2;

            The values are assigned from lift to right.  If we key in two values, say, 10 and 20, then IO will be assigned to number1 and 20 to number 2.

Chained Assignment

X = (y = 10); or x = y = 10; means first 10 is assigned to y and then to x.  A chained statement cannot be used to initialize variables at the time of declaration.
i.e. int x = y = 10; is illegal.

This may be written as int x = 10, y = 10;

Compound Assignment

x =x+10; may be written as int x+ = 10;
x =x/10; may be written as int x/= 10;

The if statement

            General form :-
                        If ( this condition is true)
                        Execute this statement ;

This expression                      Is true if

x = = y                                     x is equal to y
x! = y                                       x is not equal to y
x < y                                        x is less than y
x > y                                        x is greater than y
x<= y                                       x is less than or equal to y
x>= y                                       x is greater than or equal to y

Another form of if statement is
If (expression)
Statement ;
Here the statements will be executed if the expression is true or a non zero value Example :- a = 10;

If (a)

cout<<”the statement is executed. “;

Comments

Popular posts from this blog

Learn MS Word -Easy Tutorials | THEORY/ PRACTICAL SESSION | PART 1