Structure of cpp program, C/C++ Programming

Structure of C++ Program:

Chronological order of C++ program.

1.   Class declaration

2.   Main function program

3.   Member functions definitions

4.   Include header files

C++ program are stored in three files.   File header in one file, Class declaration and member function in another file, and the main function program in the third file.   The Class declaration and member function file is stored in server and the main function program in the client.   This client-server set up will enable several clients to use the same class to work on various modules or program.

Some header files:

Some of header files in C++ are; cctye, cfloat, climits, cmath, cstdio, cstdlib, cstring,

iostream, iomanip, bitset, list, stack, queue, deque, vector, map, utility, memory, string, sstream, set, locale, limits, typeinfo, iterator, functional, etc.

A simple program: Example 1:


int main( )

{cout << "My first C++ program.\n";

return 0;


Example 2:


int main( )

{float num1, num2,sum,avg;

cout << "Enter two number with space between numbers.\n";

cin >> num1>> num2;//each variable should have separate extraction operator

sum = num1 + num2;

avg = sum/2;

//each variable should have separate inseration operator sum, avg is invalid cout << "The sum is" << sum << "\n";

cout << "The average is" << avg << "\n";

return 0;


These simple C++ programs it may look similar to C with small changes, without of printf and scanf in C here cout and cin are used with << and >> insertion operator.  Remember when a function has a return type it should have a return value since main function has a return type of integer the function return 0 at the end of the program to indicate the end.  Just like C the C++ statement must end with semicolon and it must have only one main function. Remember <<, and

>> operators are also used as bit-wise left shift and right shift operators, thus the process of using same operator for different purpose is known Operator Overloading.   Operator overloading is another example for polymorphism.

Posted Date: 9/20/2012 7:26:24 AM | Location : United States

Related Discussions:- Structure of cpp program, Assignment Help, Ask Question on Structure of cpp program, Get Answer, Expert's Help, Structure of cpp program Discussions

Write discussion on Structure of cpp program
Your posts are moderated
Related Questions
Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

B a s i c D a t a t y p e : T h e r e a r e t h r e e t y p e o f d a t a t y p e i n C+ + 1.       P r

If we take the input image and smooth it with a Gaussian of a significant size before computing the Canny edges does the number of edges change, and do the locations of these edges

In this assignment, you will develop a program named "match" to be used by a dating service to form couples. Given the number of gentlemen, the number of ladies, and a list of acce

BACKGROUND: FILE SYSTEMS  In a computer, a file system (sometimes written filesystem) is the way in which files are named and where they are placed logically for storage and ret

1 PETTERN1 (Pettern1.c)   main() {           int i,j,k=1,a;           clrscr();           for(i=1;i           {                    if(i>=3)

Project Description: Need to develop an expert advisor base on sthocastic oscilator with my own setting.. Very basic touch line OB/OS only but on my setting n condition Skill

Function Templates Function templates give you with the capability to write a one function that is a skeleton, or template, for a family of similar functions. In function ov

The default Constructor and Destructor If you fail to write a constructor and destructor function,  the compiler automatically supplies them for you. These functions have publi