Posts

Showing posts from March, 2017

Structure of C++ Program

Image
Structure of C++ Program A typical C++ program would contain four sections as shown in figure This section may be placed in separate code files and then compiled independently or jointly. It is a common practice to organize a program into three separate files. The class declarations are placed in a header file and the definitions of member functions go into another file. This approach enables the programmer to separate the abstract specification of the interface from the implementation details (member function definition). Finally, the main program that uses the class is places in a third file which “includes: the previous two files as well as any other file required. figure: structure of c++ program This approach is based on the concept of client-server model as shown in figure below. The class definition including the member functions constitute the server that provides services to the main program known as client. The client uses the server through the public i...

Simple C++ Program

Image
Let us begin with a simple example of a C++ program that prints a string on the screen. This simple program demonstrates several C++ features. Program feature Like C, the C++ program is a collection of function. The above example contain only one function main(). As usual execution begins at main(). Every C++ program must have a main(). C++ is a free form language. With a few exception, the compiler ignore carriage return and white spaces. Like C, the C++ statements terminate with semicolons. Comments C++ introduces a new comment symbol // (double slash). Comment start with a double slash symbol and terminate at the end of the line. A comment may start anywhere in the line, and whatever follows till the end of the line is ignored. Note that there is no closing symbol. The double slash comment is basically a single line comment. Multiline comments can be written as follows: // This is an example of // C++ program to illustrate // some of its features The C comment symbol...