Академический Документы
Профессиональный Документы
Культура Документы
strrev(str);
puts(str);
puts(str1); }
4. 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 :
[2014, outside Delhi]
void main()
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<< starts with <<CH<<endl;
}
5. Observe the following C++ code and write the name(s) of the header fiIe(s), which will be essentially
required to run it in a C++ compiler :
[2014, Delhi]
void main ( )
{
char Text[20] , C;
cin>>Text;
C = tolower (Text [0]);
cout<<C<<" is the first char of " <<Text<<end1;
}
6. 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:
[CBSE,2013]
void main ( )
{
int number;
cin >> number;
if (abs (number) = = number);
cout << Positive <<endl;
}
7. Write the names of the header files, which is/are essentially required to run/execute the following C++
code:
[CBSE, 2011]
void main ( )
{
char C, String [ ] = "Excellence Overload";
for (int I=0; String [ I ] ! = '\ 0'; I ++ )
if (String [I] ==' ')
cout<<end1;
else
{
C=toupper(String[I]);
cout<<C ;
}
}
8. Which C++ header file(s) will be essentially required to be included to run/execute the following C++
code?
[CBSE, 2010]
void main( )
{
int Eno=123, char Ename[ ]=Rehan Swamp;
cout<<setw(5)<<Eno<<setw(25)<<EName<<endl;
}
9. Name the header files that shall be needed for the following code:
void main ( )
[CBSE, 2008]
{
char word [ ]= Exam;
Cout << setw (20) << word ;
}
10. Name the header file(s) that shall be needed for successful compilation of the following C++ code :
[CBSE, 2007]
void main( )
{
char Text[40];
strcpy(Text,AISSCE);
puts(Text);
}
11. Name the header file(s) that shall be needed for successful compilation of the following C++ code:
[CBSE, 2006]
void main ( )
{
char String [20];
gets (String);
strcat (String, CBSE);
puts (String);
}
12. Name the header file to which the following belong:
i. pow ( )
ii. random ( )
[CBSE, 2006-SET1]
[CBSE, 2006-SET2]
{ int s=a[0];
for(int x=1;x<n;x++)
if(a[x]>s)
a[x]=s;
return(s);
}
Q 6. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure
that you underline each correction done by you in the code.
[CBSE 2012]
Important Note :
Assume that all the required header files are already included, which are essential to run this code.
The corrections made by you do not change the logic of the program.
typedef char[80] STR;
void main()
{
Txt STR;
gets(Txt);
cout<<Txt[0]<<\t<<Txt[2];
cout<<Txt<<endline;
}
Q 7. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make
sure that you underline each correction done by you in the code.
Important Note :
[CBSE, 2011]
- Assume that all the required header files are already included, which are essential to run this code.
- The corrections made by you do not change the logic of the program.
typedef char [50] STRTNG;
void main ( )
{
City STRING;
gets (City) ;
cout<<City [0] << \t<<City [2] ;
cout << City << endline ;
}
Q 8. Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
[CBSE, 2010]
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<< 'characters' <<end1;
}
Q 9. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2009]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<:<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 10. Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2008]
include <iostream.h>
class FLIGHT
{
long FlightCode;
char Description [25];
public
void AddInfo ( )
{
cin >> FlightCode;
}
gets(Description);
void ShowInfo ( )
{
cout << FlightCode << : << Description << endl;
}
};
void main ( )
{
FLIGHT F;
AddInfo. F ( );
ShowInfo ( );
}
6
Q 11. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2007]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<:<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 12. Rewrite the following program after removing the syntax error(s), if any. Underline each correction.
[CBSE, 2006, SET-III]
# 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;
}
Q 13. Rewrite the following program after removing the syntactical error(s), if any. [CBSE, 2006, SET-II]
Underline each correction.
#include <iostream.h>
const int Size 5;
void main()
{
int Array[Size];
Array = {50,40,30,20,10};
for(Ctr=0; Ctr<Size; Ctr++)
cout>>Array[Ctr];
}
Q 14. Rewrite the following program after removing the syntactical error(s) if any.
[CBSE, 2006, SET-I]
7
else
Msg[cnt]=Msg[cnt1];
}}
void main( )
{ char MyText[]="Input Raw";
Mycode(MyText,@);
cout<<"NEW TEXT:"<<MyText<<endl; }
Q 4. Obtain the output from the following C++ program as expected to appear on the screen after its
execution. [CBSE, 2014, Outside Delhi]
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;
}
Q 5. 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 ( )
[CBSE, 2014, Delhi]
{
char *String = SARGAM ;
int *ptr, A [ ] = { 1,5,7,9 };
Ptr = A;
cout << * ptr << String<< end1 ;
String++;
Ptr+=3;
cout<< * Ptr << String<<endI;
}
Q 6. Find the output of the following program:
[CBSE, 2013]
#include<iostream.h>
void main ( )
{
int Track [ ] = {10, 20, 30, 40}, *Striker ;
Stxiker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<end1 ;
Striker =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<end1 ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<end1 ;
10
[CBSE, 2011]
[CBSE,2010-setI]
11
}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< #;
cout<<endl;
}
Q 10. Find the output of the following program :
# include < iostream.h>
void main ( )
{
intArray[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<#;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=l; I<5; I + + )
cout << Array [I-1] << @;
cout << endl;
}
[CBSE,2008]
[CBSE, 2007-II]
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{
int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
Q 13. Find the output of the following program:
#include<iostream.h>
[CBSE, 2006]
void main( )
{ long NUM = 1234543;
int F = 0, S = 0;
do
{ int Rem = NUM% 10;
if (Rem % 2 !=0)
F+ =R;
else
S+ = R;
NUM/=10;
} while(NUM>0);
cout<<F-S;
}
{
cout<<Level<<#<<Point<<endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
Q 2. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Delhi]
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<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
Q 3. Find the output of the following program :
[CBSE, 2014,Outside Delhi-I]
14
#include<iostream.h>
void in(int x,int y, int &z)
{
x+=y;
y ;
z*=(xy);
}
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;
}
Q 4. Obtain the output of the following C++ program, which will appear on the screen after its execution.
Important Note :
[CBSE, 2014,Outside Delhi]
All the desired header files are already included in the code, which are required to run the code.
class Game
{
int Level, Score;
char Type;
public:
Game(char GType=P)
{Level=1;Score=0;Type=GType;}
void Play(int GS);
void Change();
void Show()
{
cout<<Type<<@<<Level<<endl;
cout<<Score<<endl;
}
};
void main()
{
Game A(G),B;
B.Show();
A.Play(11);
A.Change();
B.Play(25);
A.Show();
B.Show();
}
void Game::Change()
{
Type=(Type==P)?G:P;
15
}
void Game::Play(int GS)
{
Score+=GS;
if(Score>=30)
Level=3;
else if(Score>=20)
Level=2;
else
Level=1;
}
Q 5. Observe the following C++ code carefully and obtain the output, which will appear on the screen after
execution of it.
[cbse, 2014, delhi]
# include <iostream.h>
class Aroundus
{
int Place, Humidity, Temp;
public :
Aroundus (int p=2) { Place=P; Humidity = 60; Temp = 20;}
void Hot (int T) { Temp += T;}
void Humid (int H) { Humidity + = H;}
void JustSee ( )
{
cout << Place << : <<Temp << & << Humidity
<< % <<endl;
}
};
void main ( )
{
Aroundus A, B(5);
A. Hot (10);
A.JustSee( );
B.Humid (15);
B.Hot (2);
B.JustSee ( );
A.Humid (5);
A.justSee( );
}
Q 6. Find the output of the following program:
#include<iostream.h>
[cbse, 2013]
void ChangeArray(int Number, int ARR[ ], int Size)
{
for (int L =0; L<Size; L++)
if (L<Number)
ARR [L] +=L;
e1se
ARR [L] *=L;
}
16
[cbse, 2011]
{
if ( isalpha (Mystring [ I ] ) )
Mystring [ I ] = * ;
else
if
( isupper (Mystring [ I ]) )
Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1];
}
cout<< Mystring;
}
Q 9. Find the output of the following program :
[CBSE-2007-II]
#include<iostream.h>
void Indirect(int Temp=20)
{
for (int I=10; I<=Temp; I+=5)
cout << I <<, ;
cout << endl ;
}
void Direct (int &Num)
{
Num + = 10;
Indirect (Num) ;
}
void main()
{
int Number=20;
Direct(Number);
Indirect();
cout<< Number= <<Number<<endl ;
}
Q 10. Find the output of the following program :
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20 ; I<*= HisNum; I+=5)
cout<<I<<;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
[CBSE, 2007-I]
18
}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<Number=<<YourNum<<endl;
}
Q 11. Find the output of the following program
# include<iostream.h>
[CBSE, 2006]
#include<string.h>
class state
{
char * state_name;
int size;
public;
state( ); { size=0; state_name=new char[size+1]; }
state(char *s)
{ size = strlen(s) ; state_name = new char[size+1];}
strcpy(state_name,s);
}
void display() {cout<<state name<<endl; }
void Replace (state &a, state &b)
{ size = a.size + b.size;
delete state_name;
state_name = new char[size+1] ;
strcpy(state_name, a.state_name);
strcat(state_name, b.state_name);
}
};
void main( )
{ char *temp = Delhi;
state state1(temp), state2(Mumbai), state3(Nagpur), SI, S2;
SI .Replace(state1, state2);
S2.Replace(S1, state3);
S1.display( );
S2.display( );
}
(ii)
CDEFGH
CDEFGH
(iii)
EFGH
EFGH
EFGH
EFGH
(iv)
FGHI
FGHI
FGHI
FGHI
Q 2. Study the following program and select the possible output(s) from the options (i)
to (iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable NUM.
Note :
[CBSE, 2015, DELHI]
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<<end1;
}
}
(i) FGHI
(ii) BCDEFGH
FGHI
BCDEFGH
FGHI
FGHI
(iii) EFGH
EFGH
EFGH
EFGH
(iv) CDEFGH
CDEFGH
Q 3. 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 :
[CBSE, 2014, Outside Delhi]
20
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
Q 4. Based on the following C++ code, find out the expected correct output(s) from the option (i) to (iv).
Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in the
code at the time when value of Count is 3: [cbse, 2013]
void main ( )
char Status [ ]
(int
{
Trick = random ( Count ) ;
cout << Turn Trick << Status [ Trick ] << # ;
}
}
(i)
(ii)
10 EXCEL # 10 EXCEL # 80 K #
10 EXCEL # 80 K # 9GOOD#
(iii)
10 EXCEL # 9GOOD # 10 EXCEL #
(iv)
10 EXCEL# 10 GOOD # 80 K #
Q 5. 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>
[CBSE 2011]
#include <stdlib.h>
void main ( )
{
randomize ( ) ;
int Guess, High=4;
Guess=random{High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;
}
21
(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55
Q 6. The following code is from a game, which generates a set of 4 random numbers. Yallav is playing this
game, help him to identify the correct option(s) out of the four choices given below as the possible set of
such numbers generated from the program code so that he wins the game. Justify your answer.
[CBSE 2010]
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<: ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:
Q 7. In the following program, find the correct possible output(s) from the options:[CBSE 2008]
#include <stdlib.h>
#include <iostream.h>
void main ( )
{
randomize ( );
char Area [ ] [ 10 ] = { NORTH , SOUTH , EAST, WEST);
int ToGo;
22
for
{
To Go = random (2) + 1;
cout<< Area [ToGo ]<< :;
}
}
Outputs:
(i)
SOUTH:EAST:SOUTH:
(ii)
(iii)
(iv)
Q 8. In the following C++ program what is the expected value of MyMarks from Options (i) to (iv) given
below. Justify answer.
[CBSE, 2007]
#include<stdlib.h >
# include<iostream.h>
void main ()
{
randomize ();
int Marks [ ]= {99, 92, 94, 96, 93, 95}, MyMarks;
MyMarks = Marks [1 + random (2) ];
cout<<MyMarks<<endl;
}
(i) 99
(ii) 94
(iii) 96
(iv) None of the above
Q 9. In the following C++ program what is the expected value of Myscore from Options (i) to (iv) given
below. Justify your answer.
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize();
int Score[] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2 + random(2)];
cout<<Myscore<<endl; }
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
23
Q3. What is the difference between call by reference and call by value
with respect to memory allocation ? Give a suitable example to
illustrate using C++ code.
[CBSE, 2014, Outside Delhi set -II]
[CBSE, 2010]
Q4. What is the difference between actual and formal parameter ? Give a suitable example to illustrate using
a C++ code.
[CBSE, 2014, Delhi]
Q5. What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to
illustrate both.
[CBSE, 2011]
Q6. Differentiate between members, which are present within the private visibility mode with those which
are present within the public visibility modes.
[CBSE, 2011]
Q7. What is the purpose of using a typedef command in C++. Explain with suitable example.
[CBSE, 2008]
Q8. Differentiate between private and public visibility modes in context of Object Oriented Programming
giving a suitable example illustrating each.
[CBSE, 2008]
Q9. Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of each in C++.
[CBSE, 2007]
Q 10. Illustrate the use of inline function in C++ with the help of an example.
[CBSE, 2006, SET-II]
Q. 11. Illustrate the use of #define in C++ to define a macro.
[CBSE, 2006, SET-I]
Q12. What are Nested Structures? Give an example.
[CBSE, 2006, SET-I]
CHAPTER -04
CLASSES AND OBJECTS (04 MARKS EACH)
Q 1.Write the definition of a class Photo in C++ with following description:
[CBSE, 2015, Outside Delhi]
24
Private Members
Pno
//Data member for Photo Number (an integer)
Category
//Data member for Photo Category (a string)
Exhibit
//Data member for Exhibition Gallery (a string)
FixExhibit //A member function to assign
//Exhibition Gallery as per Category
//as shown in the following table
Category
Exhibit
Antique
Zaveri
Modern
Johnsen
Classic
Terenida
Public Members
Register()
ViewAll()
Location
Classic
Amina
Modern
Jim Plaq
Antique
Ustad Khan
Public Members
Enter()
SeeAll()
Description
Score
qualified
char(30)
integer
char
PerKM
A
B
C
20
18
15
A function RegisterCab() to allow administrator to enter the values for CNo and CType. Also, this
function should call CityCharges() to assign PerKM Charges.
A function Display() to allow user to enter the value of Distance and display CNo, CType, PerKM,
PerKM*Distance (as Amount) on screen.
Q 5. Define a class Tourist in C++ with the following specification.
[ CBSE 2013]
Data Members :
Carno
- To store Bus No
Origin - To store Place Name
Destination - To store Place Name
Type - To store Car Type such as E for Economy
26
Member Functions :
Charge
E
16* Distance
A
22 * Distance
L
30 * Distance
A function Enter ( ) to allow the user to enter the values of Carno, Origin, Destination, Type and
Distance. Also, this function should call CalcCharge ( ) to calculate Fare.
A function Show ( ) to display the content of all the data members on screen.
Offer is 0
Offer is 5
Offer is 10
27
Public Members
A function GetStock() to allow user to enter values for Code, Iname, Price, Qty and call function
GetOffer() to calculate the offer
A function ShowItem() to allow user to view the content of all the data members.
Q 8. Define a class Clothing in C++ with the following descriptions :
Private Members :
Code
of type string
Type
of type string
Size
of type integer
Material
of type string
Price
of type float
A function Calc_Price ( ) which calculates and assigns the value of Price as follows :
For the value of Material as COTTON :
TYPE
Price (Rs)
TROUSER
1500
SHIRT
1200
For Material other than COTTON the above mentioned Price gets reduced by 25%.
Public Members :
A constructor to assign initial value of Code, Type and Material with the words NOT ASSIGNED
and Size and Price with 0.
A function Enter ( ) to input the values of data members Code, Type, Size and Material and invoke
the Calc_Price ( ) function.
A function Show ( ) which displays the content of all the members for a Clothing.
For Kilometres
500
>=1000
300
200
< 500
For each Kid the above Fare will be 50% of the Fare mentioned in
the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and
Kilometres; and invoke the Assign Fare( ) function.
A function ShowTour( ) which displays the content of all the data members for a Tour.
Q 10. Define a class named ADMISSION in C++ with the following descriptions:
[CBSE, 2006]
Private members:
AD_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
CLASS Character
FEES Float
Public Members:
Function Read_Data ( ) to read an object of ADMISSION type
Function Display() to display the details of an object
Function Draw-Nos ( ) to choose 2 students randomly. And display the details. Use random function
to generate admission nos. to match with AD_NO.
29
Q 11. Define a class named HOUSING in C++ with the following descriptions:
[CBSE, 2006, SET-II]
Private members
REG_NO integer(Ranges 10 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
Function Read_Data( ) to read an object of HOUSING type
Function Display() to display the details of an object
Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array
of 10 objects of type HOUSING Use random function to generate the registration nos. to match with
REGNO from the array.
30