Basic Program Structure of C++

C++ Program Structure (C++ प्रोग्राम का स्ट्रक्चर)

Every C++ program has four main parts, which are stored at different location in form of different files. These files are compiling one by one or together. General structure of C++ program is as follows-
प्रत्येक C++ के प्रोग्राम में चार मुख्य भाग होते है। जिन्हें विभिन्न फाइल्स के रूप में अलग-अलग स्थानों पर रखा जाता है। इन फाइल्स को एक के बाद एक या एक साथ कोम्पिले किया जाता है। C++ प्रोग्राम का सामान्य प्रारूप निम्न है :- 
-------------------------------------------------------
Include files

Global Variables

Class declaration
data members declarations
member functions declarations

Member functions definitions

Main function
variable declarations
executable statements
variable declarations
executable statements

Other Functions and classes (optional)
--------------------------------------------------------

In c++ language, three separate files are managed for storing data of different parts such as class declaration is stored in header file, member function is stored in another file, and main function is stored in program file.
C++ लैंग्वेज में तीन पृथक फाइल का प्रयोग कर प्रोग्राम के भिन्न भिन्न भागो को रखा जाता है जैसे क्लास डिक्लेरेशन को हैडर फाइल में , फंक्शन को अन्य फाइल में एवं मेन फंक्शन को प्रोग्राम फाइल में रखा जाता है।
  
This method follows client server model in which class declarations and member functions are work as server and main function working as a client. Main function is interacting with server by using public interface.
यह युक्ति क्लाइंट-सर्वर मॉडल का अनुसरण करती है जिसमे क्लास डिक्लेरेशन एवं मेम्बर फंक्शन सर्वर के रूप में कार्य करते है जबकि मेन फंक्शन क्लाइंट के रूप में कार्य करता है। मेन फंक्शन, सर्वर से पब्लिक इंटरफ़ेस का प्रयोग कर संवाद करता है।       

Example-

1.) C++ program to calculate simple Interest.

#include<iostream.h>
#include<conio.h>
void main () {
float p,r,t;
clrscr () ;
cout<<”Enter Principle, Rate and Time”<<endl;
cin>>p>>r>>t ;
float si=(p*r*t)/100 ;
cout<<”Simple Interest ="<<si<<endl;
getch () ;
}

2.) C++ program to find sum and average of two numbers.

#include<iostream.h>
#include<conio.h>
void main () {
float a,b;
clrscr () ;
cout<<”Enter two numbers”<<endl;
cin>>a>>b ;
float sum=a+b ;
cout<<”sum=<<”sum<<endl;
float avg=(a+b)/2 ;
cout<<”average =”<<avg<<endl;
getch () ;
}

No comments:

Post a Comment