Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming

C++ Program Structure

Question: 1. Explain the structure of C++ program

C++ Program Structure

• There are four sections in the structure of C++ program ‒

 

Structure of C++ program

Include file section

Class declaration section

Function definition section

Main function definition

 



The sample C++ program is as follows ‒

C++ Program

FirstProg.cpp

//This is my first C++ program

//This program simply prints the message Hello World

#include<iostream>

using namespace std;

int main()

{

      cout<<"Hello World\n";

}

Program Explanation

• The first two lines are the comments. It is a non executable portion.

• Then the next line statement begins with the sign #. It is a pre‒processor directive. It tells the pre‒processor to include the header file iostream.h. This specific file iostream.h includes the declarations of the basic standard input‒output library in C++, and it is included because its functionality is going to be used later in the program. In Linux platform # include<iostream> is used.

Next line is

using namespace std;

• This statement is used to define scope of the identifiers that are used in the program, std is a namespace where the standard class libraries are defined. By this statement we can bring all the identifiers in the current global scope. The keyword namespace is used to define the scope of identifiers. If namespace is not used then cout statement, must be written as std::cout.

• The void main() is a function from where the execution of C++ program starts. Then { indicates the beginning of the function definition.

• The next line starts with cout. The cout represents the standard output stream in C++. By this statement we will get the "Hello world" message printed on the output screen. The cout is declared in standard iostream file. The cout should be followed by << and then by some message in double quotes.

• Then the program ends by }.

 

Review Question

1. Explain the structure of C++ program

 

Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming : Tag: Oops, Computer Programming : - C++ Program Structure


Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming



Under Subject


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs) - Laboratory

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation