C++ | Part -1 | TPS Computer Science

Probable Marks : 41

Above probable marks means : In board exam questions asked form this chapter are nearly for 41 marks out of 50 Marks.

Scope of the Syllabus

1. Review of C++

2. Arrays, pointers, references, strings

3. Principle of object oriented programming

4. Classes and objects

6. Constructors and destructors

7. Operator overloading and type conversions

8.Inheritance

9. Virtual functions and polymorphism

10. Working with files

REVIEW OF C++

Q.1 What is C++ ? What are the advantages of C++ ?

  Asked in Board Exam  (March 2003, 13)  Important

Ans:
C++ is an object oriented programming language. Initially C++ was named as “C with classes”.
C++ was developed by Bjarne Stroustrup at AT & T Bell Laboratories, USA, in the early eighties.

The advantages of C++ over C are :
(i) C++ is an incremented version of C. It is a superset of C. Almost all C programs can also run in C++ compiler.

(ii) The important facilities added in C++ are classes, function overloading, operator overloading.

(iii) C++ allow user to create abstract data types, to inherit properties from existing data types.

(iv) C++ supports polymorphism.

(v) Any real life application systems such as editor, compiler, databases, communication systems can be built by C++.

(vi) Object oriented libraries can be built by C+.

(vii) C++ programs can be easily implemented, maintained and expanded.


Q.2 Differentiate between traditional procedural programming approach and object oriented
programming approach.

  Asked in Board Exam  (Oct. 2002, 2005; March 2011)  Important

Ans. : The differences between traditional procedural programming approach and object oriented, programming approach are as follows :

Traditional procedural programming approach

  1. In this approch the problem is viewed as a sequence of things to be done.
  2. Emphasis is on doing things
  3. Data move openly around the system from function to function.
  4. Employes top-down approch in program design

object oriented programming approach

  1. In this approach, the problem is decomposed into a number of entities called objects and then builds data and function around these entities.
  2. Emphasis is on the data rather than Procedure
  3. Programs are divided into entities known as objects.
  4. Data is hidden and cannot be accessed by external functions.
  5. Follows bottom-up approach in program design.

Q.3 What are the diffrent data types in C++ ?

Ans: Data types in C+ are shown in figure below :

What are the diffrent data types in C++

2) C++ allows user to create new abstract data types which can behave like any built in data type. These are called user-defined data types. These include structure, union, class and enumeration.

3) C++ provides three built in data types which are intergral, void and floating.

4)Intergral includes integer and character (string) while floating types includes float and double.

5) In addition to these data types, C++ provides user with arrays, functions and pointers, which are referred as derived data types.


Q. 4 Enlist the basic data types used in C++ with size of data in terms of bytes for each.

  Asked in Board Exam  (March 2002, 2006, October 2006)  Important

Ans. There are three main basic built-in data types used in C++ viz. integral type, void and floating type.

built-in data types used in C++

i) Integral data type :
It includes integer (int) and character (char).
An int variable requires 2 bytes to store, while a character variable requires 1 byte.
Integer variables are also of two types : (a) short int and (b) long int. Long integer requires
4 bytes, while short integer requires 2 bytes.

ii) Void data type:
Void data type is used :
(a) to specify the return type of a function when it is not returning any value.
(b) to indicate an empty argument list to a function.
(c) to declare generic pointers.

iii) Floating type :
Floating type variables are of two types; float and double. A float variable requires 4 bytes,while double requires 8 bytes to store in memory.
There is another kind of double namely long double, which requires 10 bytes to store in memory.
The following table shows all basic data types, size and range :

basic data types, size and range

Q.5 Explain insertion and extraction operators in C++

  Asked in Board Exam  (March 2012)  Important

Ans. : (i) Insertion operator :
The operator “<<” is called as insertion operator. It is also called as “put to” operator,
inserts the contents of the variables on its right to the object on its left.
It is generally used in output statement in C++.

e.g. (i) Cout <<a ;
(ii) Cout << “program”;

In first example, the value of variable ‘a’ is printed on screen, while in second example the word “program” is printed on screen.

(ii) Extraction operator :
The operator “>>” is called as extraction operator. It is also called as ‘get from’ operator, It extracts or takes the value from keyboard and assigns it to a variable on its right. It is used in input statement in C++

e.g. Cin >> a;
This instruction will extract a value from keyboard and assign it to the variable a.
C++ allows us to redefine insertion and extraction operators by overloading them.


Q.6 Write a short note on scope resolution operator.

  Asked in Board Exam  (Oct. 2014; Mar.14 )  Important

Ans: 1) The operator :: is called as scope resolution operator.

2) C++ is ablock structured language i.e. a C++ program may contain one block within anothe r block.

3) When.a variable is declared in program, scope extends from the point of declaration till the end of the block in which itis defined.

4) The same variable name can be used to have different meaning in different blocks.

5) Consider the following segment of program.

scope resolution operator

Here Block 2 is contained in Block 1, Note that declaration of a variable in an inner block
hides the declaration of the same varlable in an outer block

6) Scope resolution operator is used to uncover a hidden variable It takes from

 Scope resolution operator

The output will be as follows :
Local x is 1

Global x is 10


Sharing Is Caring:

Leave a Comment