Sunteți pe pagina 1din 22

1.

2.

Find the outputof the following program:


#include<iosteam.h>
Void main( )
{
int u = 10, v = 20 ;
for (int I = 1 ; I <= 2 ;I++)
{
Cout << [1] << u++ << & << v 5 << endl ;
Cout << [2] << ++ v << & << u + 2 << endl ;
}
}
[1] 10 & 15
[2] 21 & 13
[3] 11 & 16
[4] 22 &14
Rewrite the following program after removing the syntactical error(s) if
any. Underline each correction .

67/1

68/2

#include <iosteam.h>
Void main( )
{ First = 10, second = 20 ;
Jumpto (First ; second) ;
Jumpto (second) ;
}
Void jumpto (int N1, int n2 = 20)
{

N1 = N1 + N2
cout << N1 >> N2 ;

3.

(i)

#include <ioseam.h>
Void main( )
{
int first = 10, second = 20 ;
Jumpto(first, sfcond) ;
Jumpto(second) ;
}
Void jumpto(int N1 int N2 = 20)
{
N1=N1 + N2 ;
Cout << N1 << N2 ;
}
What is wrong with the following while loops (and how does the correct
ones look like) :
(i) int counter = 1 ;
(ii) int counter = 1 ;
While (counter < 100)
while (counter < 100)
{
cout << counter << \n ;
counter++ ;
Counter - - ;
}
In this loop the variable counter initialized to 1 . Inside the loop, counter
thedecremented so it will have value 1, 0, 1, 2, 3,.In particular, It will

69/3

(ii)

4.

always be less than 100, so this is infinite loop.To fix, we need to use
counter ++instead of counter - - to fix, or change test from (counter <
100) to (counter >= 0 i.s., as :
.
:
While ( counter < 100 )
{ :
Counter ++ ;
}
In this loop there are not brackets surrounding the code block of the
while loop. Therefore, onlythe line immdiately the while statement
repeats. Since that line does not modify counter, Its vaiues will always be
1. Hence, its another infinite loop. The fact that the last line is indented
and seems to be part of the loop code block is purely cosmetic and of no
consequence to the actual loop. To fix, we need to add grouping bracket
around the indented lines after the while statement i.e., as :
.
:
While (counter < 100 )
{
:
Counter ++ ;
}
In the following program, find the correct possible output(s) from the
options :

70/4

#include <stdlib.h>
#include <iosteam.h>
Void main( )
{
Randomize ( ) ;
Char area [ ] [10] = {NORTH , SOUTH , EAST ,
WEST } ;
{

Int To Go =random (2) + 1 ;


Cout << Area[To Go] << : ;

5.

Outputs :
(i) SOUTH :EAST :SOUTH :
(ii) NOUTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) SOUTH : EAST : EAST :
(i), (ii), (iv).
Find the output of the following program.
#include<iosteam.h>
Void withdef (int HisNum = 30)
{
for (int I = 20 ; I <= HisNum ; I += 5)
cont << I<< , ;
cout << endl ;
}
void control (int &myNum)
{
MyNum += 10 ;
Withdef (MyNum) ;

71/5

}
Void main( )
{
Int YourNum = 20 ;
Control (YourNum) ;
Withdef( )
Cout << Number = << YourNum << endl ;
}
20, 25, 30

6.

20, 25, 30
Number = 30
What is the defference between call by value and call by reference in a
user defind funtion in C++ ? give an example to illustarate the same.
In call by value mathod, the call function creates its own copies of the
originalvalue sent to it. Any changes, that are made, occur on the called
Functions copy of values and are not reflected back to the calling
function.
In call by references mathod, the called function accesses and works
with the original values using their references. Any changes, that occur,
take placeon the original values and are reflected back to the calling
code.
Example of call by value
Void main( )
{
int a = 5 ;
Cout << a = <<a ;
Change (a) ;
Cout << \n a = << a ;
}
void change (int b)
{
b = 10 ;
}

7.

73/6

Example of call by reference


void main( )
{ int a = 5 ;
cout << a= << a ;
change (a) ;
cout << \n a =<<a ;
}
void change (int & b)
{
b = 10 ;
}

Output will be :
output will be :
a=5
a=5
a=5
a = 10
Find the output of the following program :
#include <iosteam.h>
#include <ctype.h>
Void main( )
{
char Mysting[ ] =What@OUTPUT! ;
for (int I = 0 ; Mystring[I]! =\0 ;I++)
{
if (!isalpha(Mystring[I]))
Mystring[I] = *
else if (isupper(Mystring[I]))
Mystring[I] = Mystring[I] + 1 ;
Else
Mystring (I) = Mystring[I + 1] ;
}

75/7

8.

Cout << Mystring ;


}
Xat@* PVUQVU*
Give the output of the following program :
#include <iosteam.h>
struct pixel
{ int C, R ;

77/8

};
Void Display (pixel P)
{ cout << Col << Row << p . R << endl ;
}
Void main( )
{
pixel X = {40, 50}, Y, Z ;

9.

X=Z;
X . C += 10 ;
Y=Z;
Y . R += 20 ;
Z . C -= 15 ;
Display ( X ) ;
Display ( Y ) ;
Display ( Z ) ;

Col 50 Row 50
Col 50 Row 70
Col 25 Row 50
Rewrite the following after removing the syntax error(s) if any . underline
each correction.

88/9

#include <iosteam.h>
Void main( )
{ one = 10, two = 20 ;
Callme (one ; two) ;
Callme (two) ;
}
Void callme (int Arg1, int Arg2 = 20)
{ Arg1 = Arg1 + Arg2
Cout << Arg1 >> Arg2 ;
}
10.

In the following program, find the correct posibleoutput(s) from the


options :
#include <stdlib.h>
#iinclude <iosteam.h>
Void main( )
{
randozine( ) ;
char City[] [ 10 ] = {Del , CHN , KOL, BOM, BNG} ;
int Fly ;
for (int I = 0 ; I < 3 ; I++)
{

89/10

Fly = random (2) + 1 ;


Cout << City[Fly] << : ;

(i)
(iii)
11.

}
}
Output :
DEL :CHN : KOL :
(ii) CHN : KOL : CHN :
KOM : BOM : BNG :
(iv) KON : CHN : KOL :
Find the output of the following program :
#include <iosream.h>
#include <ctype.h>
Void main( )
{
Char line[ ] = Good@LOGIC! ;
For (int I = 0 ; Line (I) != \0 ; I++)
{
If (!isalpha (Line[I]))
Line[I] = $
else if (islower (Line[I]))
Line[I] = Line[I] + 1 ;
else
Line (I) = Line [I + 1] ;
}
Cout << Line ;
}

(b)

(c)

Find the output of the following program :


#include<iostream.h>
{
int First = 25, Sec = 30 ;
for (int I = 1 ; I <= 2 ; I++)
{
cout << Output1= << First++ << & << Sec + 5 << endl ;
cout << Output2=& << First 5 << endl ;
}
}
In the following program,Find the correct possible output(s) from the
option :
#include <iosrteam.h>
#include <stdlib.h>
Void main( )
{
randomize( ) ;
Char Color [ ] [10] = {RED, BLUE, PINK, BLACK} ;
int paint ;
for (int I = 1 <= 2 ; I++)
{
Paint = random (2) + 1 ;
Cout << Color [paint] << : ;
}
}
Output :
BLUE : PINK : BLUE :
(ii) RED : BLUE : PINK :

89/11

(iii)
12.

(ii)

(iii)

BLUE : PINK : BLACK :


(iv) BLUE: PINK : PINK :
Give the output of following :
(i) Char *NAME = IntRAneT ;
for (int = 0 ; < strlen(NAME) ; ++)
if(isluwer(NAME)[]) ;
else
if (isupper(NAME[])
if ( % 2 == 0)
else
NAME[ ] = tolower(NAME[ ]) ;
NAME[ ] = NAME[ - 1] ;
Puts(NAME) ;
#include <iosrteam.h>
Void Excute (int & , int Y = 200)
{ int TEPM = + Y ;
+ = TEMP ;
If (Y != 200)
Cout << TEPM << <<Y << endl ;
}
Void main( )
{ int A = 50, B = 2w0 ;
Excute (B) ;
Cout << A << B << endl ;
execute (A, B) ;
cout << A << B <, endl ;
}
Char *NAME = CoMPutER ;
for (int =0 ; < strlen (NAME) ; ++)
if(islower(NAME[ ]))
NAME[ ] = toupper(NAME[ ]) ;
else
if (isupper(NAME[ ]) )
if ( % 2 = = 0)
NAME[ ] = tolower(NAME[ ]) ;
else
NAME[ ] = NAME[ - 1] ;
Puts(NAME) ;

(iv)

#include <iosrteam.h>
Void Execute (int & B, int C = 100)
{
int TEPM = B + C ;
B + = TEPM ;
If (C = = 100)
Cout << TEPM << B << C << endl ;
}
void main( )
{ int M = 90, N = n 10 ;
Execute (M) ;
cout << M << N << endl ;
Execute (M, N) ;
Cout << M << N <, endl ;
}

91/12

13.

Find the output of the following program :


#include <iosrteam.h>
Struct package
{
Int
Length, Breadth< Heigth ;

92/13

};
Void occupies)package M)
{
cout << M.Length << << M. Breadth <, ;
Cout << M. Heigth << endl ;

14.

}
Void main( )
{
package P1 = {100, 150, 50}, P2, P3 ;
++P1.Length ;
Occupies(P1) ;
P3 = P1 ;
++P3.Breadth++ ;
P3.Breadth++ ;
Occupies(P3) ;
P2 = P3 ;
P2. Breadth += 50 ;
P2.Heigth -- ;
Occupies(P2) ;
}
Find the output of the following program :
#include <iosrteam.h>
#include <string.h>
#include <ctype.h>
Void Convert(char Str[ ], int Len)
{
for (int Cout = 0 ; Cout < Len ; Count ++)
{
If (isupper(Str[Cout] = tolower(Str[cout]) ;
else if (islower(sStr[cout]))
Str[Cout] = toupper(Str[Cout]) ;
else if (isdigit(Str[Cout]))
Str[Cout] = Str[Cout] + 1 ;
else Str[Cout] =* ;
}

}
Void main( )
{ char Text[ ] = ``CBSE Exam 2005 ;
int Size = strlen(Text) ;
Convert (Text, Size) ;
for (int C = 0, R = Size 1 ; C <= Size/2 ; C++, R --)
{
Char Tepm = Text[c] ;
Text[c] = Text[R] ;
Text[R] = Tepm ;

92/14

Cout <<Text << endl ;

}
15.

16

Fill in the blank spaces with code to provide required functionality for the
following incomplete program code that reads the name of the person in
the following format :
Lastname
/ Firstname
#include
#include
void Displayname(-----name1, ------name2);
int Find( char ch, name) ;
char * substr(char * name, int spos, int epos);
int main( )
{
------- name [---];
------- firstname[--];
------- lastname[--];
int slashposn;
int lastnameLength;
cout << Enter name (first and last separatted by a /): ;
-------------------------------- ;
slashposn = Find(/, name);
-------------- = substr(name, 0, slashposn);
lastNameLength =____________- slashposn 1;
lastName = substr(name,slashposn+1, lastNameLength);
cout << Reversed, the name is ;
DisplayName(first, lastName);
Return 0;
}
Void DisplayName(-----name1, -----name2) // display name using
format name2,name1,
{
// write code for this function.
}
int Find(char ch, name) ;
{
// write code for this function.
}
Char * substr(char * name, int spos, int epos);
{
// write code for this function.
}
A function pritchar is defined as
void printchar(char ch = *, int len = 40)
{ for(int = 0 ; < len ; + +) cout << ch ;
cout << endl ;
}
How will you invoke the function princhar for following output :
(i) to print* 40 times
(ii) to print* 20 times
(iii) to print=40 times
(iv) to print =20 times
Printchar( ) ;
Printchar(*, 20) ;

94/15

131

printchar(=) ;
printchar(=, 30) ;
17.

Which of the following overloaded functions are called in each of the calls
in main() ? If any of the calls are the ambiguous (that is, they cant be
resolved), list call the candidate functions
void func (int a) { }
void func (int a, float b) { }
void func (int a, double y) { }
int main( )
{
func (1) ;
func (1) ;
func (2, 3) ;
return 0 ;

// # 1
// # 2
// # 3

// a
// b
// c

}
Call a is exact match for func (int), # 1
Call a match though promotion for func (int)
(char can be promoted to int)
Call c is ambiguous between # 2 and # 3
An int can be converted to either of the flot and double
18.

Write a C++ program that use an area( ) function for the caculation of
area of a triangle or a rectangle or a requar. Number of sides (3 for
triangle,2 for retengle and 1 for square) suggest about the shape for
which area is to be calculated.
#include.iostream.h>
#include<conio.h>
#include<math.h>
float area(float a, float b, float c)
{
float s, ar;
s = (a + b + c) / 2;
ar = sqrt(s * (s a) * (s b) * (s c));
return ar;
}
float area(float a, float b)
{
return a*b;
}
float area(float a)
{

return a*a;

}
int main ( )
{
Clrscr ( );
int choice, s1, s2, s3, ar;
do

132

19
(i)

(ii)

cout << /nArea Main Menu \n;


cout << 1. Triangle \n;
cout << 2. Square \n;
cout << 3. Rectangle \n;
cout << 4. Exit\n;
cout << Enter your choice (1-4) :;
cin >> choice;
cout << \n;
switch(choice)
{
case 1 : cout << Enter 3 sides \n;
cin >> s1 >. S2 >>s3;
ar = area(s1, s2, s3);
cout << the area is << ar <, \n;
break;
case 2 : cout <, Enter a side \n;
cin >> s1;
ar = area(s1);
cout << the area is << ar << \n;
break;
case 3 : cout <, Enter Length & breadth \n;
cin >> s1 >. S2;
ar = area(s1, s2);
cout << The area is << ar << \n;
break;
case 4 : break;
default : cout << Wrong Choice !!\n;
};
//end of switch
} while(choice > 0 && choice < 4);
return 0;
}
Here are some desired effects. Indicate wherther each can be
accomplished with difault arguments, with function verloding, with both,
with neiter. Provide aprropriate prototypes.
repeat ( 10, -) displays the indicate character (-in this case) given
number of time(10 here). While repeat( ) displays* character 12 times.
Also repeat(#) displays the given character (# here) 12 times and
repeat (7) dislays * given no of times (7 here).
average (4, 7) return of average two int agruments, while average (4.0,
7.0) return the double average of two double voules.

(iii)

Mass (density, volume) return the mass of an object having a density


and a volume of volume, while mass (density) return the mass having a
density of density and a volume of 1.0 cubic meters. All quantities are
type double.

(iv)

Average (4,7) return an int aberage of the two int arguments when
called is one fine, and it returns a double average of the two int
arguments when called in a second file in the same program.

(v)

handle (a-character)return the reversed case of the passed character or


print it twise depending upon whether you assign the return volue it or

20.

21.
1.
2.

not.
Write difinitions for two version of an overloded function. This funsions
1st version sum( ) takes an arguments,int array, and return the sum of all
the element of the assed array. The 2 nd version of sum( )take to
arguments, an int array and a character
(E or O). if the
passedcharacter is E, it return the sum of even elements of the passed
array and if the passed charater is O, it return the sum of odd elements.
In case of any other character, it retutn 0 (zero).
What do you understand about a member function. ? how does a
member function differ from an ordinary function ?
Member functions have full access privilege two woth the publicand
private member of the class while, in genral, nonmember functions have
access only to the publik member of the class.
Member functions are defined within the class scope that is they are not
visible outside the scope of class. Nonmember function are also visible
outside the scope of class.

137

22.

What are static class member ?


What do you mean by static data member of a class ? Exampail the
charcteristics of a static data member.
A class can have static data member as well as static member functions.
The static data member are the class varible that are common for all the
object of the class. Only one of yhe copy of static data member is
maintainted which is shared by all the object of the class. They are
visible only within the class but their life time is the entire program.
They can be accesses by all the member functions.
A member function that accesses only static data member of a class is
static member function. It cannot access other data member but static
members.
The static data member useful when some data values are to be shared
across object of the same class.

191

23.

Identify and correct the errors in the following code fragment :


Class x {
static int a;
int b ;
char c ;
public :
static float x;
floaty;
void getval (int I, int j, char k)
{
a=i;
b=j;
c=y;
x=y=0;
}
void prn (void)
{
cout << a << x ;
}
};
In the above code fragment, the definition of static member is missing.
To correct it, the code shold be as follows :

193

Class X

24.

:
:

//same as above

};
int x :: a;
float x :: x;
Write the output of the following program :
#include <iostream.h>
class Counter
{
private :
unsigned int count ;
public :
counter( ) {count = 0 ; }
void inc_count( ) {count ++ ;}
int get_count( ) {return count ;}
};
Void main( )
{

198

Counter C1, C2 ;
Cout << \t C1 = << C1.get_count( ) ;
Cout << \t C2 = << C2.get_Count( ) ;
C1.inc_count( ) ;
C2.inc_Count( ) ;
C2.inc_count( ) ;
Cout << \tC1= << C1.get_Count( ) ;
Cout << \tC2= << C2.get_Count( ) ;
C1 = 0

25.

C2 = 0

C1 = 1

C2 = 2

Define a class Book with the following specification :


Private member of the class Book are
Book_No
integer type
Book_title
20 characters
Price
float (price per copy)
TOTAL_COST( )
A function to caclulate the total cost for N
number of copeis,
Where N is passed to the function as
argument
public member of the class Book are
INPUT( )
function to read Book_NO, BOOk_TITLE,
PRICE
function to ask the user to input the
number of copeis to be purchased. It invo
-kes TOTAL COST( ) and prits the total
cost to be paid by the user.
Note : you are also required to give detailed function
definitions.
#include<iostream.h>
#include<stdio.h>
class BOOK { int BOOK_NO ;
char BOOK_TITLE[20] ;
float price ;

PURCHASE( )

193

float TOTAL_COST(int N)
float TOTAL ;
TOTAL = N * PRICE ;
return TOTAL ;

}
public :
void INPUT( )
{
cout << \nEnter BOOK NO ;
Cin >> BOOK_NO ;
cout << \nEnter BOOK Titel : ;
gets(BOOK_TITLE) ;
cout << \nEnter price : ;
cin >> PRICE ;
}
Void PURCHAS( )
{ int n ;
float TOT ;
cout << \nEnter the number of copets to be
purchased : ;
cin >> n ;
TOT = TOTAL_COST(n) ;
Cout<< \nTOtal Amount is : << TOT ;
}

26

(i)

};
Difine a class to represent bowlers in a cricket team> Incude the
following member :
Data Members
First name, Last name,overs bowled, Number of Maiden overs, Runs
given, Wickets taken.
Member Functions
To assign the initial values
(ii) To update the information.

(iii)

To display the bowlers information


Make appropriate assumptions about access specifiers>

27.

Declare a class Directory with the following specification :


Private member of the class
Docunames - an array of strigs of size[10][25]
(to represent all the name of documents inside
di-rectory
Freespace long (to represent total number of bytes available
in directory)
Occupied long (to represent total number of bytes used in
Directory)
Public member of the class
Newdocuentry( ) - A function to accept values of Docunames,Fre
-espace and Occupied from user
Retfreespace( ) - A function that returns the values of total kilo
-byte = 1024 bytes)
Showfiles( )

A function displays the name of all the


documents in Directory.

203

206

28.

Given the following codefragment :


#include <iostream.h>
Class x
{
int x< y ;
Void count (void);
Public :
int a< b ;
void getval (int, int) ;
void prval (void) ;
};
:
:
//Xs member functions definitions
:
X 0b1 ;
int main ( )
{
Class y

201

int I, j ;
void abc (void) ;
static int z ;
public :
float k ;
void get(void) ;
void prin(void) ;
};

Y 0b2 ;
X 0b3 ;
:
}
//end fun1( )
void func1( ) ;
{
X 0b4;
:
}

//endfun1( )

Void fun2( )
{

}:

//end func2( )

Inentify and correct the error in above.


In correct code, which all member (data & functions) of classes X and Y
can be accessed by main( ), fun1( ) fun2( ), ? give reasons.

29.

Is there any defference between List x; and List x().,, supposing that
there exists a class namely List ?
There is a big defference !
List x ; statement declares an object of class List type whereas the
statement List x ( ) ;declares a function by the name x and having ruturn

233

type as List.
For excample, following function f() declareas a local List object called x :
void f( )
{ List x ;
// Local object named x (of class List)

30.

31.

1.
2.
3.
4.
5.
32.

}
But following function g() declaers a function called x() that return an
object of List type:
void g( )
{
List x( ) ;
// function named x (that return a List)

}
Which constructor gets call for the statements #1 and #2 in the code
given below ?
class Test { int a, b ;
public :
Test( ) ;
Test(int i, int j = 5) ;

};
int main( )
//statement #1
{ Test a[10] ;
// statement #2
Test p (10, 15) ;

}
Default constructor Test::Test() for statement #1
And parameterised constructor Test::Test(int i, int j) for statement #2.
What will be the order of constructor invocation for the following code
snippet ?
class Date { :
};
Class Time { :
};
Class Train {
int train( );
Date dep_date;
Time dep_time;
:
};
int main( )
{ Date D1;
Time T1;
Train TR1;
:
}
The order of constructor invocation will be as following :
Date :: Date( ) contructor for D1 object.
Time :: Time( ) contructor for T1 object.
Date :: Date ( ) for dep_date (of TR1) object.
Time :: Time( ) for dep_time (of TR1) object.
Train :: Train( ) for TR1 object.
What will be the output of following code
#include <iosream.h>

234

235

238.

class A

Class B

{ public :
A( )
{cout << constructor A \n ; }
~A( )
{cout << Destrutor A \n ; }
};
{ public :
B( )
{ cout << constructor B \t ; }
~B( )

{ cout << destructor B\n ; }


};
class C

A ob1, ob2 ;
B ob3 ;
Public :
C( )
{ cout <<\n Constructor C\t ; }
~C( )
{ cout << Destructor C\n ; }

};
Void main( )
{ C oc ;
B ob ;
A ob ;
}

33.

Constructor A
Constructor A
Constructor B
Constructor C
Constructor B
Constructor A
Destructor A
Destructor B
Destructor C
Destructor B
Destructor A
Destructor A
Fine the syntax error(s), if any (given reason for error) :
class ABC
{ int x = 10 ;
float y ;
ABC( ) { y = 5 ; }
~( ) { }
}
Void main( )
{
ABC a1, a2 ;
}

240.

1.

34.

35.

36.

Erroneous statement
int x = 10 ;

2.

~( ) { }

3.

Error and corrections


Date member cannot be initialized
within a class. Hence,
int x ;
Name of destructor missing. Hence,
~ABC ( ) { }
class definition should end with a semicolon. Hence,
};

Consider the following code :


class ci
{ int l ;
public :
ci (int j) {l = j ; }
ci (ci & rv) {l = rv. L ; }
void initialize( ) {l = 0 ; }
};
main( )
{ ci original (1) ;
ci X1(original) ;
ci X2 = original ;
}
Referring to the sample code above, What intializes the object X1 ?
(i) Intialize( ) function
(ii) The default constructor
(iii) The copy constructor
(iv) The default copy contructor.
Justify your anser.
Which of the following is used to identify the copy constructor class type
X?
(i) (X&) (ii)X(&X)
(iii) X(X&) (iv) X(X). justify your answer.

245

Identify the error(s) in the following and correct it, explaining every
chang being introduced in the program :
#include <iostream.h>
Class sample { int i;
float j;
void sample (void)
{
i = 0;
j = 0.0;
}
init( )
{
cin >> i >> j ;

247

245

}
Display( )
{
cout << i = << i << \n ;
Cout << j = << j << \ n ;
}
Void sample (void) { }
37.

};
Sample s1, s2;
What will be the output of the following ?
#include <iostream.h>
class MAIN {
public :

249

MAIN( )
{
calculate( ) ;
Cout << \t << constructor. \n ; }
void calculate( )
{
show( ) ;
cout << \t << calculating\n ;
}
Void show( )
{
cout << I am displaying
}
};

38.

void main( )
{
MAIN one ;
}
Consider the following and answer the question given below :
class MNC
{
char cname[25] ;
protected :
char Hoffice[25] ;
public :
MNC( ) ;
char Country[25] ;
void EnterDate( ) ;
voidDisplayDate( ) ;
};
class Branch : public MNC
{
long NOE ;
char Ctry[25] ;
protected :
void Assoiciation( ) ;
public :
Branch( ) ;
void Add( ) ;
void show( ) ;
};
Class Outlet : public Branch
Char state[25] ;
Public :
Outlet( ) ;
void Enter( ) ;
void Outlet( ) ;
};
(i) which class constructor will be called first at the time of declaration of
an object of class Outlet ?
(ii) how many bytes does an object belonging to class Outlet require ?
(iii) name the member function(s), which are accessed from the
object(s) of class Outlet.
(iv) name the data member(s), which are accessible from the object(s)
of class Branch.

(i) first of all constructor of class MNC will be called, then of Branch and
then at last of Outlet.
(ii) 129
(iii) MNC :: EnterData( ), MNC:: DisplayData( ), Branch :: Add( ), Branch
:: show( ), Outlet :: Enter( ), Outlet ::Output( ).
(iv) MNC :: Country.
39.

Given the following set of definition. What data member and function are
directly accessible by the function mentioned here ?
void inform (void) ;
class x
{
int a ;
float b ;
void inti (void) ;
public :
char ch; void gett(void) ;
protected :
double amt ;
void getamt (void) ;
friend void A (void) ;
};
class Y : public X
{
int X ;
public :
int j ;
void readit (void) ;
protected :
void inform (void) ;
friend void B (void) ;
};
Void display (void) ;
The function :: inform() can access public data member of class X and Y
and the function display() provided, the defintion of :: inform() ocurs
after the declaration of X, Y and display().
X :: init(), X :: gett(),X :: getamt() and A() can access all the member of
X and :: inform().
Y :: redit(), Y :: inform () and B() can access all the member of Y, public
and protected member of X (the inherted member) and :: inform () (only
with the scope resolution operator :.
:: display() can access public member of X and Y, :: inform(); and A()
and () if only their declartions (A()s and B()s occur before display().

40.

Suppose we have following C++ program :


#include <iostream.h>
class A
{
public:
A( ) { cout << A; }
~A( ) { cout << ~A; }
};
Class B

41.

public:
B( ) { cout << B; }

};
Class C
{
public:
C( ) { cout << C; }
~C( ) { cout << ~C; }
private:
Ba;
A b;
};
class D
{
public:
D( ) { cout << D ;
~D( ) { cout << ~D; }
};
class E : public C
{
public:
E( ) { cout << E; }
~E( ) { cout << ~E; }
Private:
D d; B b;
};
void main( )
{
Ee;
Cout << endl ;
}
Assuming that the program compiles and runs correctly, what does it
print out ?
BACDBE
~E~B~D~C~A~B
Answer the question (i) to (iv) based on the following code :
class Teacher
{
char Tno[5], Tname[20], Dept[10] ;
int Workload ;
protected :
float Salary ;
void Assignsal (float) ;
public :
Teacher( ) ;
void Tentry( ) ;
void Tdisplay( ) ;
};
class Student
{
char Admno[20], Steam[10] ;
protected :
Student( ) ;
void Sentry( ) ;
void Sdisplay( ) ;
};
class School : public Student, public Teacher
{
Char Scode [10], SchName[20] ;

(i)

42.

Public :
School( ) ;
void SchEntry( ) ;
void SchDisplay( ) ; } ;
which type of Inheritance is depicted by the above example ?

(ii) Identify the member function(s) that cannot be called directly from
the object of class School from the following :
TEntry( )
Sdisplay( )
SchDisplay( )
(iii) write name of all the member(s) accessible from member function of
class School.
(iv) if class was derived from privately from class Teacher and privately
from class Student,then, name the member function(s) that could be
accessed though object of class school.
(i) Multiple Inheritance
(ii) AssignSal( )
(iii) Data ?Members :
Salary, Attendance, TotMarks, Scode, Schname.
Member functions: AssignSal( ), Tentry( ), Tdisplay( ),Sentry( ),
Sdisplay(), SchEntry( ), SchDisplay( )
Define multilevel and Multiple inheritance in context of object orianted
programming. Give suitable example to illustrate the same.
(b) Answer the question (i) to (iii) based on the following code :
class stationery
{
char Type ;
char Manufacturer[10] ;
public :
stationery( ) ;
void Read_sta_details( ) ;
void Disp_Sta_details( ) ;
};
class office : public statinery
{
int no_of_types ;
float cost_of_sta ;
public :
void Read_off_details( ) ;
void Disp_off_details( ) ;
};
class printer : private office
{
int no_of_user ;
char delivery_date[10] ;
public :
void Read_pri_details( ) :
void Disp_pri_details( ) ;
};
void main( )
{ printer Myprinter ;
}

(i)
(ii)
(iii)
(a)

(b)

43.
44.

Mention the member names which are accessible by My printer declared


in main( ) function.
What is the size of My printer in bytes ?
Mention the name of functions accessiblefrom the member function
Read_pri_details( ) of class printer.
Multiple Inheritance. It is the inheritance heirarchy wherein one derived
class inherits from multiple base class(es).
Multilevel Inheritance. It is the inheritance heirarchy wherein a subclass
acts as a base class for other classes.
(i) Date Members
Member function
(ii) 29 Bytes
(iii) Member function

None
Read_pri_details ( ) , Disp_pri_detais ( )

Read_sta_details ( ), Disp_pri_detais ( )
Read_off_details ( ) , Disp_off_details ( ),
Read_pri_details ( ), Disp_pri_details ( )
How does the public derivation of a class differ from private and
protected derivation ?
In what order are class constructors and class destructors called when a
derived class object is created and destroyed ?

S-ar putea să vă placă și