STRUCTURE OF C++ PROGRAMMING

By | September 11, 2017
Spread the love

STRUCTURE OF C++ PROGRAMMING

In order to understand the structure of C++ programming let’s consider this program,

We will learn each line by line what it represents,

/* C++ program to create a simple class and object.*/

#include  <iostream>

using namespace std;
class Hello
{
public:
void sayHello()

        {

    cout << "Hello World" << endl;

        }
};

 int main()

{

  Hello h;

 h.sayHello();

 return 0;
}

This above program is divided into seven parts to learn Structure Of C++ Programming,

  1. Documentation Section
  2. Preprocessor Directive—1) Link Section 2) Definition Section
  3. Global Declaration Section
  4. Class Declaration or Definition
  5. Main C++ Function
  6. Beginning Of Program
  7. Object Declaration, Accessing Member Functions
  8. End Of Main Program
  1. Documentation Section

/* C++ program to create a simple class and object.*/

Yes, documentation section contains comments.

Now you have the question in your mind, let’s answer them.

What is necessary for writing comments?

  It just way to explain what this code is about. It can be used anywhere in the program.

Is it affects programming output?

 No, the compiler ignores the comments during execution.

There are two types of comments—single line comments and multiline comments.

For single line comments, we use //

For multiline comments, we use /*       */ .

  1. Preprocessor directive or compiler directive

 

#include  <iostream>

What exactly is the meaning of above line?

# tells the processor to include directive, in above case that directive is iostream.

  • Particularly, this iostream directive helps to do input/output operations.
  • There are many library functions. In order to call those library functions, we use preprocessor directive.
  • Function means the group of code, which performs a particular task.

In preprocessor directive, we can also define a function.

Ex::  #define PI 3.142

We can also include compiler functions.

Ex:: sqrt(), clrscr(), exit()

  1. Global declaration section

Declaring variable globally before main function or outside the main function.

These variables can be accessed directly by the main function.

Ex:: int a,b,c;

       float x,y,z;

       char ch, name[10];

  1. Class declaration or definition

 

class Hello
{

public:

     void sayHello()

        {

                cout << "Hello World" << endl;

        }

};

Before going to learn how a class is defined, first we will understand, what is a class?

The Class comprises of data and function. Function operate that data.

*So, we have two members—data member and member function.

The Syntax of class::

class< name of class>

{

private;

data members;

member function();

protected;

member function();

};

Class name—Name given to the class, using which we can create an object.

In our code, a class name is Hello.

Data members- To define the character of the class, we use data members.

Member function—Various functions that perform on class.

Any number of the member functions of any type can be used in the class.

In order to access the member function, we use dot operator.

    h.sayHello();

Accessibility of data members.

 Private—member in the class can be accessed by the same class.

Private members can’t be accessed outside of the class.

Public—Public members can be accessed outside of the class.

Protected—member function cannot be accessed outside of the classes, it can be accessed only in the class.

  1. Main C++ function

    int main()
    

* Every C++ program must contain one main().

* int/void represents the returning value.

  1. Beginning of program

{ –represents the beginning of the program.

}—represents the end of the program.

Visit our next blog to get clarity on namespace using std, some important points to learn C++.

HYPERLOOP-THE FIFTH MODE OF TRANSPORTATION

WHY IS KOTLIN  THE EASIEST ANDROID DEVELOPMENT LANGUAGE?

HOLOLENS-YOU CAN CREATE YOUR DESIRED WORLD

WHY IS SOCIAL MEDIA MARKETING  IN BUZZ?

HOW INTERNET WORKS? WHO OWNS IT?


Spread the love
Category: C++ Tutorials Tags:

About Manojkumar M M

Manojkumar is a Digital Marketing Expert from Bangalore, India. He has got 3 years of experience in the field of Digital Marketing. He worked with many start-ups to help them in improving their Business Lead Generation through online. He blogs about digital marketing tips, technology updates, programming language tips at this blog Techgeetam.com. Contact me for any kind of help in the field of Digital Marketing. Mail Id - digimanoj98@gmail.com

Leave a Reply

Your email address will not be published.