Structure of cpp program, C/C++ Programming

Assignment Help:

Structure of C++ Program:

Chronological order of C++ program.

1.   Class declaration

2.   Main function program

3.   Member functions definitions

4.   Include header files

C++ program are stored in three files.   File header in one file, Class declaration and member function in another file, and the main function program in the third file.   The Class declaration and member function file is stored in server and the main function program in the client.   This client-server set up will enable several clients to use the same class to work on various modules or program.

Some header files:

Some of header files in C++ are; cctye, cfloat, climits, cmath, cstdio, cstdlib, cstring,

iostream, iomanip, bitset, list, stack, queue, deque, vector, map, utility, memory, string, sstream, set, locale, limits, typeinfo, iterator, functional, etc.

A simple program: Example 1:

#include

int main( )

{cout << "My first C++ program.\n";

return 0;

}

Example 2:

#include

int main( )

{float num1, num2,sum,avg;

cout << "Enter two number with space between numbers.\n";

cin >> num1>> num2;//each variable should have separate extraction operator

sum = num1 + num2;

avg = sum/2;

//each variable should have separate inseration operator sum, avg is invalid cout << "The sum is" << sum << "\n";

cout << "The average is" << avg << "\n";

return 0;

}

These simple C++ programs it may look similar to C with small changes, without of printf and scanf in C here cout and cin are used with << and >> insertion operator.  Remember when a function has a return type it should have a return value since main function has a return type of integer the function return 0 at the end of the program to indicate the end.  Just like C the C++ statement must end with semicolon and it must have only one main function. Remember <<, and

>> operators are also used as bit-wise left shift and right shift operators, thus the process of using same operator for different purpose is known Operator Overloading.   Operator overloading is another example for polymorphism.


Related Discussions:- Structure of cpp program

C++, Write C++ code for calculating the time table

Write C++ code for calculating the time table

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw

Using nested if statement, write a program in c/C++ using nested if stateme...

write a program in c/C++ using nested if statement for calculating the average marks and grades of 5 subjects

C programming, Write a program that keeps record of football results. Progr...

Write a program that keeps record of football results. Program stores following information about each match: Description Type and/or size name of home team max. 25 characters name

Ascii string related, A string S is said to be "Super ASCII", if it contain...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Array, Assigning value to individual elements in array

Assigning value to individual elements in array

Write a program to implement operator functions, Implementing Operator Func...

Implementing Operator Functions The general format of the Operator function is: return_type operator op ( argument list );   Where op is the symbol for the operator be

Area, write a program to find the area under the curve y=f(x) between x=a &...

write a program to find the area under the curve y=f(x) between x=a & x=b

Write a c++ program that calculates the area of a circle, Write a C++ progr...

Write a C++ program that calculates the area of a circle, rectangle and square using overloaded versions of a function area ().Your program should include both declarations and def

Explain the scope resolution operator, The Scope Resolution Operator( :: ) ...

The Scope Resolution Operator( :: ) Global variables are explained outside any functions and thus can be used by all the functions defined thereafter. However, if a global vari

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd