Advertisement Remove all ads

Explain the Syntax of C++ Program Structure with Example. - Computer Science 1

Answer in Brief

 Explain the syntax of C++ program structure with example. 

Advertisement Remove all ads


 1) A typical C++ program contains 4 sections as shown in following figure. These sections may be placed in different code files and then compiled independently or jointly.

Include files 
Class declaration 
Class functions definitions 
Main function program 

                Structure of C++ program 

2) It is a common practice to organize a program into three separate files.
3) The class declarations are placed in a header file and the definitions of the member go in other file.
4) This approach enables the programmer to separate the abstract of the interface from the implementation details.
5) Finally the main program that uses the class is placed in third file, which includes the previous two files as well as any other files required. 

Example : 
# include <iostream.h>
# include <conio.h>
# include <math. h>
class triangle
float a, p, x, y, z;
public :
void accept ()
cout <‘’Enter three sides of triangle’’;
cin >> x>> y>>z;
void compute()
{p = x+y+z;
double & = P/2;
a = sqrt(s*(s-a)*(s-b)*(s-c));
cout <<‘’Area’’<<a;
void main()
triangle t1;

Concept: C++ Programming
  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads

View all notifications

      Forgot password?
View in app×