Chapter 1

Introduction to C++

CHAPTER OUTLINE
1.1   DIFFERENCES BETWEEN C AND C++

Some differences between C and C++ are as follows:

  1. C is a procedure/function-oriented language and C++ language is driven by a procedure/object.
  2. Data is not protected in C, whereas data is secured in C++. Data hiding concept is absent in C.
  3. C uses a top down approach while C++ uses a bottom up approach. The program is prepared step by step in C, and in C++ base elements are prepared first.
  4. In C, we cannot give the same name to two functions in a program, whereas due to the function overloading feature, the above concept is possible in C++. One can initialize a number of functions with the same name, but with different arguments. The polymorphism feature is built in C++, which supports this concept.
  5. C uses printf() and scanf() functions to write and read the data respectively, while C++ uses cout and cin objects for output and input operations, respectively. Further, the cout uses << (insertion operator) and cin uses >> ( extraction operator).
  6. C uses stdio.h file for input and output functions, whereas C++ uses iostream.h for these functions.
  7. Constructor and destructors are absent in C and the same are provided in C++.
  8. Inline functions are supported by C++, and the same are absent in C. Inline functions can be used as micros. They are stated by a word ‘inline’.
1.2   EVOLUTION OF C++

C++ is an object oriented programming language and also considered as an extension of C. Bjarne Stroustrup at AT&T Bell Laboratories in Murray Hill, New Jersey (USA) developed this language in the early 1980s. Stroustrup, a master of Simula67 and C, wanted to combine the features of both the languages and he developed a powerful language that supports object-oriented programming with features of C. The outcome was C++ as per Fig. 1.1. Various features were derived from SIMULA67 and ALGOL68. Stroustrup called the new language ‘C with classes’. However, in 1983, the name was changed to C++.

Fig. 1.1

Fig. 1.1 Evolution of C++

The thought of C++ came from the C increment operator ++. Rick Mascitti coined the term C++ in 1983. Therefore, C++ is an extension of C. C++ is a superset of C. All the concepts of C are applicable to C++ also.

For developing complicated applications, object oriented language such as C++ is the most convenient and easy. Hence, a programmer must be aware of its features.

1.3   THE ANSI STANDARD

The ANSI stands for American National Standards Institute. This Institute was founded in 1918. The main goal for establishing this Institute was to suggest, reform, recommend, and publish standards for data processing in the USA. This committee sets up the standard in the computer industry.

The recognized council working under the procedure of the American National Standards Institute (ANSI) has made an international standard for C++. The C++ standard is also referred to as ISO (International Standards Organization) standard. The process of standardization is gradual and the first draft of the planned ANSI standard was made on 25 January 1994. This book will continue to refer ANSI standard code, which is more commonly used. The ANSI standard is an attempt to ensure that the C++ is portable.

1.4   THE OBJECT ORIENTED TECHNOLOGY

Nature is composed of various objects. Living beings can be categorized into different objects.

Let us consider an example of a teaching institute which has two different working sections – teaching and non-teaching. Further sub-grouping of teaching and non-teaching can be made for the coordination of management. The various departments of any organization can be thought of as objects working for certain goals and objectives.

Usually an institute has faculty of different departments. The Director/Principal is a must for the overall management of the institute. The Academic Dean is responsible for the academics of the institute. The Dean for Planning should have the future plans of the institute and he/she must see how the infrastructure is utilized effectively. The Dean R&D should see research activities run in the institute forever.

Besides teaching staff there must be laboratory staff for assistance in conducting practical sessions, and a site development section for beautification of the campus. The accounts department is also required for handling monetary transactions and salaries of the employees. The Sports section is entrusted the responsibility of sports activities. The Registrar for Administration and staff for dealing with administrative matters of the institute are also required. Each department has an in-charge who carries clear-cut given responsibilities. Every department has its own work as stated above. When an institute’s work is distributed into departments as shown in Fig. 1.1, it is comfortable to accomplish goals and objectives. The activities are carried on smoothly. The burden of one particular department has to be shared among different departments with personnel. The staff in the department is controlled properly and act according to the instructions laid down by the management. The faculty performs activities related to teaching. If the higher authority needs to know the details regarding the theory, practical, seminar and project loads of individuals of the department, then a person from the department furnishes the same to the higher authority. This way some responsible person from the department accesses the data and provides the higher authority with the requisite information. It is also good to think that no unconnected person from another department reads the data or attempts to make any alteration that might corrupt the data.

As shown in Fig. 1.2, an institute is divided into different departments such as library, classroom, computer laboratory, etc. Each department performs its own activities in association with the other departments. Each department may be considered as a module and it contains class and object in C++ language. This theory of class and object can be extended to every walk of life and can be implemented with software. In general, objects are in terms of entities.

Fig. 1.2

Fig.1.2 Relationship between different sections

In a nutshell, in object oriented programming objects of a program interact by sending messages to each other.

1.5   DISADVANTAGE OF CONVENTIONAL PROGRAMMING

Traditional programming languages such as COBOL, FORTRAN, C etc. are commonly known as procedure oriented languages. The program written in these languages consists of a sequence of instructions that tells the compiler or interpreter to perform a given task. Numerous functions are initiated by the user to perform a task. When a program code is large, it becomes inconvenient to manage it. To overcome this problem, procedures or subroutines were adopted to make a program more understandable to the programmers. A program is divided into many functions.

Fig. 1.3

Fig. 1.3 Flow of functions in non-OOP languages

Each function can call another function, as shown in Fig. 1.3. Each function has its own task. If the program is too large the function also creates problems. In many programs, important data variables are declared as global. In case of programs containing several functions, every function can access the global data as per the simulation in Fig. 1.4. In huge programs it is difficult to know what data is used by which function. Due to this the program may contain several logical errors.

Fig. 1.4

Fig. 1.4 Sharing of data by functions in non-OOP languages

The following are the drawbacks observed in monolithic, procedure, and structured programming languages:

  1. Huge programs are divided into smaller programs known as functions. These functions can call one another. Hence security is not provided.
  2. No importance is given to security of data and importance is laid on doing things.
  3. Data passes globally from function to function.
  4. Most function accesses global data.
1.6   PROGRAMMING PARADIGMS
  1. Monolithic Programming:
    • In these types of programming languages, the program is written with a single function. A program is not divided into parts; hence it is named as monolithic programming. It is also called single thread execution.
    • When the program size increases it leads to difficulty.
    • In monolithic programming languages such as basic and assembly language, the data variables declared are global and the statements are written in sequence.
    • The program contains jump statements such as goto that transfers control to any statement as specified in it. Fig. 1.5 shows a program of monolithic type. The global data can be accessed from any portion of the program. Due to this reason the data is not fully protected.
    • The concept of sub-programs does not exist, and hence is useful for small programs.
    Fig. 1.5

    Fig.1.5 Program in monolithic programming

  2. Procedural/Structured Programming
    • Sometimes known as modular programming.
    • Programs written are more efficient and easier to understand and modify.
    • The procedural/structured programming languages are similar to solving a problem by human. In a nut shell, humans attempt a problem by adopting a sequence of operations.
    • It makes use of a top-down design model in which a program developer maps out the overall program structure into separate subsections.
    • Large size programs can be developed in structured programming such as Pascal and C. Programs are divided in multiple sub-modules.
    • Procedural/Structured programming languages such as FORTRAN, BASIC, ALGOL, COBOL, C, etc., are divided into a number of segments called as subprograms. There is a main function and it invokes subprograms. Thus, it focuses on functions apart from data. Figure 1.6 describes a program of procedural/structured type. It shows different sub-programs accessing the same global data. Here also the programmer can observe the lack of secrecy.
    • The control of program can be transferred using unsafe goto statement.
    • This type of programming language uses different control structures that are as follows.
      • Decision/selection control statements
      • Iteration control statements
      • Jump control statements
    • Data are global and all the sub-programs share the same data, i.e. data are globally accessible to all functions. Thus, any function operates on the global data and this directs to loosing some vital information. We can conclude here that a module represents a function.
    • Procedural structured/programming languages permit data transfer through messages by means of functions.
    • Least importance is given to the data in procedural/structured programming languages.
    • These languages are used for developing medium-sized software applications.
    • Complier and interpreter construction are easy and simple with this type of programming language. Furthermore, these compilers and interpreters need low memory to run on the computers.
    • It is difficult to implement simultaneous processes/parallelization.
    Fig. 1.6

    Fig. 1.6 Program in procedural/structured programming

1.7   PREFACE TO OBJECT ORIENTED PROGRAMMING

The prime factor in the design of object oriented programming approach is to rectify some of the faults observed in the procedure oriented languages. OOP acts with data as a critical component in program development. It does not allow the data to flow freely around the systems. It ties data to the functions that operate on it and prevents it from accidental change due to external functions. OOP permits us to analyze a problem into a number of items called objects and then assembles data and functions around these items as per Fig. 1.7. Following are the impressive characteristics of object-oriented programming:

  1. OOP pays more importance to data rather than function.
  2. Programs are divided into classes and their member functions.
  3. OOP follows a bottom-up approach.
  4. New data items and functions can be comfortably added whenever essential.
  5. Data is private and prevented from accessing external functions.
  6. Objects communicate with each other through functions.
Fig. 1.7

Fig.1.7 Relation between data and member function in OOP

1.8   KEY CONCEPTS OF OBJECT ORIENTED PROGRAMMING

Object oriented programming language is a feature that allows a mode of modularizing programs by forming ory area for data as well as functions that is used as object for making copies of modules as per requirement.

There are several fundamental concepts in object oriented programming. They are shown in Fig. 1.8 and are discussed as follows.

Fig. 1.8

Fig.1.8 Concepts/elements of object oriented paradigm

(1) Objects

Objects are primary run-time entities in object oriented programming.

Objects are primary run-time entities in object-oriented programming. They may stand for a thing that makes sense in a specific application. Some examples are a spot, a person, any data item related to the program including user-defined data types. Programming issues are analyzed in terms of object and the type of transmission between them. Program objects must be selected like the items equivalent to actual world objects. Objects occupy space in memory. Every object has its own properties or features that illustrate what the object can do. An object is a specimen of a class. It can be singly recognized by its name. It declares the state that is shown by the data values of its characteristic at a specific time. The state of the object varies according to the procedure used with it. It is called as the action of the object. The action of the object depends upon the member function defined within its class.

Fig. 1.9 (a) shows some of the objects that we use in our daily life.

Fig. 1.9(a)

Fig.1.9 (a) Commonly available objects

Object: City

Data:

Name_of_city

Population

Area

Functions:

Average age

Literacy_rate

Display

Fig. 1.9 (b) Representation of an object

Objects communicate with each other by sending messages. An object can be represented by Fig 1.9 (b).

The name of the above object is city. Its data members are name_of_city, population, and area. The various functions associated with the city are average age, literacy_ rate, and display.

(2) Classes

A class is grouping of objects that have the identical properties, common behavior, and shared relationship. A class binds the data and its related functions together.

A class is the accomplishment of abstract data type. It defines the nature and methods that act on the data structure and abstract data type, respectively. Specimens are also called as objects. In other words, a class is a grouping of objects that have identical properties, common behavior, and shared relationship. For example, Tata’s Swift, Maruti’s Alto etc. are the members of a class car.

The entire group of data and code of an object can be built as a user-defined data type using class. Objects are nothing but variables of type class. Once a class has been declared, the programmer can create a number of objects associated with that class. The syntax used to create an object is similar to the syntax used to create an integer variable in C. A class is a model and not a true specimen of the object. Every object has its own value for each of its member variables. However, it shares the property names or operations with other instances of the class. Thus, classes define the characteristic and action of objects.

Fig. 1.10

Fig. 1.10 Objects and their properties

In Fig. 1.10 commonly useful classes are described with their properties and action they perform. For example, a car has properties like company, model and color with which a car can be identified among a number of cars of other properties, and the actions like speed() and average() describes its working.

Fig. 1.11

Fig. 1.11 Classes and their members

Figure 1.11 describes the classes and related data that come under the different classes.

(3) Method

An operation required for an object or entity when coded in a class is called a method.

An operation required for an object or entity when coded in a class is called a method. The operations that are required for an object are to be defined in the class. All objects in a class carry out certain common actions or operations. Each action needs an object that becomes a function in the class that defines it and is referred to as a method.

In Fig. 1.12 the class and its associated data members and functions are shown in different styles. It is a frequent style of writing a class in the program.

The class A contains private data members and public methods or member functions. Usually, the data members are declared private and methods or member functions are declared as public and they are available outside the class. The data member of any class uses its member functions or methods to perform operations.

Fig. 1.12

Fig.1.12 (a) and (b) Representation of methods in different manners

(4) Data Abstraction

Abstraction refers to the procedure of representing essential features without including the background details.

Abstraction refers to the procedure of representing essential features without including the background details. Classes use the theory of abstraction and are defined as a list of abstract properties such as size, cost, height, and few functions to operate on these properties. Data abstraction is the procedure of identifying properties and method related to a specific entity as applicable to the application.

A powerful method to achieve abstraction is through the manipulation of hierarchical classifications. It permits us the breaking of semantics of multiple systems into layers by separating them into multiple controllable parts. For example, a computer as shown in Fig. 1.13 is made of various parts such as CPU, keyboard, and so on. We think it as a single unit, but the single unit has several sub-units. They together do the single task. By assembling sub-parts we can build a single system.

Hierarchical abstraction of complicated systems can also be used in computer software. The data from conventional procedure oriented programs can be converted by abstraction mechanism into its partial objects. A series of operation steps may develop a set of messages between these objects. Each object shows its own attributes.

Data abstraction is used to define a data type available in the programming language, called as abstract data type (ADT). It consists of a set of values and a set of operations.

Fig. 1.13

Fig 1.13 Computer and its parts

(5) Encapsulation

The packing of data and functions into a single component is known as encapsulation.

C++ supports the features of encapsulation using classes. The packing of data and functions into a single component is known as encapsulation. The data is not reachable by the outside functions. Only those functions that are able to access the data are defined within the class. These functions prepare the interface between the object’s data and the program. With encapsulation we can accomplish data hiding. Data hiding is an important feature using which an object can be used without the user knowing how it works internally.

In C++ the fundamental of encapsulation is class. A class defines the structure of data and member functions. It is common to all its objects. Class is a logical structure whereas object is a physical actuality. The goal of the class is to encapsulate complication. The class also has a mechanism for hiding the data. Each member in the class may be private or public. Any non-member function cannot access the data of the class. The public section of the class must be mindfully coded not to expose the inner details of the class. Figure 1.14 explains sections of encapsulation.

Fig. 1.14

Fig. 1.14 Encapsulation: Private and public sections

(6) Inheritance

Inheritance is the method by which objects of one class get the properties of objects of another class.

Inheritance is the method by which objects of one class get the properties of objects of another class. In object oriented programming inheritance provides the thought of reusability. The programmer can add new properties to the existing class without changing it. This can be achieved by deriving a new class from the existing one. The new class will possess features of both the classes. The actual power of the inheritance is that it permits the programmer to reuse a class that is nearly, but not precisely, what he wants, and to tailor the class in such a manner that it does not bring any unwanted incidental result into the rest of the class. Thus, inheritance is the feature that permits the reuse of an existing class to make a new class. Figure 1.15 shows an example of inheritance.

Fig. 1.15

Fig. 1.15 Inheritance

In Fig. 1.15, red, yellow and blue are the main colors. The orange is created from the combination of red and yellow, green is created from yellow and blue and violet is created from red and blue. The orange color has attributes of both red and yellow, which produces a new effect. Thus, many combinations are possible.

(7) Polymorphism

Polymorphism allows the same function to act in a different way in different classes.

Polymorphism makes it possible for the same functions to act differently on different classes as shown in Fig. 1.16. It is an important feature of OOP concept. It holds an ability to take more than one form. Polymorphism accomplishes an important part in allowing objects of different classes to share the same external interface. It is possible to code a non-specific (generi(c) interface to a set of associated actions.

Fig. 1.16

Fig. 1.16 Polymorphism in OOP

(8) Dynamic Binding

Binding means connecting one program to another program that is to be executed in reply to the call.

Binding means connecting one program to another program that is to be executed in reply to the call. Dynamic binding is also known as late binding. The code present in the specified program is unknown till it is executed. It is analogous polymorphism.

In Fig. 1.16 polymorphism allows the single object to invoke similar function from different classes. The program action is different in all the classes. At execution time, the code analogous to the object under the present reference will be executed. The reader is advised to refer polymorphism chapter for more details.

(9) Message passing

An object oriented programming includes objects. The objects communicate with one another. The programming with these objects should be followed with following steps.

  1. Declaring classes that define objects and their actions.
  2. Declaring objects from classes.
  3. Implementing relation between objects.

Data is transferred from one object to another object. A message for an object is the demand for implementation of the process. Message passing consists of indicating the name of the object, function, and required data elements (Fig. 1.17). Objects can be created, released, and interacted with each other. An object is workable, as long as it is active. In object oriented programming there is a panorama of independent objects that communicate with each other by swapping messages. Objects invoke member functions. They also negate if the calling object is not a member of the same class. Thus a message is a solicitation to an object to call one of its member functions. A message contains name of the member function and parameters of the function. Execution of member function is just a response generated due to receipt of a message. It is possible when the function and the object are of the same class.

Fig. 1.17

Fig. 1.17 Message Passing

(10) Reusability

Object oriented technology allows reusability of the classes by extending them to other classes using inheritance.

Object oriented technology allows reusability of the classes by extending them to other classes using inheritance. Once a class is defined, the other programmer can also use it in their programs. The programmer can also add new feature to the derived classes. The verified and checked qualities of base classes need not to be redefined. Thus, the reusability saves the time. In Fig. 1.18, class A is reused and class B is created. Again class B is reused and class C is created.

Fig. 1.18

Fig.1.18 Reusability

(11) Delegation

In OOP, two classes can be joined in two ways: (a) Inheritance, (b) Delegation. Both these ways provide reusability of the class.

In Inheritance one class can be derived from the other class. The relationship between these two classes is called as kind of relationship. For example if class Y is derived from class X, then class Y is known as kind of X. Figure 1.19 (a) explains this point.

Fig. 1.19

Fig.1.19 Relationships between two classes: (a) Kind of relationship (Inheritance) (b) has a relationship (Delegation)

The second type of relationship is has a relationship. When object of one class is used as data member in the other class, such composition of objects is known as delegation. As shown in Fig. 1.19 (b) class C has two data members. These two data members are objects of class A and B, such relationship between the classes in known as has a relationship.

(12) Genericity

The software components of a program have more than one version depending on the data types of arguments. This feature allows declaration of variables without specifying exact data type. The compiler identifies the data type at run time. The programmer can create a function that can be used for any type of data. The template feature in C++ allows generic programming.

1.9   ADVANTAGES OF OOP

Object oriented technology provides many advantages to the programmer and the user. This technology solves many problems related to software development, provides improved quality and low cost software.

  1. Object oriented programs can be comfortably upgraded.
  2. Using inheritance, we can eliminate redundant program code and continue the use of previously defined classes.
  3. The technology of data hiding facilitates the programmer to design and develop safe programs that do not disturb code in other parts of the program.
  4. The encapsulation feature provided by OOP languages allows programmer to define the class with many functions and characteristics and only few functions are exposed to the user.
  5. All object oriented programming languages allows creating extended and reusable parts of programs.
  6. Object oriented programming changes the way of thinking of a programmer. This results in rapid development of new software in a short time.
  7. Objects communicate with each other and pass messages.
1.10   OBJECT ORIENTED LANGUAGES

There are many languages which support object oriented programming. Tables 1.1 and 1.2 describe the OOP languages and features supported by them.

 

Table 1.1 Properties of pure OOP and object based languages

Table 1.1

Table 1.2 Properties of extended traditional languages

Table 1.2

The following are the object-oriented languages, which are widely accepted by the programmer.

  • C++
  • Smalltalk
  • Charm ++
  • Java

SMALLTALK

Smalltalk is a pure object oriented language. C++ makes few compromises to ensure quick performance and small code size. Smalltalk uses run-time binding. Smalltalk programs are considered to be faster than the C++. Smalltalk needs longer time to learn than C++. Smalltalk programs are written using Smalltalk browser. Smalltalk uses dynamic objects and memory is allocated from free store. It also provides automatic garbage collection and memory is released when object is no longer in use.

CHARM++

Charm ++ is also an object oriented programming language. It is a portable. The language provides features such as inheritance, strict type checking, overloading, and reusability. It is designed in order to work efficiently with different parallel systems together with shared memory systems, and networking.

JAVA

Java was developed by Patrick Naughton, James Gosling, Chris Warth, Mike Sheridan and Ed Frank at Sun Microsystems. Java is an object oriented programming language and supports maximum OOP characteristics exist. Its statement structure is like C and C++, but it easier than C++. Java excludes few confusing and unsafe features of C and C++ like pointers.

Java allows client/server programming. Java is used for Internet programming. The Java programs are downloaded by the client machines and executed on different types of hardware. This portability is achieved by translation of Java program to machine code using compiler and interpreter.

The Java compiler converts the source program to JVM (Java virtual machine). The JVM is a dummy CPU. The compiler Java program is called as byte code. The Java interpreter translates byte code into the object code. Compiler and interpreter do the conversion of Java program to object code.

1.11   USAGE OF OOP

Object oriented technology is changing the style of software engineers to think, analyze, plan, and implement the software. The software developed using OOP technology is more efficient and easy to update. OOP languages have standard class library. The users in their program can reuse the standard class library. Thus, it saves lot of time and coding work.

The most popular application of object oriented programming is windows. There are several windowing software based on OOP technology. Following are the areas for which OOP is considered.

  1. Simulation
  2. Object oriented DBMS
  3. Office automation software
  4. Artificial Intelligence and expert systems
  5. CAD/CAM software
  6. Network programming & Internet applications
  7. System software
1.12   USAGE OF C++

C++ is a flexible language. Lengthy programs can be easily controlled by the use of C++. It permits us to create hierarchy -associated objects and libraries that can be useful to other programmers. C++ helps the programmer to write bug-free program, which are easy to maintain.

SUMMARY
  1. C++ is an object oriented programming language invented by Bjarne Stroupstrup at AT&T Bell Laboratories.
  2. The recognized council working under the procedure of the American National Standard Institute (ANSI) has made an international standard for C++.
  3. The disadvantage in conventional programming language is that the program written in these languages consists of a sequence of instructions that tells the compiler or interpreter to perform a given task. When program code is large then it becomes inconvenient to manage.
  4. The prime factor in the design of object oriented programming approach is that to get back some of the faults found in the procedure oriented languages.
  5. In monolithic programming languages such as basic and assembly language, the data variables declared are global and the statements are written in sequence.
  6. In the procedural programming languages such as FORTRAN and COBOL, programs are divided into number of segments called as subprograms. Thus it focuses on functions apart from data.
  7. Larger programs are developed in structured programming such as Pascal and C. Programs are divided in multiple sub modules and procedures.
  8. OOP acts with data as a critical component in the program development and does not let the data to flow freely around the systems.
  9. Object: Objects are primary run-time entities in an object-oriented programming. They may stand for a thing that makes sense in a specific application.
  10. Class: A class is grouping of objects that have the identical properties, common behavior, and shared relationship. The entire group of data and code of an object cab be built as a user-defined data type using class.
  11. Method: An operation required of an object or entity when coded in a class is called a method.
  12. Data Abstraction: Abstraction directs to the procedure of representing essential features without including the background details.
  13. Encapsulation: C++ supports the features of encapsulation using classes. The packing of data and functions into a single component is known as encapsulations.
  14. Inheritance: Inheritance is the method by which objects of one class get the properties of objects of another class. In object oriented programming inheritance provides the thought of reusability.
  15. Polymorphism: Polymorphism makes possible the same functions to act differently on different classes. It is an important feature of OOP concept.
  16. Object oriented technology allows reusability of the classes by extending them to other classes using inheritance.
  17. The languages C++, Smalltalk, Eiffel and Java are widely used OOP languages.
  18. Object oriented technology is changing the style of software engineers to think, analyze, plan and implements the software. The software developed using OOP technology is more efficient and easy to update.
  19. C++ is a flexible language. Lengthy programs can be easily controlled by the use of C++.
EXERCISES

(A) Answer the following questions.

  1. Compare C and C++.
  2. What is object oriented programming?
  3. Explain the key concepts of OOP.
  4. What is ANSI standard?
  5. What are the disadvantages of conventional programming languages?
  6. Explain the characteristics of monolithic programming languages.
  7. Compare structured and procedural languages.
  8. List the disadvantages of procedural programming languages.
  9. Explain evolution of C++.
  10. List the names of popular OOP languages.
  11. List the unique features of an OOP paradigm.
  12. What is an object and class?
  13. How is data secured in OOP languages?
  14. Compare and contrast OOP languages with procedure oriented languages.
  15. Mention the types of relationships between two classes.
  16. What is structured oriented programming? Discuss its pros and cons.
  17.  How is global data shared in procedural programming?
  18. Describe any two object oriented programming languages.
  19. What are the differences between Java and C++?
  20. Mention the advantages of OOP languages?
  21. What do you mean by message passing?
  22. Distinguish between inheritance and delegation.
  23. Can we define member functions in private section?
  24. Can we declare data member in the public section?

(B) Answer the following by selecting the appropriate option.

  1. Data hiding concept is supported by language
    • C
    • Basic
    • Fortran
    • C++
  2. Function overloading means
    • different functions with different names
    • function names are same but same number of arguments
    • function names are same but different number of arguments
    • none of the above
  3. C++ language was invented by
    • Bjarne Stroupstrup
    • Dennis Ritche
    • Ken Thompson
    • none of the above
  4. The languages COBOL and BASIC are commonly known as
    • procedure oriented languages
    • object oriented languages
    • low level languages
    • none of the above
  5. A program with only one function is observed in
    • monolithic programming languages.
    • object oriented languages
    • structured programming languages
    • none of the above
  6. The packing of data and functions into a single component is known as
    • encapsulation
    • polymorphism
    • abstraction
    • none of the above
  7. The method by which objects of one class get the properties of objects of another class is known as
    • inheritance
    • encapsulations
    • abstraction
    • none of the above
  8. The mechanism that allows same functions to act differently on different classes is known as
    • polymorphism
    • encapsulations
    • inheritance
    • none of the above
  9. The existing class can be reused by
    • inheritance
    • polymorphism
    • dynamic binding
    • abstraction
  10. Composition of objects in a class is known as
    • delegation
    • inheritance
    • polymorphism
    • none of the above
  11. A class
    •  binds the data and its related functions together
    • data and their addresses
    • contains only functions
    • none of the above
  12. The major drawback of procedural programming languages is
    • frequently invoking functions from main()
    • non security of data
    • non security of methods
    • none of the above
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset