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


0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.