Skip to main content

2. Basic Structure of c++

 ● BASIC STRUCTURE OF C++ LANGUAGE :-

         The program written in C++ language follows this basic structure. The sequence of sections should be as they are in the basic structure. A C program should have one or more sections but the sequence of sections is to be followed.


1. Documentation section

2. Linking section

3. Definition section

4. Global declaration section & class declarations

5.Member function definition

6. Main function


section main()

{

Declaration section

Executable section

}


1. DOCUMENTATION SECTION :-


       comes first and is used to document the use of logic or reasons in your program. It can be used to write the program's objective, developer and logic details. The Documentation is done in C language with /* and */ . Whatever is written between these two are called comments.


2. LINKING SECTION :-


        This section tells the compiler to link the certain occurrences of keywords or functions in your program to the header files specified in this section.

e.g. #include<iostream>

using namespace std;


        directive causes the preprocessor to add the contents of the iostream file to the program. It contains declarations for cout and cin.

        cout is a predefined object that represents the standard output stream. The operator << is an insertion operator, causes the string in double quotes to be displayed on the screen.

        The statement cin>>n; is an input statement and causes the program to wait for the user to type in a number. The number keyed is placed on the variable “n”. The identifier cin is a predefined object in C++ that corresponds to the standard input stream. The operator >> is known as extraction operator. It extracts the value from the keyboard and assigns it to the value variable on its right.


3. DEFINITION SECTION :-

        

           It is used to declare some constants and assign them some value. e.g. #define MAX 25

Here #define is a compiler directive which tells the compiler whenever MAX is found in

the program replace it with 25.


4. G LOBAL DECLARATION SECTION :-


         Here the variables and class definations which are used through out the program (including main and other functions) are declared so as to make them global(i.e accessible to all parts of program). 

         A CLASS is a collection of data and functions that act or manipulate the data. The data components of a class are called data members and function components of a class are called member functions A class ca also termed as a blue print or prototype that defines the variable or functions common to all objects of certain kind. 

         It is a user defined data type e.g. int i; //this declaration is done outside and before main()


5. SUB PROGRAM OR FUNCTION SECTION :-


      This has all the sub programs or the functions which our program needs.

void display()

{

cout<<”C++ is better that C”;

}


SIMPLE „C++‟ PROGRAM:


#include<iostream>

using namespace std;

void display()

{

cout<<”C++ is better that C”;

}

int main()

{

display()

return 0;

}


6. MAIN FUNCTION SECTION :-


          It tells the compiler where to start the execution from main()

{

point from execution starts

}


main function has two sections......

1. declaration section : In this the variables and their data types are declared.

2. Executable section or instruction section : This has the part of program which actually performs

the task we need.



Comments

Popular posts from this blog

Remove specific item from Recyclerview in android studio

For Full video click on below link :- https://youtu.be/sUz4fqeanjI?si=A8AqBWCgu-5NnBOJ Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursenam...

Fingerprint Authentication in Android Studio Project

Implement the implementation : - implementation 'androidx.biometric:biometric:1.0.1' Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity" android:background="@color/white"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to the Boxcode!!" android:textSize=...

Sqlite with CRUD operation in Android studio

For Full video click on link :- https://youtu.be/QTvy8sJSiyI?si=dM1f98Mr7aFpJpqG Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursename...