Sie sind auf Seite 1von 13

KANHA MAKHAN PUBLIC SCHOOL

Question Bank for Half Yearly Exam (2018-19)


th
Class: 12 Subject: C++
Chapter-1: C++ REVISION TOUR
Section – A: Each question of 1 Mark.
1. Name the header files to which the following belong:
a) abs () b) strcmp() c) isupper ()
2. Name the header file: to which the following belong :
a) puts() b) isalnum ()
3. Name the header files in which the following belong:
a) pow() ii) random()
4. Give two examples of object oriented language.

Section – B: Each question of 2 Marks.


1. Observe the following program SCORE.CPP carefully, if the value of Num entered by the user is 5,
choose the correct possible output (s) from the options from (i) to (iv), and justify your option.
#include<stdlib.h>
#include<iostream.h>
void main () {
randomize ( ) ;
intNum, Rndnum;
cin>>Num;
Rndnum – random (Num) + 5;
for (int N = 1; < = Rndnum; N++)
cout<< N << “ “ ;
}
Output options:
i) 1234 ii) 1 2 iii) 1 2 3 4 5 6 7 8 9 iv) 1 2 3
2. What is the difference between global variables and local variables? Give an example to illustrate the
same.
3. Differentiate between a Run Time Error and syntax Error. Also give suitable examples of each in C++.
4. In the following program, find the correct possible output(s) the options:
#include<stdlib.h>
#include<iostream.h>
void main () {
randomize ();
char City { } { 10 } = {“DEL”, “CHN”, “KOL”, “BOM”, “BNG”};
int Fly;
for (int I = 0 , I < 3; I++){
Fly=random (2) + 1;
cout<<City[Fly]<<””;
}
}
outputs:
i) DEL:CHN:KOL: ii) CHN:KOL:CHN: iii)KOL:BOM:BNG: iv)
KOL:CHN:KOL:
5. What is the difference between type casting and automatic type conversion? Explain with suitable
example.
6. What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to
illustrate both type of parameters.
7. Go through the C++ code, show below, and find out the possible output or outputs from the
suggested Output Options (i) to (iv). Also , write the least value and highest value, which can be
assigned to the variable Guess.
#include<iostream.h>
#include<strlib.h)
void main () {
randomize ( ) ;
int Guess, High = 4;
Guess = random (High) + 50;
for (int C = Guess; C< = 55; C++)
cout<<C<<”#”;
}
i) 50# 51 # 52 # 53 # 54 # 53 #
ii) 52 # 53 # 54 # 55 #
iii) 53 # 54 #
iv) 51# 52 # 53# 54# 55 #
8. What are the applications of void data type in C++?

Chapter-2: OBJECT ORIENTED PROGRAMMING (10 Marks in Blueprint)


Section – A: Each question of 1 Mark.
1. Define the term Data Hiding in the context of Object Oriented Programming. Give a suitable
example using a C++ code to illustrate the same.
2. Define the term Data Encapsulation in the context of Object Oriented Programming. Give a
suitable example using a C++ Code to illustrate the same.
3. What do you understand by Data Encapsulation and Data Hiding? Also, give an example in C++
to illustrate both.
4. What do you understand by polymorphism? Give an example illustrating its use in a C++
program.
5. What do you mean by function overloading? Give an example illustrating its use in a C++
program.
6. What are advantages of OOPs over procedural programming?

Section – B: Each question of 2 Marks.


1. Write the output of the following C++ Code. Also, write the name of feature of Object Oriented
Programming used in the following program jointly illustrated by the functions (i) to (iv).
#include<iostream.h>
void Print () //Function[1]
{
for (int K = 1; < = 60; K++) cout<<”-“;
cout<<endl;
}
void Print(int N) //Function [II]
{
for (int K = 1; K < = N; K++) cou<<”*”;
cout<<endl;
}
void Print (int A, int B) //Function [III]
{
for (int K=1; K < = B; K++) cout<< A*K;
cout<<endl;
}
void Print(char T, int N) //Function [IV]
{
for (int K = 1; K , = N; K++) cout<<T;
cout<<endl;
}
void main () {
int U=9, V=4, W=3;
char C=’@’;
Print (C, V);
Print (U,W);
}
2. Write the output of the following C++ code. Also, write the name of feature of Object Oriented
Programming. used in the following program jointly illustrated by the functions [I] to [IV].
#include<iostream.h>
void Line () // Function [I]
{
for (int L = 1; L < = 80; L++) cout<< “-“;
cout<<endl;
}
void Line(int N) //Function [II]
{
for (int L=1; L<=N; L++) cout<<”*”;
}
void Line(char C, int N) // Function [III]
{
for (int L = 1; L < = N; L++) cout<<C;
cout<<endl;
}
void Line(int M, int N) //Function [IV]
{
for (int L = 1; L ++) cout<<M*L;
cout<<endl;
}
void main ( ) {
int A=9, B=4, C=3;
char K = ‘#’;
Line (K, B);
Line (A, C);
}
3. How can you find a function is overloaded?
4. What is the key to reusability of OOP?
Section – C: Each question of 3 Marks.
1. When an inline function should be used?
2. When should function overloading be preferred over default argument?
Chapter-3: FUNCTION OVERLOADING (10 Marks in Blueprint)
Section – A: Each question of 1 Mark.
1. How can you find a function is overloaded?
2. Is it possible to have an overloaded function with different return types but same number and
types of arguments?
Section – B: Each question of 2 Marks.
1. Write the prototype of the overloaded function called sum () that add two integer and return
integer; that add two double precision quantity and return double precision quantity; that add one
float and one integer and return floating point quantity.
2. Which function is called during each function call in the program given below:
int sum (int x); ………(I)
char choice(char a , char b); ………(II)
char choice (char a); ………(III)
float sum (int x, float y); ………(IV)
main ( ) {
int n;
charch, ch1;
float n1;
sum (n); ………(1)
choice (ch); ………(2)
choice(ch, ch1); ………(3)
sun(n, n1); ………(4)
}
Section – C: Each question of 3 Marks.
1. Differentiate between syntax and semantics of a programming language?
2. Name any three OOPs principles.
OR
Discuss the various situations when a copy constructor is automatically invoked.
Section – D: Each question of 4 Marks.
1. Write declaration for two overloaded functions named bar ( ). They both return float type. The
first takes one argument of type char and the second takes two arguments of type char. If this
impossible, say why?
OR
How is matching done in case of overloaded functions?
2. What will be the output of following program:
#inclue<iostream.h>
int are a(int s) [
return (s * s);
}
float area(int b, int h) {
return(0.5 * b * h);
}
main ( )
{
cout<< area (5) <<endl;
cout<< area(4, 3) <<endl;
cout<< area(6, area(3))<<endl;
retun 0;
}
Chapter-4: CLASS & OBJECT (10 Marks in Blueprint)
Section – A: Each question of 1 Mark.
1. What are the access labels in a class?
2. What are the advantages and disadvantages of inline functions?
Section – B: Each question of 2 Marks.
1. Rewrite the following C++ program code after removing the syntax error(s) (if any) Underline
each correction.
#include<iostream.h>
class TRAIN {
longTrainNo;
char Description [25];
public
void Entry ( ) {
cin>>TrainNo; gets(Description);
}
void Display ( ) {
cout<<TrainNo<<”:”<<Description<<endl;
}
};
void main () {
TRAIN T;
Entry.T(); Display.T ( );
}
2. Differentiate between members, which are present within the private visibility mode with those
which are present within the public visibility modes.
Section – C: Each question of 3 Marks.
1. A class called A is declared and all its data member and member functions are private. Is it
possible to declare an object of type A and use it in any function? Justify your answer.
2. What ‘s wrong with this?
class c { public : int x = 0; };
OR
How does a class enforce data hiding, abstraction and encapsulation?
OR
What is a class? How does it accomplish data hiding?
Section – D: Each question of 4 Marks.
1. Define a class Candidate in C++ with following description:
Private members
 A data member RNo (Registration Number) of type long
 A data member Name of type string
 A data member Score of type float
 A data member Remarks of type string
 A member function AssignRem ( ) to assign Remarks as per the Score obtained by a
candidate.
 Score range and the respective Remarks are shown as following:
Score Remarks
>=50 Selected
less than 50 Not selected
Public Members
 A function ENTER () to allow user to enter values for Rno, name , Score and call
function
AssignRem () to assign the remarks.
 A function DISPLAY () to allow user to view the content of all the data members.
2. Define a class Applicant in C++ with following description:
Private Members
 A data member ANo (Admission Number) of type long
 A data member Name of type string
 A data member Agg (Aggregate Marks) of type float
 A data member Grade of type char
 A member function Grademe ( ) to find the Grade as per the Aggregate marks obtained
by a student.
 Equivalent Aggregate marks range and the respective Grads are shown as follows:
Aggregate marks Grade
>80= A
less than 80 and >=65 B
less than 65 = > = 50 C
less than 50 D
Public Members
 A function ENTER ( ) to allow user to enter values for ANo, Name, Agg& call function
GradeMe () to find the Grade.
 A function RESULT () to allow user to view the content of all the data members.
Chapter-5: Constructor and Destructors (10 Marks in Blueprint)
Section – A: Each question of 1 Mark.
1. How constructor overloading different from function overloading?
2. What is the difference between the constructor and the normal function?
OR
Distinguish between the following two statements:
Time T1 = (11, 12, 20);
Time T1 = Time(11, 12, 20);
Section – B: Each question of 2 Marks.
1. Identify the syntax errors(s), if any, and give reason for error:
class ABC
{
int x = 10;
float y;
ABC( ) { y = 5; }
~ABC( ) { }
};
void main( )
{
ABC a1,a2;
}
2. Write the output of the following program:
#include<iostream.h>
class Counter
{
unsignedint count;
public:
Counter( ) { count = 0; }
voidincCount( ) { count ++; }
intgetCount( ) { return count; }
};
void main( )
{
Counter C1, C2;
cout<<”\n C1 = “<<C1.getCount( );
cout<<”\n C2 = “<<C2.getCount( );
C1.incCount( );
C2.incCount( );
Cout<<”\n C1 = “<<C1.getCount( );
Cout<<”\n C2 = “<<C2.getCount( );
}
3. What is default constructor? How does it differ from destructor?
4. Answer the questions (i) and (ii) after going through the following class:
class Exam
{
int year;
public:
Exam(int y) { year = y; } //Constructor 1
Exam(Exam &t); //Constructor 2
}
(i) Create an object, such that it invokes Constructor 1.
(ii) Write the complete definition for Constructor 2.
5. In what order will be the constructor be invoked for the following program segment:
class distance
{ };
class time
{ };
class figure
{
int plane( );
distance dist;
timestime;
….
….
};
main( )
{
time T1;
distance D1;
figure F1;
….
….
}
6. When is a constructor called? When is a destructor called?
Section – C: Each question of 3 Marks.
1. Discuss about copy constructor with example code.
2. What will be the output of the following program:
#include<iostream.h>
classmyclass
{
inta,b;
public:
myclass(int x, int y); //constructor
void show( );
};
myclass :: myclass(int x, int y)
{
cout<<”In constructor\n”;
a = x;
b = y;
}
voidmyclass :: show( )
{
cout<<a<<’ ’<<b<<endl;
}
void main( )
{
myclassob(7, 9);
Ob.show( );
}
Chapter-6: Inheritance (10 Marks in Blueprint)
Section – A: Each question of 1 Mark.
1. When we would we use inheritance?
2. What is the benefit of declaring a data member as protected?
OR
What will happen in the absence of the constructor in the inherited class?
Section – B: Each question of 2 Marks.
1. Identify the errors in the following program:
classmyclass
{
private:
Int a;
public:
void display( )
{
cout<<a<<endl;
}
};
class myclass1
{
int a1;
public:
void display( )
{
cout<<a1<<endl;
}
};
classyourclass : public myclass, private myclass1
{
…..
…..
};
void main( )
{
yourclassobj;
obj.display( );
objmyclass :: display( )
obj.myclass1 :: display( )
}
2. What will be the output of the following program code:
class A
{
int x1, x2;
public:
A( )
{
Cout<<”Base Class A\n”;
x1 = 8;
x2 = 7;
}
};
class B : public A
{
int y;
public:
B( )
{
Cout<<”Derived Class B\n”;
}
};
Void main( ) {
B obj;
}
Section – C: Each question of 3 Marks.
1. Given the following program segment:
class B
{
int I;
public:
voidset_I(int n);
intget_I( );
};
class D : public B
{
int j;
public:
voidset_j(int n);
int add( );
};
(i) Name the base class and derived class.
(ii) Name the data member which can be used by the function set_j(int n).
(iii)Name the member functions inherited by the class D.
2. Given the following base class:
class area_c1
{
public:
double height;
double width;
};
Create two derived classes called rectangleand isosceles that inherit area_c1. Have each class included a
function called area( ) that returns the area of rectangle or isosceles triangle, as appropriate. Used
parameterized constructor to initialize height and width.
Section – D: Each question of 4 Marks.
1. Write a C++ program to read and display information about employees and managers. Employee is a
class that contain employee number, name, address and department. Manager class contains all
information of the employee class and list of employees working under a manager.
2. Answer the questions (i) to (iv) based on the following program:
class First
{
int X1;
protected:
float X2;
public:
first( );
void Enter1( );
void Display1( );
};
class Second : private First
{
int Y1;
protected:
float Y2;
public:
Second( );
void enter2( );
void Display( );
};
class Third : public Second
{
int Z1;
public:
Third( );
void Enter3( );
void display( );
};
void main( )
{
Third T; //Statement 1
______; //Statement 2
}
(i) Which type of Inheritance is implemented inabove program?
(ii) Write the names of all the member functions, which are directly accessible by the object T
declared in main( ).
(iii) Write Statement 2 to call function Display( )of class Secondfrom the object T.
(iv) What will be the order of execution of the constructors, when the object T is declared inside
main( )?
Chapter-7: Pointers (10 Marks in Blueprint)
Section – A: Each question of 1 Mark.
1. Write the statements that store and display the address of a variable num.
OR
Are the expression (*p)++ and ++*p same? Justify your answer.
2. What is the meaning of **p?
OR
What is wrong with this?
main( )
{
int *ptr;
*ptr = 10;
}
Section – B: Each question of 2 Marks.
1. Identify the syntax error(s), if any, in the following program. Also give the reason for errors.
void main( )
{
Constinti = 20;
Constint * constptr = &i;
(*ptr)++;
int j = 15;
ptr = &j;
}

2. Give the output of following program segment:


void main( )
{
int a = 32, *X = &a;
charch = 65, &eco = ch;
eco + = a;
*X + = ch;
cout<<a<<’,’<<ch<<endl;
}
OR
Distinguish between:
int *ptr = new int(5); and int *ptr = new int[5];

Section – C: Each question of 3 Marks.

1. What is the output of following program:


#include<iostream.h>
void main( )
{
int a = 32;
int *ptr = &a;
charch = ‘A’;
char *cho = &ch;
cho += a;
*ptr+=ch;
cout<<a<<” ”<<ch<<endl;
}
2. Find the output of the following program:
#include<iostream.h>
void main( )
{
int points = 300;
int *start = &points;
int *end;
end = new int;
(*end) = points – 150;
points += 100;
cout<<points<<” :”<<*start<<endl;
cout<<*end<<endl;
start = end;
cout<<points<<” :”<<*start<<endl;
points -= 100;
*start -= 50;
cout<<points<<”:”<<*start<<endl;
}
OR
Write the appropriate declaration for the following statements:
(i) Declare two pointers to character named a andb.
(ii) Declare a function that accepts two floating point arguments and return a pointer to a long
float.
(iii) Declare a pointer to double precision quantity.

Section – D: Each question of 4 Marks.

1. Write a program to reverse the string using pointer.


2. Given the following definition:
int x = 20;
int *p;
double *d;
Which of the following assignments are invalid? Why?
(i) x = 20 (ii) *p = i (iii) p = x (iv) *p = &x
(v) x = p (vi) d = p (vii) d = *p (viii) d = &x

Das könnte Ihnen auch gefallen