Blogger templates

Pages

Friday, 25 May 2012

Tutorial on Basic Concepts of C++ Program Part 1

Concepts

Structure of C++ Program:
  • C++ Program contain Four Sections. 
  • These Sections may be placed in Separate code Files.
  • Most popular Compiler systems are UNIX AT & T C++ , Turbo C++ , Microsoft Visual C++.


          Include Files 
       Class Declaration 
 Member Function Definition 
     Main Function Program


Output operator:
  1. This statement  Cout << " c++ is better than c. " ; introduces two new C++ Features i.e Cout and <<
  2. The operator << is called the Insertion or Put to Operator. 
  3. The identifier Cout is a predefined object that represents the standard output stream in c++. 
  4. << Operator is also known as bitwise left-shift operator.
Note: Both Cout << and printf() are used for displaying an Output.

Input operator:
  1. The statement  Cin >> number;  is an input statement. 
  2. The identifier Cin is a predefined object in C++ that represents the standard input stream. 
  3. The operator >> is known as Extraction or get from operator. It extracts the value from the keyboard and assign it to the variable on the right of the identifier Cin.
Note: 
  • Both scanf() and Cin is used for input values.
  • Both << and >> can also be overloaded.
Return Type of main() :
  1. In C++ main() returns an integer type value to the operating system. Thus every main() in C++ should end with a return(0) statement, otherwise a warning or an error Might occur. 
  2. The default return type for all functions in C++ is int.
Example:
     main()
     {
     ...........
     ...........
    return(0);
     }
Manipulators:
  1. Manipulators are the Operators that are used to Format the data display. 
  2. The most commonly used manipulators are endl and setw.
  3. " endl " manipulator when used in an output statement, it causes a linefeed to be inserted. It has same effect as that of newline character " \n ".

Cascading of I/O Opertors:
  • Cout<< "Sum=" << sum<<"\n";
The above Statement first sends the string "Sum=" to Cout and then sends the value of sum.

  • Cin>> a >> b;
    The values are assigned from Left to Right. If we press two values i.e 10 and 5 from the keyboard then 10 will be assigned to "a" and "5" to b.

    • This is one statement and provides one lines of output.
                               Cout<< "Sum=" << sum<<" , "
                                      << "Average="<< average<< "\n";
    Output:
     Sum=30 , Average=7

    • This is one statement but provides two lines of output.
                                   Cout<< "Sum=" << sum<<" \n "
                                          << "Average="<< average<< "\n";

    Output:
     Sum=30 
     Average=7


    0 comments:

    Post a Comment