1 Oopc++ - Questions
1 Oopc++ - Questions
1 Mark Questions
1. Name the header files to which the following belong:
(i) puts() (ii) isalnum()
2. Write the name of the header files to which the following belong:
(i) strcat() (ii) atoi()
3. Name the header files in which the following belong:
(i) pow() (ii) random()
4. Name the header files in which the following belong:
(i) gets() (ii) open()
5. Name the header file(s) that shall be needed for successful compilation of the following C++ code:
void main() {
char string[20];
gets(String);
strcat(String, “CBSE”);
puts(String);
}
6. Name the header files that shall be needed for the following code:
void main() {
char word[] = “Exam”;
cout<<setw(20)<<word;
}
7. What is cascading?
8. What is the purpose of default clause in a switch statement?
9. What are the applications of void data type in C++?
10. What is the effect of absence of break in switch-case statement?
11. Give the output of the following program segment:
Int I =200, = 18;
cout<< i/j << endl;
12. When will you make a function inline?
13. What is the significance of any empty parentheses in a function declared?
14. How are abstraction and encapsulation inter-related?
15. Write the declaration of inline function named bar() that takes one argument of type float and
return type int.
16. Observe the following C++ and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler.
void main()
{
float Area,Side;
cin>>Area;
Side = sqrt (Area):
cout<< “One Side of the Square=”<<Side<<endl ;
}
17. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler.
void main ()
{
Int Number;
cin>>Number;
if (abs (Number) = = Number);
cout<< “Positive”<<endl;
}
18. Name the header file(s), which are essentially required to run the following program segment.
void main ()
{
char A= ‘K’,B;
if (islower (A) )
B=toupper (A);
else
B= ‘*’;
cout<<A>> “turned to” <<B<<endl;
}
19. Write the names of the headers files to which the following belong:
(i) puts ( ) (ii) sin ( )
20. Write the name of the header file to which the following belong:
(i) puts ( ) (ii) randomize ( )
21. Observe the following C++ code and write the name(s) of the header file (s), which will be
essentially required to run in a C++ compiler.
void main ( )
{
char Text[20],c;
cin>>Text;
C=tolower (Text[0]);
cout<<C<< “is the first char of”<<Text<<endl;
}
22. Observe the following C++ code and write the name(s) of the header file (s), which will be
essentially required to run in a C++ compiler.
void main ( )
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<< “starts with”<<CH<<endl; }
23. Which C++ header files(s) are essentially required to be included to run/execute the following C++
source code?
void main ( )
{char STRING[ ]=Something”;
cout<<”Balance Characters :”<<160-
strlen (STRING)<<CH<<endl;
}
(Note Do not include any header file, which is /are not required).
24. Which C++ header file(s) are essentially required to be include to run/execute the following C++
source code?
void main ( )
{
char Text[ ]=SomeThing”;
cout<< “Remaining SMS Chars:”<< “160-
strlen (STRING) <<endl;
}
(Note Do not include any header file, which is /are not required).
25. Write the names of the header files, which is/are essentially required to run, execute the following
C++ code.
void main ( )
{
char C, string[ ]= “Excellence Overload”;
for (int I=0; string[ I ] != ‘\0’;I++)
if(string[ I ]== ‘ ’ )
cout<<endl;
else
{
C=toupper (Text[ I ]) ;
cout<<C;
}
}
26. Write the names of the header files, which is/are essentially required to run/execute the following
C++ code.
void main ( )
{
char CH, Text[ ]= “+ve Altitude”;
for (int I =0; Text [ I ] != ‘\0’;I++)
if(Text[ I ]== 1 )
cout<<endl;
else
{
CH =toupper (Text[ I ]) ;
cout<<CH;
}
}
27. Which C++ header file(s) will be essentially required to be included to run/execute the following C++
code?
void main ( )
{
Int Rno=24;
char Name[]= “Aman Singhania”;
cout<<setw(10)<<Rno<<setw(20)
<<Name<<endl;
}
28. Name the header files that shall be needed for the following code
void main ( )
{
char Text[ ]= “computers”;
cout<<setw(15)<<Text;
}
29. Name the header files that are essential to run the following code segment successfully
void main()
{ char ch[10];
cout<<"enter ur name \n"; cin.getline(ch,10);
int l=strlen(ch);
cout.write(ch,l);
}
30. Find the correct identifiers out of the following, which can be used for naming
variable, constants or functions in a C++ program :
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
31. Find the correct identifiers out of the following, which can be used for naming
Variable, Constants or Functions in a C++ program :
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
32. Name the header files that are essential to run the following code segment successfully
void main()
{
int r;
float A,B;
cout<<"enter the radius of circle\n";
cin>>r;
A=3.14*pow(r,2);
B=32767;
cout<<"area =\t"<<A<<endl;
cout<<B;
}
33. Which of the following are valid identifiers?
Data_rec Data rec, 1 data, data 1, my.file, asm, switch, goto
34. What is the result of following expression? Y= (t=4, t+3);
35. What is the significance of preprocessor directive?
36. Why is char often treated as integer data type in C++ ?
37. Why main function is special in C++ ?
38. Write the names of the headers files to which the following belong:
randomize(), getch( )
39. Write the names of the headers files to which the following belong:
fabs(), atoi( )
40. Observe the following program very carefully and write the names of those
header file(s), which are essentially needed to compile and execute the following
program successfully:
typedef char TEXT[80];
void main()
{
TEXT Str[] = “Peace is supreme”;
int Index=0;
while (Str[Index]!=’\0’)
if (isupper(Str[Index]))
Str[Index++]=’#’;
else
Str[Index++]=’*’;
puts(str);
}
41. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and
Statement 2 using seekg( ), seekp( ), tellp( ) and tellg( ) functions for performing the required task.
#include<fstream.h>
class PRODUCT
{ int Pno; char Pname[20); int Qty;
public :
void ModifyQty( ) ; // The function is to modify quantity of a
PRODUCT
} ;
void PRODUCT: :ModifyQty ( )
{ fstream File ;
File.open ("PRODUCT.DAT", ios::binary |ios :: in| ios::out) ;
int MPno;
cout<<"Product No to modify quantity : ";
cin>>MPNo;
while (File.read ((char*) this, sizeof(PRODUCT))
{ if (MPno == Pno)
{ cout<<"Present Quantity:"<<Qty<<end1 ;
cout<<"Changed Quantity:";cin>>Qty ;
int Position = _______________; //Statement 1
_____________________________; // Statement 2
File.write ((char*) this, sizeof (PRODUCT)) ; //Re-writing the
record
} }
File.close ( );
}
42. Find the output of the following C++ code considering that the binary file
MEMBER.DAT exists on the hard disk with records of 100 members:
class MEMBER
{
int Mno; char Name[20];
public:
void In();void Out();
};
void main()
{ fstream MF;
MF.open("MEMBER.DAT”,ios::binary|ios::in);
MEMBER M;
MF.read((char*)&M,sizeof(M));
MF.read((char*)&M,sizeof(M));
MF.read((char*)&M,sizeof(M));
int POSITION=MF.tellg()/sizeof(M);
cout<<"PRESENT RECORD:"<<POSITION<<endl;
MF.close(); }
43. Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using tellg() and seekp() functions for performing the required
task.
#include <fstream.h>
class Client
{
long Cno;
charName[20],Email[30] ;
public:
//Function to allow user to enter
//the Cno, Name,Email
void Enter() ;
//Function to allow user to enter
//(modify) Email
void Modify() ;
long ReturnCno()
{
return Cno;
}
};
void ChangeEmail()
{
Client C;
fstream F;
F.open (“INFO.DAT”,ios::binary|ios::in|ios::out);
long Cnoc; //Client’s no. whose
//Email needs to be changed
cin>>Cnoc;
while (F.read((char*)&C,
sizeof(C)))
{
if (Cnoc= =C.ReturnCno())
{
C.Modify(); //Statement 1
int Pos = __________
//To find the current position
//of file pointer
_______________ // Statement 2
//To move the file pointer towrite the modified recordback onto the file for
thedesired Cno
F.write((char*)&C, sizeof(C));
}
}
F.close();
}
44. Observe the program segment given below carefully and fill in the blanks marked as
Line 1 and Line 2 using fstream functions for performing the required task.
#include <fstream.h>
class Stock
{
long Ino ; //Item Number
char Item [20] ; //Item Name
int Qty ; //Quantity
public:
void Get(int);
//Function to enter the content
void show( );
//Function to display the content
void Purchase (int Tqty)
{
Qty + = Tqty ;
} //Function to increment in Qty
long KnowIno ( )
{
return Ino;
}
};
void Purchaseitem(long PINo, int PQty)
//PINo -> Ino of the item purchased
//PQty -> Number of item purchased
{f
stream File;
File.open(“ITEMS.DAT”, ios ::binarylios ::inlios :: out);
int Pos = –1 ;
Stock S ;
while (Pos = = –1 && File.read((char*) &S,sizeof (S)))
if (S. KnowIno( ) ==PINo)
{
S. Purchase (PQty);
//To update the number of Items
Pos = File.tellg ( ) -sizeof (S) ;
__________________;
//Line 1: To place the file
//pointer to the required position
___________________;
//Line 2: To write the object s on to
//the binary file
}i
f (Pos = = –1)
cout<<“No updation done as
required Ino not found..” ;
File.close ( ) ;
}
45. Observe the program segment given below carefully, and answer the question that
follows
class candidate
{ long Cid ; // Candidate’s Id
char CName[20]; // Candidate’s Name
float Marks ; // Candidate’s Marks
public ;
void Enter( ) ;
void Display( ) ;
void MarksChange( ) ;
//Function to change marks
long R_Cid( )
{ return Cid;
}
};
void MarksUpdate (long Id)
{
fstream File ;
File.open (“CANDIDATE.DAT”, ios ::binary|ios::in|ios :: out) ;
Candidate C ;
int Record = 0, Found = 0 ;
while (!Found&&File.read((char*)&C,sizeof(C)))
{
if (Id = =C.R_Cid( ))
{ cout << “Enter new Marks” ;
C.MarksChange( ) ;
____________ //Statement1
___________ //Statement 2
Found = 1 ;
}
Record++ ;
}
if (Found = = 1)
cout << “ Record Updated” ;
File.close( ) ;
}
Write the Statement to position the File Pointer at the beginning of the Record for which the
Candidate’s Id matches with the argument passed, and Statement 2 to write the updated
Record at that position.
46.
Fill in the blanks marked as Statement 1 and Statement 2 in the program segment given below with
appropriate functions for the required task.
class Club
{
long int Mno ; //Member number
char Mname [20] ; //Member name
char Email [30] ; //Email of member
public:
void Register ( ) ; //Function to register member
void Disp ( ) ; //Function to display details
void ChangeEmail ( ) //Function to change Email
{
cout<< “Enter Changed Email:”;
}
long int GetMno ( )
{
Return Mno ;
}
};
void ModifyData ( )
{
fstram File ;
File.open (“CLUB DAT”.ios: :binary │ios : : out);
int Modify = 0. Position;
long int ModiMno;
cout<< “Mno-whose email required to modified:”;
cin>>ModiMno;
Club CL;
while(!Modify&&File.read((char*)&CL.sizeof(CL)))
{
If(CL.GetMno( ) == ModiMno)
{
CL.ChangeEmail ( );
Position = File.tellg( )-sizeof(CL);
//Statement 1: To place file pointer to the required position
;
//Statement 2: To write the object CL onto the binary file
;
Modify++;
}
}
If (Modify)
cout<< “Email Changed. . .”<<end];
else
cout<< “Member not found. . .”<<end];
File.close( );
}
47. Observe the program segment given below carefully and answer the questions that follow:
class Stock
{
int Ino,Qty; char Item[20];
public:
void Enter() {cin>>In0;gets(Item); cin>>Qty;}
void Issue(int Q) { Qty+=Q}
void Purchase(int Q) { Qty-=Q}
int GetIno(return Ino;}
};
void Purchaseitem(int Pino, int PQty)
{
fstream file;
File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while (Success==0 && File.read((char*)&S, sizeof(S)))
{
if (Pino==S.GetIno())
{
S.Purchase(PQty);
_____________________________//Statement 1
_____________________________//statement 2
Success++;
}
}
if (Success==1)
cout<<“Purchase Updated”<<endl;
else
cout<<”Wrong Item No”<<endl;
File.close( );
}
(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is
done for the required item.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.
48.
Observe the program segment given below carefully and fill the blanks marked as Line
1 and Line 2 using fstream functions for performing the required task.
#include <fstream.h>
class Library
{
long Ano; //Ano - Accession Number of the Book
char Title[20]; //Title - Title of the Book
int Qty; //Qty - Number of Books in Library
public:
void Enter (int); //Function to enter the content
void Display(); //Function to display the content
void Buy(int Tqty)
{
Qty+=Tqty;
} //Function to increment in Qty
long GetAno( )
{
return Ano;
}
};
void BuyBook(long BANo,int BQty) //BANo ->Ano of the book purchased
//BQty ->Number of books purchased
{ fstream File;
File.open(“STOCK.DAT” ,ios::binary|ios::in|ios::out);
int position=-l;
Library L;
while(Position==-l &&File.read((char*)&L,sizeof(L)))
if (L.GetAno()==BANo)
{
L.Buy(BQty);
//To update the number of Books
Position = File.tellg()-sizeof(L) ;
____________________;
//Line 1: To place the file pointer to the required position
____________________;
//Line 2:To write the object L on to the binary file
} if (Position==-l)
cout<< “No updation do:r{e as
required Ano not found..”;
File.close( );
}
49. Observe the program segment given below carefully,and answer the question that
follows:
class Labrecord
{ int Expno;
char Experiment[20] ;
char Checked ;
int Marks ;
public :
void EnterExp( ) ;
//function to enter Experiment details
viod ShowExp( ) ;
//function to display Experiment details
char RChecked( )
//function to return Expno
{
return Checked;
}
void Assignmarks (int M)
//function to assign Marks
{
Marks = M;
}
};
void ModifyMarks( )
{
fstream File ;
File.open (“Marks.Dat”, ios :: binary lios :: in l ios :: out) ;
Labrecord L ;
int Rec=0 ;
while (File.read ( (char*) &L,sizeof (L)))
{
if (L.RChecked( )= =’N’)
L.Assignmarks(0)
else
L.Assignmarks (10)
_______________; //Statement 1
________________;//Statement 2
Rec++ ;
}
File.close( ) ;
}
If the function ModifyMarks ( ) is supposed to modify marks for the records in the file
MARKS.DAT based on their status of the member Checked (containg value either ‘Y’ or
‘N’).Write C++ statements for the statement 1 and statement 2,where, statement 1 is
required to position the file write pointer to an appropriate place in the file and statement 2 is
to perform the write operation with the modified record.
50. Observe the program segment given below carefully , and answer the question that
follows :
class Member
{
int Member_no ;
char Member_name[20] ;
public :
void enterdetails ( ) ; //function to enter Member details
void showdetails ( ) ; //function to display Member details
int RMember_no( )
{
return Member_no;
} //function to return Member_no
};
void Update (Member NEW)
{
fstream File ;
File.open(“MEMBER.DAT” , ios ::
binary |ios :: in | ios :: out) ;
Member OM ;
int Recordsread = 0, Found = 0 ;
while (!Found && File.read((char*)& OM, sizeof(OM)))
{
Recordsread++ ;
if (NEW.RMember_no( ) ==OM.RMember_no( ))
{
___________ //Missing Statement
File.write((char*) & NEW ,
sizeof(NEW) ;
Found = 1 ;
}
else
File.write((char*) & OM,
sizeof(OM)) ;
}
if (!Found)
cout<<”Record for modification does
not exist” ;
File.close( ) ;
}
If the function Update( ) is supposed to modify a record in file MEMBER.DAT with the values of
Member NEW passed to its argument, write the appropriate statement for Missing
statement using seekp( ) or seekg( ), whichever needed, in the above code that would write
the modified record at its proper place.
2 Marks Questions
37. What is copy constructor? Give an example in C++ to illustrate copy constructor.
41. How are binary files different from text files in C++?
42. What is a stream? Name the streams generally used for file I/O.
47. Define Multilevel and Multiple inheritance in context of Object Oriented Programming.
Give suitable example to illustrate the same.
48. Differentiate between public and protected visibility in context of Object Oriented
Programming giving suitableexamples for each.
49. How does the invocation of constructor differ in derivation of class and nesting of
classes?
50. What is the difference between the constructor and normal function?
51. Observe the following C++ code very carefully and rewrite it after removing
any/all syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=’N’;
cin>>Speed;
if Speed>Max
Stop=’Y’;
cout<<Stop<<end;
}
52.
Observe the following C++ code very carefully and rewrite it after removing any/all
syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
const Max=70.0;
void main[]
{
int Speed;
char Stop=’N’;
cin<<Speed;
if (Speed>Max)
Stop=’Y’;
cout<<Stop<<endline;
}
53.
Rewrite the following program after removing the syntactical error(s) if any. Underline each
correction.
#include<iostream.h>
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<<N1>>N2;
}
54.
Rewrite the following program after removing the syntactical error(s) if any. Underline each
correction.
#include<iostream.h>
const int Max 10;
void main()
{ int Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];
}
55.
Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction.
#include<iostream.h>
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}M;
gets(movie_name);
gets(movie_type);
}
56.
Rewrite the following program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int X[]={60, 50, 30, 40},Y;Count=4;
cin>>Y;
for(I=Count-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout<<Y*X[I]<<endl;break;
case1:
case 3:cout>>Y+X[I];
}}
57.
Rewrite thefollowing program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int P[]={90, 10, 24, 15},Q;Number=4;
Q=9;
for(int I=Number-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout>>P[I]*Q<<endl;
break;
case 1:
case 3:cout<<P[I]+Q;
}
58.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each
correction.
#include<iostream.h>
void main(){
Present=25,Past=35;
Assign(Present;Past);
Assign(Past);
}
void Assign(int Default1,Default2=30)
{
Default1=Default1+Default2;
cout<<Default1>>Default2;
}
59.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.
#include<iostream.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;
}
60.
Rewrite the following program after removing all the syntactical error(s), if any. Underline each
correction.
#include<iostream.h>
typedef char[80];
void main(){
String S="Peace";
int L=strlen(S);
cout<<S<<'has'<<L<<'characters'<<endl;
}
61.
What are programming paradigms? Give names of some popular programming paradigms.
62. Reusability of classes is one of the major properties of OOP. How is it implemented in C++?
64.
Rewrite the following program after removing the syntactical errors (if any).Underline each
correction.
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<<'characters'<<end1;
}
65. Observe the following C++ code very carefully and rewrite it after removing
any/all syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
66.
Study the following program and select the possible output(s)from the option (i) to (iv)
following it. Also write the maximum and the minimum values that can be assigned to
the variable NUM.
Note:‐ Assume all required header files are already being included in the program.
‐ random(n) function generates an integer between 0 and n‐1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]="ABCDEFGHIJK";
for (int I=1;I<=NUM; I++)
{
for (int J=NUM;J<=7;J++)
cout<<TEXT[J];
cout<<endl;
}
}
(i)FGHI (ii) BCDEFGH (iii) EFGH (iv) CDEFGH
FGHI BCDEFGH EFGH CDEFGH
FGHI EFGH
FGHI EFGH
67.
Go through the C++ code shown 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<stdlib.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 # 55 # (ii) 52 # 53 # 54 # 55
(iii) 53 # 54 # (iv) 51 # 52 # 53 # 54 # 55
68. Go through the C++ code shown below, and find out the possible output or
outputs from the suggested Output Options (i) to (iv). Also find out the minimum and
maximum value that can be assigned to Guess at the time when value of Turn is 3.
#include<iostream.h>
#include<stdlib.h>
void main()
{
char Result[][10]={"GOLD","SILVER","BRONZE"};
int Gt=9,Guess;
for(int Turn=1;Turn<4;Turn++)
{
Guess=random(Turn);
cout<<(Gt-Guess)<<Result[Guess]<<"*";
}
}
(i) 9GOLD*9GOLD*8SILVER*
(ii) 9GOLD*7BRONZE*8GOLD*
(iii) 9GOLD*8SILVER*9GOLD*
(iv) 9GOLD*8SILVER*8GOLD*
69. Observe the code carefully and find which output(s) will be expected from the program?
and justify your answer:
#include <iostream.h>
#include <stdlib.h>
const int K=2;
void main()
{ randomize();
int A;
A=random(K)+2;
for(int i=A;i<3;i++)
cout<<i<<",";
cout<<endl;
}
(i) 1,2, (ii) 0,1,2 (iii) 2, (iv) 0,1,2,
70.
Observe the code carefully and find which output(s) will be expected from the program?
Justify your answer:
#include <iostream.h>
#include <stdlib.h>
void main()
{ randomize(); int A; A=2+random(3);
for(int i=A;i<5;i++)
cout<<'#'<<i;
}
#1#2#3 (ii) #2#3#4 (iii) #4#3#2 (iv) None of these
71.
Observe the code carefully and find which output(s) will not be expected from the program?
Justify your answer:
#include <iostream.h>
#include <stdlib.h>
const int K=4;
void main()
{ randomize();
int A;
A=2+random(K);
for(int i=0;i<A;i++)
cout<<i<<",";
}
(i) 0,1, (ii) 0,1,2, (iii) 0,2,4, (iv) 0,1,2,3,4,5,
72.
Observe the code carefully and select most possible answer from the choices given below and justify your
answer:
#include <iostream.h>
#include <stdlib.h>
#define K 4
void main()
{ randomize();
int A;
A=20+random(K);
for(int i=A;i>=20;i--)
cout<<i<<"^";
cout<<endl;
}
(i) 22^21^20^19^ (ii) 24^23^22^21^20^
(iii) 20^21^22^ (iv) 20^
73.
Observe the following code carefully, if the value of num entered by user is 4, choose the correct
possible output(s) from the options from (i) to (iv) and justify your option.
#include<iostream.h>
#include "stdlib.h"
void main()
{ randomize();
int num, rn;
cin>>num;
rn=random(num)+5;
for(int n=1;n<=rn;n++)
cout<<n<<" ";
}
Output options: (i) 1 2 3 (ii) 5 4 3 2 1
(iii) 1 2 3 4 5 6 (iv) 1 2 3 4
74.
Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are the
expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to the
variable Start used in the code :
#include<iostream.h>
#include <stdlib.h>
void main ()
{
int guess[4]={200,150,20,250};
int Start=random(2)+2;
for(int C1=Start; C1<4; C1++)
cout<<guess[C1]<<'#';
}
75
Read the following C++ code carefully and find out, which out of the given options (i) to
(iv) are the expected correct output(s) of it. Also, write the maximum and minimum value
that can be assigned to the variable Taker used in the code :
#include<iostream.h>
#include <stdlib.h>
void main()
{ int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
cout<<GuessMe[Chance]<<"#"; }
(i) 100#
(ii) 50#200#
(iii) 100#50#200#
(iv) 100#50
76.
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .
void Position (int &C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<endl;
Position(P2,P1);
cout<<P1<<”,”<<P2<<endl;
}
Else
Msg[cnt]=Msg[cnt-1];
}
}
void main()
{
char MyText[]="Input Raw";
Mycode(MyText,'@');
cout<<"NEW TEXT:"<<MyText<<endl;
}
79.
Obtain the output from the following C++ program as expected to appear on the screen
after its execution.
Important Note : - All the desired header files are already included in the code, which are
required to run the code.
void main()
{
char *Text=”AJANTA”;
int *P, Num[]={1,5,7,9};
P=Num;
cout<<*P<<Text<<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}
80.Obtain the output from the following C++ program as expected to appear on the
screen after its execution.
#include<iostream.h>
void SwitchOver(int A[],int N,int split)
{
for(int K=0;K<N;K++)
if(K<split)
A[K]+=K;
Else
A[K]*=K;
}
Void Display(int A[],int N)
{
for(int K=0;K<N;K++)
(K%2==0)?cout<<A[K]<<"%":cout<<A[K]<<endl;
}
void main()
{
int H[]={30,40,50,20,10,5};
SwitchOver(H,6,3);
Display(H,6);
}
81.
Find the output of the following program :
#include <iostream.h>
#include <ctype.h>
void ChangeIt(char Text[ ], char C)
{
for (int K=0;Text[K]!='\0';K++)
{
if (Text[K]>='F' && Text[K]<='L')
Text[K]=tolower (Text[K]);
Else
if (Text[K]=='E' || Text[K]=='e')
Text[K]=C;
Else
if (K%2==0)
Text[K]=toupper(Text[K]);
Else
Text[K]=Text[K-1];
}
}
void main ( )
{
char OldText[ ]="pOwERALone";
ChangeIt(OldText,'%');
cout<<"New TEXT:"<<OldText<<endl;
}
82.
Find. the output of the following program:
#include <iostream.h>
#include <ctype.h>
void MyCode (char Msg [], char CH)
{ for (int Cnt=0;Msg[Cnt]!='\0';Cnt++)
{ if (Msg[Cnt]>='B' && Msg[Cnt]<='G')
Msg[Cnt]=tolower(Msg[Cnt]);
else if (Msg[Cnt]=='A'|| Msg[Cnt]=='a')
Msg[Cnt]=CH;
else if (Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt-1];
}
}
void main ()
{ char MyText [] ="ApEACeDriVE";
MyCode(MyText,'@');
cout<<"NEW TEXT:"<<MyText<<endl;}
83. Find the output of the code segment given below:
#include<iostream.h>
void main( )
{
int A=5,B=10;
for(int I=1;I<=2;I++)
{
cout<<"Line1"<<A++<<"&"<<B-2 <<endl;
cout<<"Line2"<<++B<<"&"<<A+3 <<endl;
}
}
84. Find the output.
#include<iostream.h>
void main( )
{
long int NUM=1234543;
int F=0,S=0;
do
{
int R=NUM % 10;
if (R %2!= 0)
F+= R;
else
S+= R;
NUM/= 10;
} while (NUM>0);
cout<<F-S;
}
85.Find the output of the following program:
#include<iostream.h>
void main( )
{
int var1=5,var2=10;
for(int i=1;i<=2;i++)
{
cout<<var1++<<'\t'<<--var2<<endl;
cout<<var2--<<'\t'<<++var1<<endl;
}
}
86.
What will be the result of following code in C++?
#include<iostream.h>
void main()
{
int a=4,b=2,c=6,d=1;
cout<<(a+6>=9+b || d*b<=10 && a+b+c/d)<<endl;
cout<<(a--+2*b+++a/d);
}
87.
Find the output of code given below:
#include <iostream.h>
int main()
{
int i=0,a=0,b=0,c=0;
while(i<=4)
{
switch(i++)
{
case 1: ++a;
break;
case 2:
case 3: ++b;
case 4: ++c;
default: break;
}
}
cout<<"a="<<a<<"b="<<b<<endl;
cout<<"c="<<c;
return 0;}
88.
What will be the output of the following code fragment?
#include<iostream.h>
int x=10;
void test( int a,int &b,int c=5)
{
a+=x+c;
b=x*c;
c=x/c;
cout<<a<<","<<b<<","<<c<<endl; }
void main( )
{
int x=10,y=20;
test(x,y,::x);
cout<<x<<","<<y<<","<<::x<<endl;
test(::x,x,y);
cout<<::x<<endl; }
89.
Find the output of the following program:2
#include <iostream.h>
#include <ctype.h>
void Encode (char Info [ ], int N) ;
void main ( )
{ char Memo[ ]= "Justnow" ;
Encode (Memo,2) ;
cout<<Memo<<endl ;
}
void Encode (char Info [ ], int N)
{ for (int I = 0;Info[I] !='\0';I++)
if (I%2==0)
Info[I] = Info[I] -N ;
else if (islower(Info[I]))
Info[I] = toupper(Info[I]) ;
else
Info[I] = Info[I] +N ;
}
90.
Find the output of the following program:2
#include <iostream.h>
#include <ctype.h>
void Secret (char Mig[ ], int N);
void main ( )
{
char SMS[ ] = “rEPorTmE” ;
Secret{SMS,2);
cout<<SMS<<end1;
}
void Secret(char Msg[ ], int N)
{
for (int C=0; Msg[C] !=’ \0' ;C++)
if (C%2==0)
Msg[C] = Msg[C]+N;
else if (isupper(Msg[C]))
Msg[C] = tolower(Msg[C]);
else
Msg[C] = Msg[C]-N;
}
91.
Obtain the output from the following c++ program as expected to appear on the screen after its execution.
knponant Note :
- All the desired header files are already included in the code, which are required to run the code.
#include <iostream.h>
void main ( )
{
char *String="SARGAM";
int *Ptr, A[]={1,5,7,9};
Ptr=A;
cout <<*Ptr<<String<<endl;
String++;
Ptr+=3;
cout<<*Ptr<<String<<endl ;
}
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
typedef char str80[80];
void main()
{
char *notes;
str80 str="vR.zGooD";
int L=6;
notes=str;
while(L>=3)
{
str[L]=isupper(str[L])?tolower(str[L]):toupper(str[L]);
cout<<notes<<endl;
L--;
notes++;
}
getch();
}
#include<iostream.h>
void main( )
{ char *p="Difficult";
char c;
c=*p++;
cout<<c<<endl;
cout<<*p;
}
101. Observe the following C++ code and answer the questions (i) and (ii) :
class Traveller
{
long PNR;
char TName[20];
public :
Traveller() //Function 1
{cout<<"Ready"<<endl;}
void Book(long P,char N[]) //Function 2
{PNR = P; strcpy(TName, N);}
void Print() //Function 3
{cout<<PNR << TName <<endl;}
~Traveller() //Function 4
{cout<<"Booking cancelled!"<<endl;}
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3
respectively in the following code:
void main{)
{
Traveller T;
_____________ //Line 1
_____________ //Line 2
}//Stops here
(ii) Which function will be executed at }//Stops here? What is this function referred as ?
102. Observe the following C++ code and answer the questions (i) and (ii) :
class Passenger
{
long PNR;
char Name [20] ;
public:
Passenger() //Function 1
{ cout<<"Ready"<<endl; }
void Book(long P,char N[]) //Function 2
{ PNR = P; strcpy(Name, N); }
void Print() //Function 3
{ cout«PNR << Name <<endl; }
~Passenger() //Function 4
{ cout<<"Booking cancelled!"<<endl; }
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function
3 respectively in the following code:
void main()
{
Passenger P;
___________ //Line 1
___________ //Line 2
}//Ends here
(ii) Which function will be executed at }//Ends here? What is this function referred as?
103. Answer the questions (i) and (ii) after going through the following class :
class Health
{
int PId, DId;
public:
HeaIth (int PPId) ; // Function 1
Health ( ) ; // Function 2
Health (Health &H); //Function 3
void Entry ( ) ; // Function 4
void Display( ) ; // Function 5
};
void main ( )
t
Health H (20) ; //statement 1
}
(i) Which of the function out of Function 1,2,3, 4 or 5 will get executedwhen the Statement I is
executed in the above code ?
(ii) Write a statement to declare a new object G with reference to alreadyexisting object H using
Function 3.
104.
Answer the questions (i) and (ii) after going through the following class:
class TEST
{
int Regno, Max, Min, Score;
public:
TEST() //Function 1
{
Regno= 101;
Max=100;
Min=40;
Score=75;
}
TEST(int Pregno,int Pscore) //Function 2
{
Regno=Pregno;
Max=100;
Min=40;
Score=Pscore;
}
~TEST() //Function 3
{
cout<<“TEST Over”<<endl;
}
void Display() //Function 4
{
cout<<Regno<<“:”<<Max<<“:”<<Min<<endl;
cout<<“[Score]”<<Score<<endl;
}};
(i) As per Object Oriented Programming, which.concept is illustrated by Function 1
and
Function 2 together?
(i) What is Function 3 specifically referred as? When do you think, Function 3 will
beinvoked/called?
105.
Answer the questions (i) and (ii) after going through the following class:
class Race
{ int CarNo, Track;
public:
Race(); // Function 1
Race(int CN); // Function 2
Race(Race &R); // Function 3
void Register(); // Function 4
void Drive(); // Function 5
};
void main()
{ Race R;
}
(i) Out of the following, which of the option is correct for calling Function 2?
Option 1- Race T(30);
Option 2- Race U(R);
(ii) Name the feature of Object Oriented Programming, which is illustrated by Function
1, Function 2 and Function 3 combined together.
106. Answer the questions after going through the following class.
class Exam
{ char Subject[20] ;
int Marks ;
public :
Exam() // Function 1
{ strcpy(Subject, “Computer” ) ; Marks = 0 ;}
Exam(char P[ ]) // Function 2
{
strcpy(Subject, P) ;
Marks=0 ;
}
Exam(int M) // Function 3
{
strcpy(Subject, “Computer”) ; Marks = M ;
}
Exam(char P[ ], int M) // Function 4
{ strcpy(Subject, P) ; Marks = M ; }};
(i) Which feature of the Object Oriented Programming is demonstrated using Function 1, Function2,
Function 3 and Function 4 in the above class Exam?
(ii) Write statements in C++ that would execute Function 3 and Function 4 of class Exam.
107. Answer the questions (i) and (ii) after going through the following class:
class Exam
{
int Rno,MaxMarks,MinMarks,Marks;
public:
Exam ( ) //Module 1
{
Rno=101;
MaxMarks=l00;
MinMarks=40;
Marks=75;
}
Exam (int Prno, int Pmarks) //Module 2
{ Rno=Prno;
MaxMarks=l00;
MinMarks=40;
Marks=Pmarks;
}
~Exam () //Module 3
{
cout<<“Exam Over”<<endl;
}
void Show () //Module 4
{
cout<<Rno<<“:”<<MaxMarks<<“:”<<MinMarks<<endl
;
cout<<“[Marks Got]”<<Marks<<endl;
}
};
(i) As per Object Oriented Programming, which concept is illustrated byModule 1 and
Module2 together?
(ii) What is Module 3 referred as ? When doyou think, Module 3 will be invoked/called?
108.
Consider the following declaration:
class welcome
{
public:
welcome (int x, char ch); // constructor with parameter
welcome(); // constructor without parameter
void compute();
private:
int x; char ch;
};
Which of the following are valid statements?
welcome obj (33, ‘a9’);
welcome obj1(50, ‘9’);
welcome obj3();
obj1= welcome (45, ‘T’);
109.
Answer the questions (i) and (ii) after going through the following program:
class TestMeOut
{ public:
~TestMeOut( ) //Function 1
{
cout<<”Leaving the examination hall”<<endl;
}
TestMeOut( ) //Function 2
{
cout<<”Appearing for examination”<<endl;
}
void MyWork( )
{
cout<<”Attempting Questions”<<endl;
}
};
(i) In Object Oriented programming what is Function 1 referred as and when does it get
invoked/called?
(ii) In Object Oriented Programming,what is Function 2 referred as and when does it get
invoked/called?
110.
Answer the following questions (i) and (ii) after going through the following class.
class Test
{ char Paper[20];
int Marks
public:
Test() //Function 1
{ strcpy(Paper, “Computer”);
Marks=0;
}
//Function 2
Test(char P[])
{ strcpy(Paper,P);
Marks=0;
}
//Function 3
Test(int M)
{ strcpy(Paper,”Computer”);
Marks=M;
}
Test(char P[],int M)
//Function 4
{ strcpy(Paper,P);
Marks=M;
}
};
(i)Which feature Object Oriented programming is demonstrated using Function 1, Function 2,
Function 3 and Function 4 in the above class text?
(ii)Write statements in C++ that would execute Function 2 and Function 4 of class Text.
111.
Write function definition for SUCCESS () in C++ to read the content of a
text file STORY.TXT count the presence of word STORY and display the
number of occurrence of this word.
Note : The word STORY should be an independent word.
Ignore type cases (i.e. lower/upper case)
112.
Write function definition for TOWER() in C++ to read the contentof a text
file WRITEUP.TXT, count the presence of word TOWERand display the number
of occurrences of this word.
Example:
If the content of the file WRITEUP.TXT is as follows:
Tower of hanoi is an interesting problem.Mobile phone tower is away from
here. Viewsfrom EIFFEL TOWER are amazing.
The function TOWER () should display the following:3
113.
Write a function EUCount()in C++, which should read each character of a
textfile IMP.TXT, should count and display the occurrence of alphabets E
and U(including small cases e and u too).
Example :
If the file content is as follows:
Updated informationis simplified by official websites.
The EUCount() function should display the output as:
E:4
U:1
114.
Write a function AECount() in C++, which should read each character of a text file
NOTES.TXT, should count and display the occurrence of alphabets A and E (including
small cases a and e too).
Example :
If the file content is as follows :
CBSE enhanced its
CCE guidelines further.
The AECount() function should display the output as
A:1
E:7
115.
Write a function CountYouMe() in C++ which reads the contents of a text
file story.txt and counts the wordsYou and Me (not case sensitive).
For example, if the file contains:
You are my best friend.
You and me make a good team.
The function should display the output as
Count for You: 2
Count for Me: 1
116.
Write a function TotalDigits() in C++ , which reads the contents of the
Text File “child.txt” and display the number of digits in it.
If the file contains:
All in all, I would like to be 500 note
and my elders would be 1000 note.
Then the output should be: 7
117.
Assuming the class WORKER as declared below, write a function in c++ to
read the objects of WORKER from binary file name “WORKER.DAT” and display
those records of workers whose wage is less than 300.
class WORKER
{ int WNO;char WName[50]; float Wage;
public :
void enter() { cin>>WNO; gets(WName); cin>>Wage;}
void display() { cout<<WNO<<”*”<<WName<<”*”<<Wage<<endl;}
float GetWage() { return Wage;}
};
118.
Write a function in a C++ to read the content of a text file “UNO.TXT”
and display all those lines on screen, which are either starting with ‘D’
or starting with ‘M’.
119.
Write a function in C++ to count the words“this” and “these” present in a
text file“ARTICLE.TXT”.
[Note that the words “this” and “these” arecomplete words]
120.
Write a function in C++ to count the words“to” and “the” present in a
text file“POEM.TXT”.
[Note that the words “to” and “the” arecomplete words]
121.
Write a function in a C++ to count the number of lowercase alphabets
present in a text file “BOOK.txt”.
122.
Assume a text file “coordinate.txt” is already created. Using this file
create a C++ function to count the number of words having first character
capital.
123.
Write a function to count the number ofblanks present in a text file
named“PR.TXT” .
3 Mark Questions
class Calc
{
char Grade;
int Bonus;
public:
Calc(){Grade='E' ; Bonus=0;}
void Down(int G)
{ Grade= G; }
void Up(int G)
{ Grade+=G; Bonus++; }
void Show()
{ cout<<Grade<<"#"<<Bonus<<endl; }
};
void main()
{
Calc c;
C.Down(97); C.Show();
C.Up(3); C.Show();
C.Up(-32); C.Show();
}
2. Write the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
class Eval
{ char Level;
int Point;
public:
Eval() {Level='E';Point=0;}
void Sink(int L)
{ Level-= L; }
void Float(int L)
{ Level+= L; Point++; }
void Show()
{ cout<<Level<<"#"<<Point<<endl;
}};
void main()
{ Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
3. Obtain the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
class Player
{
int Score,Level;char Game;
public :
Player(char GGame='A')
{Score=0;Level=1;Game=GGame;}
void Start(int SC) ;
void Next();
void Disp()
{ cout<<Game<<"@"<<Level<<endl;
cout<<Score<<endl;
}};
void main()
{ Player P,Q('B');
P.Disp();
Q.Start(75);
Q.Next();
P.Start(120);
Q.Disp();
P.Disp();
}
void Player::Next()
{ Game=((Game=='A')?'B':'A'); }
void Player::Start(int SC)
{ Score+=SC;
if (Score >=100 )
Level=3;
else if (Score>=50 )
Level=2;
else
Level=1;
}
4.
Obtain the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in
the program.
void in(int x,int y,int &z)
{ x+=y; y--; z*=(x-y); }
void out(int z,int y, int &x)
{ x*=y; y++;z/=(x+y); }
void main()
{ int a=20, b=30, c=10;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl;
in(b,c,a);
cout<<a<<"@"<<b<<"@"<<c<<"@"<<endl;
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}
5. Obtain the output of the following C++ program code:
#include<iostream.h>
class TQ
{
int r; float s;
public:
TQ(){ r=1;s=5;}
TQ(TQ &Q)
{ r=Q.r++; s=Q.s+=5; }
void Bonus(float B=5)
{ s+=B; }
void Res() { cout<<r<<','<<s<<endl;}
};
void main()
{ TQ A;
A.Res();
A.Bonus(10);
A.Res();
TQ B(A);
B.Bonus();
B.Res();
}
#include <iostream.h>
struct PLAY
{ int Score, Bonus;};
void Calculate(PLAY &P, int N=10)
{
P.Score++;P.Bonus+=N;
}
void main()
{
PLAY PL={10,15};
Calculate(PL,5);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
Calculate(PL);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
Calculate(PL,15);
cout<<PL.Score<<":"<<PL.Bonus<<endl;
}
10. Obtain the output of the following C++ program code:
#include<iostream.h>
struct Package
{ int Length,Breadth,Height;
};
void Occupies(Package M)
{ cout<<M.Length<<"x"<<M.Breadth<<"x";
cout<<M.Height<<endl;
}
void main( )
{ Package P1={10,20,30},P2,P3;
++P1.Height;
Occupies(P1);
P3=P1;
++P3.Length;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Height+=50;
P2.Length--;
Occupies(P2);
}
11. Obtain the output of the following C++ program code:
#include<iostream.h>
void Indirect(int Temp=25)
{ for(int I=15;I<=Temp;I+=5)
cout<<I<<' ';
cout<<endl;
}
void Direct(int &Num)
{ Num+=10;
Indirect(Num);
}
void main( )
{ int Number=10;
Direct(Number);
Indirect( );
cout<<"Number ="<<Number<<endl;
}
12. Obtain the output of the following C++ program code:
#include<iostream.h>
#include<ctype.h>
void main( )
{ char STR[]="WhatOutPut!";
for(int I=0; STR[I]!='\0';I++)
{ if(!isalpha(STR[I]))
STR[I]='*';
else if(isupper(STR[I]))
STR[I]=STR[I]+1;
else
STR[I] =STR[I+1];
}
cout<<STR;}
17. Assuming the class GAMES as declared below, write a functions in C++
to readthe objects of GAMES from binary file GAMES.DAT and display the
detailsof those GAMES, which are meant for children of Age Range“8 to
13".
class GAMES
{
int GameCode;
char GameName [10] ;
char *AgeRange;
public :
void Enter ()
{
cin>>GameCode;
gets (GameName);
gets (AgeRange);}
void Display()
{
cout <<Gamecode<<”:”<<GameName<<endl;
cout<<AgeRange<<endl ;
)
Char*AgeR () {return AgeRange; }
};
18.
Assuming the class TOYS as declared below, write a functions in C++ to
readthe objects of TOYS from binary file “TOYS.DAT” and display the
detailsof those TOYS, which are meant for children of Age Range “5to 8".
class TOYS
{
int ToyCode;
char ToyName [10] ;
char *AgeRange;
public :
void Enter ()
{
cin>>ToyCode;
gets (ToyName);
gets (AgeRange);}
void Display()
{
cout <<Toycode<<”:”<<ToyName<<endl;
cout<<AgeRange<<endl ;
)
Char *WhatAge () {return AgeRange; }
};
19.
Given a binary file GAME.DAT, containing records of the following
structure type
struct Game
{
char GameName[20];
char Participant[10][30];
};
Write a function in C++ that would read the contents from the file
GAME.DAT and creates a file named BASKET.DAT copying only those records
from GAME.DAT where the gamename is“Basket Ball”.
20.
class book
{
int book_no;
char book_name[20];
float price;
public:
void enter_book_Details( )
{
cin>> book_no>> price; gets(book_name);}
void show_book_Details( );
int checkbookno(int bookno)
{
If(book_no==bookno)
Return(0);
Else
Return (1);
};
Write a function deleteBook() in C++ that deletes the required book
record from the binary file BOOKS.DAT based on book_no.
class mobile
{
char number[10]; int calls;
public:
void Enter() { gets(number);cin>>calls;}
void Billing(){cout<<number<<”#”<<calls<<endl;
24. Write a function in C++ to search for a tablet from a binary file
“tablet.dat” containing objects of class tablet (defined below). The user
should enter the ModelNo and function should search and display the
detail of tablet.
class tablet
{
long ModelNo; float RAM, HD;
char Details[20];
public:
void Enter(){ cin>>ModelNo>>RAM>>HD; gets(Details);}
void Disp(){ cout<<ModelNo<<RAM<<HD<<Details<<endl;}
long Model(){ return ModelNo;}
};
25. Write a function in C++ to read and display the detail of all the
members whose membership type is ‘L’ or ‘M’ from a binary file
“CLUB.DAT”. Assume the binary file “CLUB.DAT” contains objects of class
CLUB, which is defined as follows:
class CLUB
{
int Mno; //Member Number
char Mname [20]; //Member Name
char Type; //Member Type: L Life Member M Monthly Member
public:
void Register (); //Function to enter the content
void Display (); // Function to display all data members
char WhatType () {return Type;).
};
26.
Write a function in C++ to search anddisplay details of all flights,
whose destinationis “Mumbai” from a binary file“FLIGHT.DAT”. Assuming the
binary file iscontaining the objects of the following class.
class FLIGHT
{ int Fno; //Flight Number
char From[20]; //Flight Starting Point
char To[20]; //Flight Destination
public:
void Enter( )
{
cin>>Fno;
gets(From);
gets(To);
}
char* GetFrom( )
{return From;}
char* GetTo( )
{return To;}
void Display( )
{
cout<<Fno<<“:”<<From<<“:”<<To<<endl;
}
};
27. Write a function in C++ to search and display details of all trains,
whose destination is“Delhi”from a binary file“TRAIN.DAT”.Assuming the
binary file is containing theobjects of the following class.
class TRAIN
{ int Tno; // Train Number
charFrom[20]; // Train Starting Point
charTo [20]; // Train Destination
public:
char* GetFrom( )
{return From;}
char* GetTo( )
{return To;}
void Input( )
{cin>>Tno;gets(From);gets(To);
}
void Show( )
{
cout<<Tno<<“:”<<From<<“:”<<To<<endl;
}
};
4 Marks Questions
Public Members
Enter()// A function to allow user to enter valuesPno,category and
call //FixLocation() function
SeeAll()// A function to display all the data members
For Material other than “COTTON” the above mentioned Price gets reduced
by 25%.
Public Members:
A constructor to assign initial values of Code, Type and Material with
the word “NOT ASSIGNED” and Size and Price with 0.
A function Enter () to input the values of the data members Code, Type,
Size and Material and invoke the CalcPrice() function.
A function Show () which displays the content of all the data members for
a Clothing.
12. Define a class Travel in C++ with the description given below:
Private Members:
T_Code of type string
No_of_Adults of type integer
No_of_Children of type integer
Distance of type integer
TotalFare of type float
Public Members:
A constructor to assign initial values as follows :
T_Code with the word “NULL”
No_of_Adults as 0
No_of_Children as 0
Distance as 0
TotalFare as 0
A function AssignFare( ) which calculates and assigns the value of the
data member TotalFare as follows :
For each Adult
Fare (Rs) Distance (Km)
500 >=1000
300 <1000 &>=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned in the
above table.
For example :
If Distance is 750, No_of_Adults = 3 and No_of_Children = 2
Then TotalFare should be calculated as No_of_Adults * 300 +
No_of_Children * 150i.e. 3 * 300 + 2 * 150 = 1200
• A function EnterTraveK ) to input the values of the data members
T_Code, No_of_Adults, No_of_Children and Distance; and invoke the
AssignFare( ) function.
• A function ShowTraveK) which displays the content of all the data
members for a Travel.
13.
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 follows:
Score Remarks
>=50 Selected
less than 50 Not selected
Public Members
_ A function ENTER ( ) to allow user to enter values for RNo, Name,
Score & call function AssignRem( ) to assign the remarks.
_ A function DISPLAY ( ) to allow user to view the content of all the
datamembers.
15.
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 Grades are shown as follows
Aggregate Marks Grade
> = 80 A
Less than 80 and > = 65 B
Less than 65 and > = 50 C
Less than 50 D
Public Members
o A function Enter( ) to allow user to enter values for ANo, Name, Agg & call function GradeMe( )
to find the Grade
o A function Result ( ) to allow user to view the content of all the data members.
16.
Define a class ORDER in C++ with following description:
Private Members
· ICode of type integer (Item Code)
· Item of type string (Item Name)
· Price of type float (Price of each item)
· Qty of type integer (Quantity in stock)
· Discount of type float (Discount percentage on the item)
· A member function FindDisc() to calculate discount percentage as per the following rule:
If Qty < =50 Discount is 0
If 50 < Qty < =100 Discount is 5
If Qty > 100 Discount is 10
Public Members
· A function Buy () to allow user to enter values for ICode, Item, Price, Qty and call function
FindDisc() to calculate Discount.
· A Function ShowAll() to allow user to view the content of all the data members.
18. A dining hall can accommodate only 50 guests. Define a class to store seat number and name of the
guests who are seated on first come first seated basis. Define functions to display details of any seat
number and to display the current seating situation. Write a program to show the working of this class.
19.
Define a class named Tour in C++ with following description?
Private members:
tcode integer (Ranges 6 - 10)
adults, children, distance integer
totalfare float
AssignFare( ) A function which calculates and assign the value to data member
totalfare as follows:-
- For adults Fare Distance
Rs. 500 >=1500
And fare get reduced by 25% if distance is < 1500.
- For Children
For every child a fixed Rs. 50 is charged as fare.
Public members:
A constructor which initialized initialize all data members with 0
Function EnterTour() to input the values of the data members tcode, adults, children and call to
AssignFare function.
Function ShowTour() to print all the details of object of Travel type.
20.
Define a class named Admission in C++ with following description? 4
Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0
Function getdata() to read the object of Admission type.
Function putdata() to print the details of object of admission type.
Function draw_nos() to generate the admission no. randomly to match with admno and display the detail of object.
21. Answer the question (i) to (iv) based on the following:
class Exterior
{
int OrderId;
char Address[20];
protected:
float Advance;
public:
Exterior();
void Book();
void View();
};
class Paint:public Exterior
{
int WallArea,ColorCode;
protected:
char Type;
public:
Paint() ;
void PBook();
void PView();
};
class Bill:public Paint
{
float Charges;
void Calculate();
public:
Bill() ;
void Billing() ;
void Print() ;
};
(i) Which type of Inheritance out of the following is illustrated
23. Consider the following C++ code and answer the questions from (i) to (iv) :
class University { long Id; char City[20];
protected: char Country[20]; public: University(); void Register( ); void
Display( ); };
class Department: private University { long DCode[10];char HOD[20];
protected:
double Budget; public: Department();
void Enter();
void Show(); };
class Student: public Department { long RollNo; char Name[20];
public:
Student();
void Enroll();
void View(); };
(i) Which type of Inheritance is shown in the above example ?
(ii) Write the names of those member functions, which are directly accessed from the
objects of class Student.
(iii) Write the names of those data members, which can be directly accessible from the
member functions of class Student.
(iv) Is it possible to directly call function Display( ) of class University from an object of
class Department ? (Answer as Yes or No).
24. Consider the following C++ code and answer the questions from (i) to
(iv):
class Campus
{
long Id;
char City[20];
protected:
char Country [2O] ;
public :
Campus();
void Register();
void Display() ;
);
char Section;
protected :
char SName[20];
public:
Student() ;
void Stentry();
void Stdisplay();
};
class Score: private Student
{
float Marks[S];
protected:
char Grade[S];
public:
Score();
voidSentry();
voidSdisplay();
};
classReport:publicScore
{ floatTotal,Avg;
public:
charOverallGrade, Remarks[20];
Report();
voidREvaluate();
voidRPrint();
};
(ii) Write the names ofthose data members, which can be directly accessed
fromtheobjects ofclassReport.
(iii) Write the names of those member functions, which can be directly
accessed fromtheobjectsofclassReport.
(iv) Write the names of those data members, which can bedirectly accessed
fromtheSentryt()function ofclassScore.
26. Consider the following c++ code and answer the questions from (i) to
(iv):
class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal();
void pentry();
void Pdisplay();
};
class Marks: private Personal
{ float M[5];
protected:
char Grade[5];
public:
Marks(); void Mentry (); void Mdisplay();
};
class Result: public Marks
{ float Total, Agg;
public:
char FinalGrade, Comments[20];
Result();
void Rcalculate();
void Rdisplay();
};
(ii) Write the names ofthose data members, which can be directly accessed fromtheobjects
ofclassResult.
(iii) Write the names of those member functions, which can be directly accessed
fromtheobjectsofclassResult.
(iv) Write the names of those data members, which can bedirectly accessed fromtheMentryt()
function ofclassMarks.
27. Answer the questions (i) to (iv)based onthe following: .
classCOMPANY
{ charLocation[20];
double Budget,Income;
protected:
voidAccounts();
public: COMPANY();
voidRegister();
voidShow();
};
classFACTORY: public COMPANY
{ charLocation[20) ;
intWorkers;
protected:
double Salary;
voidComputer();
public:
FACTORY();
voidEnter();
voidShow();
};
classSHOP:private COMPANY
{ charLocation[20]; floatArea; double Sale;
public: SHOP();
voidInput();
voidOutput();
};
32. Answer the questions (i) to (iv) based on the following code:
class Dolls
{ char DCode[5];
protected:
float Price ;
void CalcPrice(float);
public:
Dolls( );
void DInput( );
void DShow( );
};
class SoftDolls: public Dolls
{ char SDName[20];
float Weight;
public:
SoftDolls( );
void SDInput( );
void SDShow( );
};
class ElectronicDolls: public Dolls
{ char EDName[20];
char BatteryType[10];
int Battieries;
public:
ElectronicDolls ( );
void EDInput( );
void EDShow( );
};
(i) Which type of Inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class
ElectronicDolls?
(iii) Write name of all the data members accessible from member functions
of the class SoftDolls.
(iv) Write name of all the member functions accessible by an object.
33. consider the following class declaration and answer the question
below :
class university
{ int noc;
protected;
char uname[25];
public:
university();
char state[25];
void enterdata();
void displaydata();
};
class college : public university
{ int nod;
char cname[25];
protected:
void affiliation();
public:
college();
void enrol(int ,int);
void show();
};
class department : public college
{ char dname[25];
int nof;
public:
department();
void display();
void input();
};
(i) Which class’s constructor will be called first at the time of
declaration of an object of class department?
(ii) How many bytes does an object belonging to class department require?
(iii)Name the member function(s), which are accessed from the object of
class department.
(iv) Name the data member, which are accessible from the object of class
college.
34. Answer the questions(i) to (iv) based on the following :
class cloth
{ char category[5];
char description[25];
protected:
float price;
public:
void Entercloth( );
void dispcloth( );
};
36. Consider the following declarations and answer the questions given
below :
class living_being
{ char name[20];
protected:
int jaws;
public:
void inputdata(char, int);
void outputdata();
}
class animal : protected living_being
{ int tail;
protected:
int legs;
public:
void readdata(int, int);
void writedata();
};
37. Consider the following and answer the questions given below:
class MNC
{
char Cname[25]; // Company name
protected :
char Hoffice[25]; // Head office
public :
MNC( );
char Country[25];
void EnterDate( );
void DisplayData( );
};
class Branch : public MNC
{
long NOE; // Number of employees
char Ctry[25]; // Country
protected:
void Association( );
public :
Branch( );
void Add( );
void Show( );
};
class Outlet : public Branch
{
char State[25];
public :
Outlet();
void Enter();
void Output();
};
(i) Which class’s constructor will be called first at the time of
declaration of an object of class Outlet?
(ii) How many bytes 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.