Saturday

Computer Science with C++ important question for class 12 - CBSE

 Question 31:

Find syntax error(s), if any, in the following program: (Assuming all desired header file(s) are already included)

typedef String [80] char; 
void main()
{
String S;
for (L=0; L<26; C++)
S[L] = L+65;
S[L]="\0": 
cout<<S<<endline :
} Delhi 2013C

Answer:

tvpedef char Strlnq[80] : 
void main ( )
{
String S;
for (int L= 0: L<26; L++)
S[L]=L+65;
S[L]="\0" ; 
cout<<S<<end l ;
}

Question 32:
Based on the following C++ code, find out the expected correct output(s) from the options (i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the variable Guess used in the code at the time when value of Turn is 3.

void main( )
{
 char Result[][10]={"GOLD",
 "SILVER”,"BRONZE"}: 
int Getit=9,Guess : 
for(int Turn=l;Turn<4;Turn++)
 {
 Guess=random(Turn); cout<<Getit-Guess<<Result [Guess]<<"*" ;
}
}
 (i) 9GOLD*9GOLD*8SILVER*
(ii) 9GOLD*7BRONZE*8GOLD*
(iii) 9GOLD*8SILVER*9GOLD*
(iv) 9GOLD*8SILVER*8GOLD*
 All India 2013

Answer:
Correct output is (i) 9G0LD*9G0LD*8SILVER*
Maximum value of Guess is 2
Minimum value of Guess is 0.

Question 33:
Based on the following C++ code, find out the expected correct output(s) from the options (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

void main()
 {
 char StatusC][10]={"EXCEL”,
 "GOOD"."OK"i;
 int Turn=10,Trick;
 for(int Count=1;Count<4;Count++)
{
 Trick=random(Count); 
cout<<Turn-Trick<<Status
 [T ri ck]«"#" ;
}
}

(i)   10EXCEL# 10EXCEL#80K#
(ii)  10EXCEL#80K#9GOOD#
(iii) 10EXCEL#9GOOD# 10EXCEL#
(iv) 10EXCEL# 10GOQD#80K# Delhi 2013
Answer:
Correct output is (iii) 10EXCEL#9GOOD#10EXCEL#
Minimum value of Trick is 0
Maximum value of Trick is 2

Question 34:
Observe the following program and find out, which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Turn?

#i nclude<iostream.h> 
#include<stdlib.h> 
void main()
 (
 randomize(); 
int Game[]={10.16},P; 
int Turn=random(2)+5; 
for(int T=0; T<2; T++)
 { 
 P=random(2) ;
 cout<<Game[P]+Turn<<"#" ;
}
}

(i) 15#22#      (ii) 22#16#
(iii) 16#21#    (iv) 2I#22# Delhi 2012

Answer:
(i), (iii) and (iv) can never be the output.
Minimum value of Turn =5
Maximum value of Turn =6

Question 35:
Observe the following program and find out which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Chance?

#i nclude<iostream.h>
 #include<stdlib.h> 
void main()
 {
 randomze( ) ; 
int Arr[]={9,6},N; 
int Chance=random(2)+10; 
for(int CO;C<2;C++)
 {
 N=random(2);
 cout<<Arr[N]+Chance<<"#" ;
}
}

(i) 9#6#
(ii) 19#17#
(iii) 19#16#
(iv) 20# 16# All India 2012
Answer:
(i), (ii) and (iv) will not be expected from the program
Maximum value of Chance =11
Minimum value of Chance =10

Question 36:
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 '<<endl;
} Delhi 2011

Answer:

# include<iostream.h>
#include<strinq.h> 
typedef char Text[80]: 
void main()
{
Text T="Indian";
int Count=strlen(T) ; cout<<T<<"has"<<Count
<<"characters"<<end1 ;
}

Question 37:
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.

#include<iostream.h> 
typedef char[80] string; 
void main()
{
 string S="Peace"; 
int L=strlen (S) ; 
cout<<3<< 'has'<<L<<'characters'<<endl;
} Delhi 2011

Answer:

#include<iostream.h>
#include<string.h> 
tvpedef char strinq[80]: 
void main()
{
string S="Peace"; 
int L=strlen(S);
cout<<S<< " has "<<L<<characters" <<endl; 
}

Question 38:
Find the output of the following program;

#include<iostream.h> 
void SwitchOver(int AC], int N.intSplit)
{
for ( int K=0 ; K<N ; K++ 
if(K<Spl it)
A[K]+=K; 
else
A[K]*=K;
}
void Display(int A[],int N)
{
for (int KO ; K<N ; K++)
(K%2=0)?cout<<A[K]<<"%" :cout <<A[K]<<endl ;
}
void main()
{
int H[]={30.40.50,20,10,5); 
Switch0ver(H,6,3);
Display (H,6);
} All India 2011

Answer:
Output

30%41 
52%60 
40%25

Question 39:
Find the output of the following program

#includeCiostream.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
i f (Text[K]—"E"| |Text[K]=="e" ) Text[KJO; 
else
if(K%2= =0)
Text[K]=toupper(Text[K]) ; 
else
Text[K]=Text[K-1];
}
}
void main()
{
char 0ldText[]="p0wERALone"; 
changeIt(0ldText,); cout<<"New Text: "<<01dText<<endl ;
} Delhi 2010

Answer:
Output

New Text :PPW%RRllN%

Question 40:
Find the output of the following program:

#include<iostream. h>
#include<ctype.h>
void MyCodetchar 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(Msq[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" ; 
MyCodetMyText, "@"); 
cout<<"NEW TEXT: "<<MyText<<endl;
) All India 2010

Answer:
Output

NEW TEXT:@@e@ccddIIe

Thursday

Important Question - CS with C++ - Class 12- Part 3

 Question 21:

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 VAL. All India 2015
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()
{
randomizef);
int VAL;
VAL=random(3) + 2;
char GUESSC] =”ABCDEFGHIJK”;
for(int 1=1; K=VAL; I++)
{
for(int J=VAL; J<=7; J-F-F)
cout<<GUESS[J] ;
cout<<endl ;

(i) BCDEFGH    (ii) CDEFGH    (iii) EFGH    (iv) FGHI
BCDEFGH         CDEFGH             EFGH           FGHI
EFGH           FGHI
EFGH           FGHI

Answer:
The possible outputs are (ii) and (iii).
Minimum value of VAL = 2
Maximum value of VAL = 4

Question 22:
Observe the following C +4- 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 float PIE = 3.1416; 
void main( )
{
float Radius =(3.5,6.2,8.6,9.11.Area; 
int N;
cout<<'Enter N (Less than 5)?'; cin>>N;
for (0=0 ; C<N ; C++ )
{
Area=PIE*Radius[C] *Radius CC]; 
cout<<Area<<endline ;
}
} All India 2015c

Answer:
Const float PIE = 3.1416;

void main()
(
float Radius[] = {3.5, 6.2, 8.6, 9.1}, 
Area;
int N;
cout <<"Enter N (Less than 5)?": 
cin>>N ;
for (int C=O: C<N; C++)
{
Area = PIE* Radius[C]* Radi us[C] ; 
cout<<Area<<end!;
}
}

Question 23:
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 VALUE. All Indio 2015C
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 VALUE;
VALUE=random(2) + 2;
char Y0URTEXT[]
=("ONE”,"TWO","SIX”,"TEN"} ;
for(int Y=0;Y<VALUE; Y++)
COUt<<Y0URTEXT[Y] ;
cout<<"END"<<endl ;
cout<<endl;
}

(i)                             (ii)                               (iii)                                 (iv)
ONETWOEND  ONEENDTWO   ONETWOSIXEND      ONETWOSIXEND

Answer:

The possible outputs are (i) and (iv)
Minimum value of VALUE = 2
Maximum value of VALUE = 3

Question 24:
Deepa has just started working as a programmer in STAR SOFTWARE company. In the company, she has got her first assignment to be done using a C++ function to find the smallest number out of a given set of numbers stored in a one-dimensional array. But she has committed some logical mistakes while writing the code and is not getting the desired result. Rewrite the correct code underlining the corrections done. Do not add any additional statements in the corrected code.
All India 2014C

int find (int a[], int n)
{
int s=a[0]; 
for(int x=l; x<n; x++) 
if(a [x]>s) 
a[x]=s; 
return (s);
}

Answer:
The correct code is

int find (int a[], int n)
{
int S=a[0]; 
for (int x=l; x<n; x++) 
if (a [x]<s)
s=a [x] ; 
return(s);
}

Question 25:
Find output of the following program segment: All India 2014C

#include<iostream.h>
 #include<ctyupe.h>
 void Mycode (char Msg [ ], Lehar CH)
{
 {for(int cnt=0; Msg[cnt3] !
 ="\0";cnt++)
 { if (Msg [cnt]>='B'&& Msg[cnt]<='G’)
 Msg [cnt]=tolower(Msg[cnt);
 else
 if(Msg[cnt]= =’N'  ∪Msg[cnt]=
 = 'n' ∪Msg[cnt]= =' ' )
 Msg[cnt]=CH;
 else
 if(cnt%2= =0)
 Msg[cnt]=toupper(Msg[cnt]);
 else
 Msg[cnt]=Msg[cnt-l];
} }
 void main()
 { 
Char MyText[]="Input Raw";
 Mycode (MyText, '@'
 cout<<"NEW TEXT : "<<MyText<<endl
}

Answer:
Output

NEW TEXT : I@PPT@RRW

Question 26:
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:
Assume that all the required header file are already included, which are essential to run this code.
The correction made by you do not change the logic of the program.

typedef char[50] STRING; 
void main()
City STRING;
gets(City);
cout<<City[0]<<'\t,<<City[2]; 
cout<<City<<endline;
} Delhi 2014

Answer:
The correct code is

typedef char STRING[50] : //Error 1 
void main()
{
STRING City;    //Error 2
gets(City);
cout<<City[o]<<"\t"<<City[2] ; //Error 3
cout<<City<<endl:    //Error 4
}

Question 27:
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:

void main( )
{
 int Guess[4]={200, 150, 20, 250}; 
int Start=random(2)+2; 
for(int C=Start; C<4; C++) 
cout<<Guess[C]<<"#" ;
}
(i)   200# 150#
(ii)  50#20#
(iii) 150#20#250#
(iv) 20#250# Delhi 2014

Answer:
Correct option is (iv) 20 # 250#
Maximum value of variable Start= 3
Minimum value of variable Start = 2

Question 28:
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. All India 2014

or

What is the difference between call by value and call by reference? Also, give a suitable C++ code to illustrate both.
All India 2010; Delhi 2009
Answer:
Differences between call by value and call by reference are as follows:
Important Questions for Class 12 Computer Science (C++) - C++ Revision Tour-2

e.g.
Following example illustrates the concept of call by value:
#imclude<iostream.h>
#include<conio.h> 
void swap(int x,int y)
int temp = x; 
x = y; 
y = temp;
cout<<"After swapping\n"; 
cout<<"Inside swap”<<endl ;
cout<<"x : "<<x<<endl; 
cout<<"y : "<<y<<endl ;
}
void main()
{
int x,y;
cout<<"Enter two numbers\n"
 cin>>x>>y; 
swap(x.y);
cout<<”After swapping\n"; 
cout<<"Inside main"<<endl;
 cout<<"x : "<<x<<endl ; 
cout<<"y : "<<y; 
getch( ) ;
}

The following example illustrates the concept of call by reference:

#include<iostream.h>
#include<conio.h> 
void swap(int &x,int &y)
(
int temp = x;
 x = y; 
y = temp;
couK<<'After swapping\n"; 
cout<<"Inside swap"<<endl; 
cout<<"x : "<<x<<endl ; 
cout<<"y : "<<y<<endl ;
}
void main()
{
int x,y;
cout<<"Enter two numbers\n"; 
cin>>x>>y ; 
swap(x,y);
cout<<"After swapping\n” ; 
cout<<"Inside main"<<endl; 
cout<<"x : "<<x<<endl ; 
cout<<"y : "<<y; 
getch( ) ;
}

Question 29:
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. All India 2014
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;

Answer:
The corrected code is given below:

tvpedef char STR[80] ://Error 1 
void main()
{
STR Txt; //Error 2
gets(Txt);
cout<<Txt[0]<<"\t"<<Txt[2]; //Error 3
cout<<Txt<<endl:    //Error 4

Question 30:
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:

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 All India 2014
Answer:
Correct output for the given code would be option
(iii) 100#50#200#
Maximum value of Taker = 3
Minimum value of Taker = 2


Friday

Important Question Answers - Class 12 - CS with C++-CBSE

 Question 11:

Which C++ header file(s) will be essentially required to be included to run/execute the following C++ code?

void main() 
{
char Name[20]; 
cin>>Name; 
toupper (Name[0]); 
cout<<Name<<endl;
} Delhi 2011C

Answer:

<iostream.h>→C0ut,cin 
<ctype.h>→ toupper()

Question 12:
Which C++header file(s) will be essentially required to be included to run/execute the following C++ code?

void main()
{
int Eno=123, char EName[]
="Rehan Swarop"; 
cout<<setw(5)<<Eno<setw(25)
<<EName<<endl;
) Delhi 2010

Answer:

<iomanip.h> → setw() 
Ciostream.h> → Cout

Question 13:
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(10X<Rno<<setw(20)
<<Name<<endl;
} All India 2010

Answer:

<iomanip.h>→setw()
<iostream.h>→cout

Question 14:
Find and write the output of the following C++ program code:
NOTE Assume all required header files are already included in the program.

# define Diff(N1,N2)
((N1>N2)?N1-N2:N2-N1)
void main ()
{
int A,B,NUM[] = {10,23,14,54,321 ; 
for(int CNT=4; CNT>0; CNT--)
{
A=NUM[CNT] ;
B=NUM[CNT-1] ; 
cout<<Diff(A,B)<<'#' :
}
} All India 2017

Answer:

Output
22#40#9#13#

Question 15:
Look at the following C++ code and find the possible outputs(s) from the options (i) to (iv) following it. Also, .write the maximum values that can be assigned to each of the variables N and M.
NOTE

• Assume all the required header files are already being included in the code.
• The function random(n) generates an integer between 0 and n-1.

void main()
 {
 randomize() ;
 int N=random(3), M=random(4);
 int DOCK[3][3]
 = {{1,2,3},{2,3,4},1{3,4,5,}}:
 for (int R=0; R<N; R++)
 {
 for(int C=0; C<M; C++)
 cout<<DOCK[R][C]<<" cout<<endl ;
(i)(ii)
1       2      31       2      3
2      3      42      3      4
3     4       5
(iii)(iv)
1       21          2
2      32         3
3         4

Answer:
Possible Outputs: (ii) and (iii)
Maximum value of N is 2.
Minimum value of N is 0.
Maximum value of M is 3.
Minimum value of M is 0.

Question 16:
Find and write the output of the following C++ program code: All India 2016
NOTE Assume all required header files are already included in the program.

typedef char TEXT[80]; 
void JumbleUp(TEXT T)
{
int L=strlen(T);
for(int C=0; C<L-1; C+=2)
{
char CT=T[C]:
T[C]=T[C+1] :
T[C+1]=CT;
}
for(C=1: C<L; C+=2)
i f(T [C]>= ’ M ' && T[C]<='U' )
T[C]='@' :
}
void main()
{
TEXT Str="HARMONIOUS";
JumbleUp(Str) ;
cout<<Str<<endl :
}

Answer:

The output will be
AHM@N@OIS@

Question 17:
Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can he assigned to the variable PICKER. All India 2016
NOTE Assume all required header files are already being included in the code. The function random(n) generates an integer between 0 and n -1.

void main()
 {
 int PICKER:
 PICKER=1+random(3) ;
 char COLOURC][5]={"BLUE","PINK”, "GREEN”,"RED"):
 for(int I=0;I<=PICKER; I++)
 {
 for(int J=0;J<=I; J++)
 cout<<COLOUR[J] :
 cout<<endl:
 }
 }
(i)(ii)(iii)(iv)
PINKBLUEGREENBLUE
PINKGREENBLUEPINKGREENREDBLUEPINK
PINKGREENBLUEPINKBLUEPINK
RED

GREEN

BLUEPINK

GREENRED

GREEN

Answer:
The possible outputs are (ii) and (iv)
Minimum value of PICKER = 1
Maximum value of PICKER = 3

Question 18:
Find and write the output of the following C++ program code: Delhi 2016 NOTE Assume all required header files are already included in the program,

typedef char STRING [80];
void MIXITNOW(STRING S)
{
int Size=strlen(S) :
for(int I=0; I<Size-1; I+=2)
Char WS = S[I] ;
S[I] = S[I+1]:
S[I+1]=WS;
}
for( I=1 ; I<Size; I+=2)
if(S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void main( )
{
STRING Word = “CRACKAJACK”;
MIXITNOW(Word) ;
cout<<Word<<endl;

Answer:

Output
RCCAAKAJKC

Question 19:
Look at the following C++ code and find 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 CHANGER. Delhi 2016
NOTE Assume all the required header files are already being included in the code. The function random(n) generates an integer between 0 and n -1.

void main()
 {
 randomize();
 int CHANGER;
 CHANGER = random(3);
 char CITY[ ][25] = {"DELHI", "MUMBAI","KOLKATA","CHENNAI"};
 for(int 1=0; I<=CHANGER; I++)
 {
 forlint J=0; J<=I; J++)
 cout<<CITY[J] ;
 cout<< endl;
Important Questions for Class 12 Computer Science (C++) - C++ Revision Tour-1
Answer:

The possible outputs are (i) and (ii)
Minimum value of CHANGER = 0
Maximum value of CHANGER = 2

Question 20:
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. 
Delhi 2015
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 1=1; 1<=NUM; I++)
 for(int J=NUM; J<=7; J++) 
cout<<TEXT( J ) ;
cout<<endl ;
}
}

(i) FGHI       (ii) BCDEFG          (iii) EFGH       (iv) CDEFG
H                                                           H
FGHI              BCDEFG                  EFGH               CDEFG
H                                                           H
FGHI                                                EFGH
FGHI                                                EFGH

Answer:
The possible outputs are (iii) and (iv)
Minimum value of Num = 2
Maximum value of NUM = 4