Posts

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

Application of OOP

OOP has become one of the programming buzzwords today. There appears to be a great deal of excitement and interest among software engineers in using OOP. Applications of OOP are beginning to gain importance in many areas. The most popular application of object-oriented programming, up to now, has been in the area of user interface design such as window. Hundreds of windowing systems have been developed, using the OOP techniques. Real-business system are often much more complex and contain many more objects with complicated attributes and method. OOP is useful in these types of application because it can simplify a complex problem. The promising areas of application of OOP include:  Real-time system  Simulation and modeling Object-oriented data bases Hypertext, Hypermedia, and expertext AI and expert systems  Neural networks and parallel programming Decision support and office automation systems  CIM/CAM/CAD systems  The object-oriented paradigm sprang from the language, ha

Benefits of OOP (object oriented programming)

OOP offers several benefits to both the program designer and the user. Object-Orientation contributes to the solution of many problems associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are: Through inheritance, we can eliminate redundant code extend the use of existing classes We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity. The principle of data hiding helps the programmer to build secure program that can not be invaded by code in other parts of a programs. It is possible to have multiple instances of an object to co-exist without any interference. It is possible to map object in the problem domain to those in the program. It is easy to partition the work

Object Oriented Programming Concepts

Image
It is necessary to understand some of the concepts used extensively in object-oriented programming. These include: • Objects • Classes • Data abstraction and encapsulation • Inheritance • Polymorphism • Dynamic binding • Message passing We shall discuss these concepts in some detail in this section. 1) Objects Objects are the basic run time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. They may also represent user-defined data such as vectors, time and lists. Programming problem is analyzed in term of objects and the nature of communication between them. Program objects should be chosen such that they match closely with the real-world objects. Objects take up space in the memory and have an associated address like a record in Pascal, or a structure in c. When a program is executed, the objects interact by sending messages to one another. For exam