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
The STL details are described in many places online (see the CS377 webpage for some links), and there's a very quick introduction in Section A.14. Here are just a few additional no

Write a C program to input three real numbers and  print them out as follows : The first variable is ....... and the second one is ...... The last variable is .......... T

Input Format: First line starts with T, which is the number of test cases. Each test case contains a string (S). Output Format: For each test case print the minimum number of ch

Write a program to input two integers. If they are equal display "The numbers are equal". Otherwise display a message if the first is a multiple of the second or if it is not a mul

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

one of the applications of computers in numerical analysis is computing the area under a curve. one method of calculating the area under acurve is to divide the area int a number o

write a program to find the area under the curve y=f(x) between x=a & x=b

1. The shell must support the following internal commands: i. cd - Change the current default directory to . If the argument is not present, report the current directory. If t

In this worksheet you are asked to write three classes in C++: Lecture class, Course class and University class. The classes relate to each other in the way that a Course has many

Program is to create a file student.dat: Program is to create a file student.dat which contains all name, roll_no,marks(5 sub) and percentage   class student    {