· web viewf) observe the following program game.cpp carefully, if the value of num entered by...

72
MODEL PAPER 1 a) Define the term variable. Give example. How is it different from a constant? b) Name the header files required for the following 1) pow() 2) clrscr() c) Rewrite the following program after removing the syntactical error(s), if any. 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]; } d) What will be the output of the following code: #include <iostream.h > struct emp { char name[25]; int age; int code; }; void main() { emp e1={“Pranav”,28,12}; emp e2; e2=e1; e2.code=43; cout<<” \n Name: “<<e2.name;

Upload: vankiet

Post on 09-Mar-2018

215 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

MODEL PAPER 1a) Define the term variable. Give example. How is it different from a constant?

b) Name the header files required for the following             1) pow()                    2) clrscr()                 

c) Rewrite the following program after removing the syntactical error(s), if any. 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];} 

d) What will be the output of the following code:  #include <iostream.h >struct emp{char name[25];int age;int code;};void main(){emp e1={“Pranav”,28,12};emp e2;e2=e1;e2.code=43;cout<<”  \n Name: “<<e2.name;cout<<” \n Age: “<<e2.age;cout<<” \n Code: “<<e2.code;cout<<” \n Code: “<<e1.code;}

 

e) Give the output of the following program segment:

 

Page 2: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

char *NAME="IntRAneT";for(int x=0; x < strlen(NAME); x++)            if(islower(NAME[x]) )                        NAME [ x] = toupper ( NAME [x]);else            if(isupper(NAME [x] ) )            if( x%2==0)                        NAME [x] = tolower ( NAME [x] );else                        NAME [x] = NAME [ x - 1 ];            puts(NAME);   

f) 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                                          [2+1+2+3+2+2=12] Marks:12

Answer:

a) A variable represent named storage locations whose values can be manipulated during program run. In C++ a variable is declared as follows -                                        int a;                                  float num;

 A constant never changes its value during the execution of the program whereas the value of a variable varies.

 

b)  1) math.h 2) conio.h   

Page 3: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

 

c) Correct code is: 

#include < iostream.h>const int Size = 5;void main(){

int Array[Size] = {50,40,30,20,10};for( int Ctr=0; Ctr< Size; Ctr++)

cout<< Array[Ctr];} 

d) Output:           Name : Pranav          Age   : 28          Code : 43          Code : 12

e) Output is: iNTTaNEE 

f) Correct Option is (ii) 34 . The random function returns the value between 0 to N-1 so,

 Min Value = 2+0=2

Max Value =2+1=3

MODEL PAPER 2

a) What is an Identifier? How is it different from a Keyword?           

b) Name the header files required for the following                                       1) clrscr()                  2) isalnum()            

c) 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 > = 0 ; Loc - -)

cout>>Numbers [Loc];} 

Page 4: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

d) What will be the output of the following code:                              

 #include<iostream.h>int area(int side){return (side*side)}float area(int length,int breadth){return(length*breadth)}main(){cout<<area(6);cout<<area(10,10);cout<<area(6,area(5)); 

e) Give the output of the following program segment (Assuming all required header files are included in the program):                                                                

 

char *NAME="a ProFiLe";for(int x=0; x< strlen(NAME); x++)

            if(islower(NAME[x]))                        NAME[x]=toupper(NAME[x]);            else                        if(isupper(NAME[x]))                                    if(x%2!=0)                                                NAME[x]=tolower(NAME[x-1]);                                    else                                                NAME[x]–-;                        cout<< NAME<< endl;

 f) Observe the following program GAME.CPP carefully, if the value of Num entered

by the user is 14, choose the correct possible output(s) from the given options from (i) to (iv).

#include < stdlib.h >    #include< iostream.h>void main()

{            randomize ();            int Num, Rndnum;            cin>> Num;            Rndnum=random (Num)+7;

Page 5: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

            for(int N=1; N< =Rndnum; N++)                        cout<< N<< ””;}Output Option:(i) 1 2 3(ii) 1 2 3 4 5 6 7 8 9 10 11(iii) 1 2 3 4 5(iv) 1 2 3 4                                                                                                                       

[2+1+2+3+2+2=12]

Marks:12

Answer: a) An Identifier a name given to variable, constant, class etc, It is basically a long

sequence of letters and digits. Its first letter should be a character or underscore (_). The identifiers must have a valid type. It’s lower case and upper case are different from each other.A keyword is also an identifier but the keywords are the reserved words in C++ and they have a predefined meaning to be interpreted by the compiler.

 b)      1) conio.h               2) ctype.h                c) # include < iostream.h>const int Max = 10;void main ( ){

int Numbers [Max] = { 20, 50,10, 30,40 } ;for (int Loc= Max-1 ; Loc > = 0 ; Loc - -)

cout<< Numbers [Loc];} d) Output:          36100150

 e) A OROoIiE f) Correct output option is: (ii)

Hide Answer

 

Q2

MODEL PAPER 3

a) Why prototyping is necessary in C++ program?

b) Name the header files required for the following functions -                

Page 6: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

            1) gets()        2) clrscr()       

c) Considering the given code snippet, rewrite the correct one -                                  void main()

{                        struct room                        {                                    char room_type[25];                                    int room_no;                                    int rate=250;                        }                        ROOM;                                    gets(room_type);                                    gets(room_no);            } d) Find the output of the following program -                                                     #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 ;

} e) What will be the output of the following code:                     (2)  #include <iostream.h >int ABC(int a){

Page 7: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

return (a+a) ;} float ABC(int x,int y){return(x*y) ;}main(){cout<<ABC(1);cout<<ABC(6,9);cout<<ABC(4,ABC(5));} 

(f)In the following program, if the value of N given by the user is 20, what maximum and minimum values the program could possibly display?                                         

 #include < iostream.h>#include < stdlib.h>void main(){

  int N,Guessnum;s  randomize();  cin>>N;  Guessnum=random(N-10)+10;  cout<< Guessnum<< endl;

}                                                                                                                                [2+1+2+3+2+2=12]

Marks:12

Answer: a)

C++ makes it necessary to declare functions by providing their prototypes so that the type and requirements (in terms of number and type of its arguments) must be identified before first call is made to it.

Function declaration enables a compiler to check whether the function is used correctly or not i.e. the number and types of arguments are compared and if not matched then it reports an error.

 b)      1) stdio.h                2) conio.h                c) The errors are underlined as follows:           void main(){                struct room                {                   char room_type[25];                    int room_no;

Page 8: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                    int rate;                }ROOM;                        gets(ROOM.room_type);                       cin>>ROOM.room_no;            }d)  1015202520

101520

Number = 30

 e)

          25440 f) Maximum Value: 19             Minimum Value: 10      MODEL PAPER 4

a) What do you mean by global variables and local variables?                                 

b) Name the header files required for the following                                                  1) gets()                    2) abs()

c) Give the output of the following code:

#include< iostream.h>                                                                               #include < conio.h>void main(){

clrscr();int sum(int(*)(int),int);int square(int);int cube(int);cout<< sum(square,4)<< endl;cout<< sum(cube,4)<< endl;getch();

}int sum(int(*ptr)(int k),int n){

int s=0;            for(int i=1;i< =n;i++)               {                   s+=(*ptr)(i);               }           return s;}int square(int k){

 int sq;sq=k*k;

Page 9: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

return k*k;}int cube(int k){

return k*k*k;}  d) Consider the code:                                             class Apple{int a;public:void seta(int b){a=b;}};---------------------------- 

i) Which of the variables ‘a’ and ‘b’ is global variable?ii) What does a=b signifies? e) What will be the output of the following code:           #include<iostream.h>int vol(int s){return(s*s*s);}int vol(int a, int b, int c){return (a*b*c);}main(){cout<<vol(4);cout<<vol(2,4,2);cout<<vol(4,5,vol(2));} 

f) In the following program, if the value of N given by the user is 25, what maximum and minimum values the program could possibly display?                                                                                                                                                                     #include < iostream.h>#include < stdlib.h>void main()

Page 10: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

{            int N,Guessno;

randomize();cin>>N;Guessno=random(N)-10;cout<< Guessno<< endl;

}

[2+1+2+3+2+2 = 12]

Marks:12

Answer: a)              Global variable is one, which is declared outside a function. It is accessible

throughout the program.Local variable is one, which is local to the block of the function would be accessible only within the block of the function and not outside the function.

 b)      1) stdio.h                2) math.h               

c)       The output is       30     100.

d)       i) Variable ‘a’ is global variable.          ii) a=b means the assignment of the value of a local variable to a global variable. e) Output:         6416160 f) Maximum Value: 14                   Minimum Value: -10   

Hide Answer

MODEL PAPER 5

a) What do you mean by global variables and local variables?                                 

b) Name the header files required for the following                                                  1) gets()                    2) abs()

c) Give the output of the following code:

#include< iostream.h>                                                                               #include < conio.h>void main(){

clrscr();int sum(int(*)(int),int);int square(int);

Page 11: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

int cube(int);cout<< sum(square,4)<< endl;cout<< sum(cube,4)<< endl;getch();

}int sum(int(*ptr)(int k),int n){

int s=0;            for(int i=1;i< =n;i++)               {                   s+=(*ptr)(i);               }           return s;}int square(int k){

 int sq;sq=k*k;return k*k;

}int cube(int k){

return k*k*k;}  d) Consider the code:                                             class Apple{int a;public:void seta(int b){a=b;}};---------------------------- 

i) Which of the variables ‘a’ and ‘b’ is global variable?ii) What does a=b signifies? e) What will be the output of the following code:           #include<iostream.h>int vol(int s){return(s*s*s);}

Page 12: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

int vol(int a, int b, int c){return (a*b*c);}main(){cout<<vol(4);cout<<vol(2,4,2);cout<<vol(4,5,vol(2));} 

f) In the following program, if the value of N given by the user is 25, what maximum and minimum values the program could possibly display?                                                                                                                                                                     #include < iostream.h>#include < stdlib.h>void main(){            int N,Guessno;

randomize();cin>>N;Guessno=random(N)-10;cout<< Guessno<< endl;

}

[2+1+2+3+2+2 = 12]

Marks:12

Answer: a)              Global variable is one, which is declared outside a function. It is accessible

throughout the program.Local variable is one, which is local to the block of the function would be accessible only within the block of the function and not outside the function.

 b)      1) stdio.h                2) math.h               

c)       The output is       30     100.

d)       i) Variable ‘a’ is global variable.          ii) a=b means the assignment of the value of a local variable to a global variable. e) Output:         6416160 f) Maximum Value: 14                   Minimum Value: -10   

Page 13: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

Hide Answer

2015 QUESTION PAPER

a) Find the correct identifiers out of the following, which can be used for a naming Variable, Constants or Functions in a C++ program:

For, while, INT, NeW, delete, lsiName, Add+Subract, name1

(b) Observe the following program very carefully and write the names of those header files(s), which are essentially needed to compile and execute the following program successfully:

 

(c) 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 MaxSpeed=60.5;void main(){int MySpeedchar Alert=’N’;cin>>MySpeed;if MySpeed>MaxSpeedAlert=’Y’;cout << Alert<< endline;} 

(d) Write the output of the following C++ program code:Note: Assume all required header files are already being included in the program.

               void Location(int &X, int Y=4){Y+=2;

Page 14: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

X+=Y;}void main(){int PX=10, PY=2;

Location(PY);cout << PX<< ”,”<< PY<< endl;Location(PX,PY);cout << PX << ”,” << PY << endl;

}(e) Write the output of the following C++ program code:

Note: Assume all required header files are already being included 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; }

Page 15: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

};void main(){Eval E;E.Sink(3);E.show();E.Float(7);E.Show();E.Sink(2);E.Show();} 

(f) 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.

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 VAL;       VAL= random(3) +2;       char GUESS[]=”ABCDEFGHIJK”;       for( int I=1; I<=VAL; I++)       {       for(int J=VAL; J<=7;J++)              cout << GUESS[J];       cout << endl;}

         }

Page 16: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

 

                                                                                                               [2+1+2+2+3+2=12] 

Answer

(a) For, INT, NeW, lsiName, name1 are the correct identifiers of C++.(b) The header files required are-

ctype.h stdio.h

(c)#include< iostream.h >#define float MaxSpeed=60.5;void main(){int MySpeed;char Alert='N';int MaxSpeed; 

cin>>MySpeed;cin>>MaxSpeed; 

if( MySpeed>MaxSpeed)Alert='Y';cout << Alert << endl;}

(d) Output-10,820,8 

(e) Output-B#0I#1G#1

Page 17: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(f) Correct output of the code is (ii) and (iii)2014 QUESTIOMN PAPER

a) Find the correct identifiers out of the following, which can be used for a naming Variable, Constants or Functions in a C++ program:

For, while, INT, NeW, delete, lsiName, Add+Subract, name1

(b) Observe the following program very carefully and write the names of those header files(s), which are essentially needed to compile and execute the following program successfully:

 

(c) 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 MaxSpeed=60.5;void main(){int MySpeedchar Alert=’N’;cin>>MySpeed;if MySpeed>MaxSpeedAlert=’Y’;cout << Alert<< endline;} 

(d) Write the output of the following C++ program code:Note: Assume all required header files are already being included in the program.

               void Location(int &X, int Y=4){Y+=2;

Page 18: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

X+=Y;}void main(){int PX=10, PY=2;

Location(PY);cout << PX<< ”,”<< PY<< endl;Location(PX,PY);cout << PX << ”,” << PY << endl;

}(e) Write the output of the following C++ program code:

Note: Assume all required header files are already being included 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; }

Page 19: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

};void main(){Eval E;E.Sink(3);E.show();E.Float(7);E.Show();E.Sink(2);E.Show();} 

(f) 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.

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 VAL;       VAL= random(3) +2;       char GUESS[]=”ABCDEFGHIJK”;       for( int I=1; I<=VAL; I++)       {       for(int J=VAL; J<=7;J++)              cout << GUESS[J];       cout << endl;}

         }

Page 20: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

 

                                                                                                               [2+1+2+2+3+2=12] 

Answer

(a) For, INT, NeW, lsiName, name1 are the correct identifiers of C++.(b) The header files required are-

ctype.h stdio.h

(c)#include< iostream.h >#define float MaxSpeed=60.5;void main(){int MySpeed;char Alert='N';int MaxSpeed; 

cin>>MySpeed;cin>>MaxSpeed; 

if( MySpeed>MaxSpeed)Alert='Y';cout << Alert << endl;}

(d) Output-10,820,8 

(e) Output-B#0I#1G#1

Page 21: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(f) Correct output of the code is (ii) and (iii)QUESTION PAPER 2013

(a) What is the benefit of using default parameter/argument in a function? Give a suitable example to illustrate it by using C++ code.

(b) 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()

  {

          float Area, Side;

          cin >> Area;

          Side=sqrt(Area);

cout << ”One Side of the Square: ”<< Side << endl;

}

 

(c) Observe the following C++ code carefully and rewrite the same after removing all the

syntax error(s) present in the code. Ensure that you underline each correction in the code.

Important Note:

-     All the desired header files are already included, which are required

to run the code.

 

-     Correction should not change the logic of the program.

 

#define Change(A,B) 2*A+B;

void main()

{

          Float X,Y,F;

          cin >> X >> Y;

          F=Change[X,Y];

          count << ” Result : ”<< F<< endline;

}

Page 22: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(d) Observe the following C++ code carefully and obtain the output, which will appear on

the screen after the execution of it.

Important Note:

-     All the desired header files that are required to run the code are

already included in 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;

}

(e) Observe the following C++ code carefully and obtain the output, which will appear on

the screen after the execution of it.

#include< iostream.h >

class Mausam

{

       int City, Temp, Humidity;

public:

       Mausam(int C=1)

       {

       City=C;

       Temp=10;

       Humidity=63;

}

void Sun(int T)

{

Page 23: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

       Temp+=T;

}

void Rain(int H)

{

       Humidity+=H;

}

void CheckOut()

{

       cout << ”City”<< ”:”<< Temp<< ”&” << Humidity<< ”%” << endl;

}

};

 

void main()

{

       Mausam M, N(2);

       M.Sun(5);

       M.CheckOut();

       N.Rain(10);

       N.Sun(2);

       N.CheckOut();

       M.Rain(15);

       M.CheckOut();

}

 

(f) 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 the value of the Turn is 3.

void main()

{

char Result[ ][10] = {“GOLD”, “SILVER”, “BRONZE”};

int Getit=9, Guess;

 

Page 24: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

for(int Turn=1; Turn<4; Turn++)

{

   Guess=random(Turn);

   cout << Getit-Guess << Result[Guess]<< ”*”;

}

   }

                          [2+1+2+2+3+2 = 12]

Marks:12

Answer:

(a) The passing default arguments are a good choice when the user

wants to override or not the value passed in the function call.

For example,

       // function containing default arguments

       void sum(int a=10, int b=20)

{

cout << a+b;

}

void main()

{

       :

       sum(3,4);    //call 1

       sum(5); //call 2

       sum();         //call 3

}

As shown in the example, the call 1 method will override the default

values passed to the function; hence it will display the sum as 7.

Page 25: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

The second way of calling (call 2) will use the default value passed to

the second variable b and override the value of a; hence it will display

the sum as 25.

In the third call, we want to use the default values of both the functions,

therefore if we have not passed any value while calling the sum

function; then the call 3 will display the sum as 30.

(b) The header files required are:

       • iostream.h

       • math.h

(c)

#define Change(A,B) 2*A+B;

void main()

{

          float X,Y,F;

          cin >> X >> Y;

          F=Change(X,Y);

          cout << " Result : "<< F<< endl;

}

(d)

Page 26: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

       Output:

       1AJANTA

       5JANTA

(e)

 

   Output:

        City:15&63%

        City:12&73%

        City:15&78%

(f) The answer can be (i) and (iii).

QUESTION PAPER 2012

a) Give the difference between the type casting and automatic type conversion. Also, give a suitable C++ code to illustrate both. b) Which C++ header file(s) are essentially required to be included to run/execute the following C++ source code(Note: Do not include any header file, which is/are not required):

void main()

{

char TEXT[] = “Something”;

cout<< ”Remaining SMS Chars:”<< 160-strlen(TEXT)<< endl;

}

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

Page 27: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

    #include< iostream.h >

    Class item

{

long IId, Qty;

public:

void Purchase

{

cin>> IId>> Qty;

}

void Sale()

{

cout<< setw(5)<< IID<< ”Old:”<< Qty<< endl;

cout<< ”New:”<< --Qty<< endl;

}

  };

void main()

{

Item I;

Purchase();

I.Sale();

I.Sale()

}

d) Find out the output of the following program:

#include< iostream.h >

class METRO

{

int Mno,TripNo,PassengerCount;

Page 28: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

public:

METRO(int Tmno = 1)

{

Mno = Tmno;

TripNo=0;

PassengerCount=0;

}

void Trip(int PC =20)

{

TripNo++;

PassengerCount+=PC;

}

void StatusShow()

{

cout<< Mno<<  ”:”<< TripNo<< ”:”<<  PassengerCount<< endl;

}

};

void main()

{

METRO M(5),T;

M.TRIP();

T.TRIP(50);

M.StatusShow();

M.TRIP(30);

T.StatusShow();

M.StatusShow();

}

Page 29: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

e) Find the output of the following program:

              #include< iostream.h >

              #include< ctype.h >

              typedef char Str80[80];

              void main()

              {

           char  *Notes;

           Str80 Str=”vR2GooD”;

           int L=6;

           Notes=Str;

              while (L>=3)

{

Str[L]=(isupper(Str[L])?tolower(Str[L]): toupper(Str[L]));

cout<< Notes<< endl;

L--;

Notes++;

}

}

 

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

      

#include< iostream.h >

#include< stdlib.h >

void main()

{

Page 30: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

randomize();

int Arr[]={9,6},N;

int Chance=random(2)+10;

for(int C=0;C<2;C++)

{

N=random(2);

cout<< Arr[N]+Chance<< ”#”;

}

}

(i) 9# 6#(ii) 19#17#(iii) 19#16#(iv) 20#16#

[2+1+2+3+2+2 = 12]

Marks:12

Answer:

(a)  

Type Casting Automatic Type ConversionType casting refers to the data type conversions from one type to another. Type casting is done explicitly by the programmer according to the requirement.

The type conversion is done automatically by the compiler without user interference. In such conversion the variable of lower data type is automatically converted into the data types of variable having higher data type.

For example:  int a;float b;a=12; b=5;

For example:  int a;float b;a=12; b=5;

Page 31: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

cout<<(int)a/b;  //displays 2, since result is converted to int type.

cout<<a/b;  // displays 2.4, since float has the higher data type

  

(b). #include< iostream.h >       #include< string.h >

 

(c)     # include< iostream.h>

           # include< iomanip.h> //header file for setw()         

          class Item   //  class should be in small letters          {                long IId, Qty;

public:                        l

        void Purchase() {cin>>IId>>Qty;}        void Sale()               {

cout<< setw(5)<< IId<< ”Old:”<< Qty<< endl;            cout<< ”New:”<< --Qty<< endl;

  }};void main(){       Item I;       I.Purchase();  // object name is missing       I.Sale();           I.Sale();     //semi-colon is missing

Page 32: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(d) OUTPUT:

               5:1:20               1:1:50               5:2:50

 

(e) Output:              vR2GooD

              R2GoOd

              2GOOd

gOOd

 

(f) Minimum value assigned to variable Chance is =10 Maximum value assigned to variable Chance is =11

  The answers (i), (ii) and (iv) are not expected as output.  QUESTION PAPER 2011

a) What is the difference between Type Casting and Automatic Type conversion? Also, give a suitable C++ code to illustrate both.                                                               b) 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 Attitude";   for(int I=0;Text[ I ] !='\0';I++)   if(Text[ I ] == ‘ ’)

Page 33: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

      cout<< endl;   else   {        CH = toupper(Text[ I ]);        cout<< CH;     }}  

c) 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 << S << 'has' << L << 'characters’ << endl;   }d) Find the output of the following program:                      #include< iostream.h >           void SwitchOver(int A[ ], int N, int Split)           {                  for (int K=0; K < N; K++)                       if(K < Split)

Page 34: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                           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);          }  

e) Find the output of the following program:             

           #include< iostream.h >           void main()           {               int *Queen, Moves[ ]={11,22,33,44};               Queen = Moves;

Page 35: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

               Moves[ 2 ] += 22;              cout << "Queen @" << *Queen << endl;              *Queen -= 11;               Queen += 2;               cout << "Now @" << *Queen << endl;               Queen ++;               cout << "Finally @" << *Queen << endl;               cout << "New Origin @” << Moves[0] << endl;          } f) 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 minimum and maximum values, which can be assigned to the variable MyNum.               

#include< iostream.h >#include< stdlib.h >void main(){    randomize();    int MyNum , Max=5;    MyNum = 20 + random (Max);    for (int N= MyNum; N<=25; N++)    cout << N << "*"; }    (i)  20*21*22*23*24*25(ii) 22*23*24*25*

Page 36: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(iii)23*24*           (iv)21*22*23                                 [ 2+1+2+3+2+2 = 12 ]Marks:12

Answer:

1 (a) 

Type casting Automatic Type 

1.Explicit conversion 1.Implicit conversion2. Converting an expression of a given type into another type is known as type-casting.

2.Value gets automatically converted to the specific type in which it is assigned.

3. Eg:int x=65; char c=(char) x; 

3.Eg: short x=6000;int y;y=x;

 

(b)  #include< iostream.h >     #include< ctype.h > 

(c)   #include< iostream.h >       #include< string.h >        typedef char string[ 80 ];

       void main()       {          string S="Peace";          int L=strlen(S);          cout << S << "has" << L << "characters" << endl;      }

Page 37: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(d)      30 % 41      52 % 60      40 % 25 

(e)        Queen @ 11        Now @ 55        Finally @ 44        New Origin @ 0 

(f)        ii) 22*23*24*25*       Minimum value = 20       Maximum value = 24

QUESTION PAPER 2010

a) What is the difference between call by value and call by reference? Also give a suitable C++ code to illustrate both.                                                                               (2)

b) Which C++ header files will be essentially required to be included to run/execute the following C++ code?                                                                                   (1)

void main ()

{

 int Rno=24; char Name [ ] = ” Amen Singhania ” ;

     cout << setw (10) << Rno << setw (20) << Name << endl ;

}

Page 38: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

c) Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each correction.   (2)

include < iostream.h >

class FLIGHT

{

long FlightCode;

char Description [ 25 ];

public

void AddInfo()

{

cin >> FightCode; gets(Description);

}

void ShowInfo ()

{

cout << FlightCode << ”:” << Description << endl;

}

} ;

void main()

{

FLIGHT F;

AddInfo.F (); ShowInfo.F ();

}

d) Find the output of the following program:         (3)

# include < iostream.h >

Struct THREE_D

{ int X,Y,Z ; } ;

void MoveIn (THREE_D &T, int Step=1)

{

Page 39: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

T.X+=Step;

T.Y-=Step;

T.Z+=Step;

}

void MoveOut (THREE_D & T,int Step=1)

{

T.X-=Step;

T.Y+=Step;

T.Z-=Step;

}

void main()

{

THREE_D T1= { 10,20,5 }, T2= { 30,10,40 } ;

MoveIn(T1);

MoveOut(T2, 5);

cout << T1.X << ” , ” << T1.Y << ” , ” << T1.Z << endl ;

cout << T2.X << ”,” << T2.Y << ”,” << T2.Z << endl ;

MoveIn (T2, 10);

cout << T2.X << ”,” << T2.Y << ”,” << T2.Z << endl ;

}

e) Find the output of the following program: (2)

# include < iostream.h >

# include < ctype.h >

void MyCode (char Msg [ ] , char CH)

{

for (int Cnt=0; Msg [ Cnt ] != ’ \ 0 ’ ; Cnt++)

{

Page 40: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

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(My Text, ‘@’);

cout << ”NEW TEXT:” << MYTEXT << endl;

}

f) The following code is from a game which generates a set of 4 random numbers. Praful 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.                                                                 (2)

#include < iostream.h >

#include < stdlib.h >

Const int LOW=25;

void main()

{

randomize();

Page 41: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

int POINT=5, Number;

for(int I=1; I<=4; I++)

{

Number=LOW+random(POINT);

cout << Number << ”:” ;

POINT -- -- ;

}

}

i)29:26:25:28:

ii)24:28:25:26:

iii)29:26:24:28:

iv)29:26:25:26:

Marks:12

Answer:

a) Call By Value: This means that when calling a function with parameters, what we have passed to the function are copies of their values but never the variables themselves. The “passing by value” is also known as “Passing by copy”. For example:

#include < iostream.h >

void change (int x)      //x is call by value

{

       x++;

}

main ()

{

Page 42: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

int a;

a=2;

change (a);

cout<< a;

}

Call by Reference: When a variable is passed by reference, we are not passing a copy of its value, but we are somehow passing the variable itself to the function and any modification that we do to the local variables will have an effect in their counterpart variables passed as arguments in the call to the function. A reference parameter is indicated by following the formal parameter name in the function prototype/header by an ampersand (&). The compiler will then pass the memory address of the actual parameter, not the value.

# include < iostream.h >

void change(int &x)     //x is call by reference

{

x++;

}

main()

{

int a ;

a=2;

change (a);

Page 43: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

cout << a;

}

 

b) i) iostream.h   ii) iomanip.h

c) The underlined correction is as:

#include< iostream.h >

# include < stdio.h >

class FLIGHT;

{

long FlightCode;

char Description [ 25 ] ;

public:

void AddInfo()

{

cin >> FightCode;gets(Description);

}

void ShowInfo()

{

cout << FlightCode << ”:” << Description << endl;

}

};

Page 44: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

void main()

{

Flight F;

F.AddInfo (); F.ShowInfo ();

}

 

d) Output:

11,19,6

25, 15, 35

35,5,45

 

e) Output:

    New Text: @@e@ccddIIe

f) iv) 29:26:25:26:

Justification is as follows:

 

I

 

POINT

Number

Minimum

Maximum

1

2

3

5

4

3

25

25

25

29

26

25

Page 45: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

4 2 25 26

 

QUESTION PAPER 2009

(a) What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to illustrate both types of parameters.                             [ 2]           

( b) Write the names of the header files to which the following belong:                                [ 1 ]         (i) setw()(ii) sqrt()

(c) Rewrite the following program after removing the syntactical errors (if any). Underline each correction.                                                     [ 2 ]include < iostream.h >include < stdio.h >Class MyStudent{int StudentId=1001;char Name[20] ;public MyStudent(){}void Register () {cin  >>  StudentId; gets (Name) ;}void Display () {cout << StudentId << ’’ :’’  << Name << endl;}};void main (){MyStudent MS; Register.MS ();MS. Display ();}                                                                                                       

(d) Find the output of the following program :                                 [3 ]# include < iostream.h >  void main (){int A[]  {10,15, 20, 25, 30};int *p = A;while (*p < 30){if (*p %3 ! = 0 )*p = *p + 2;else*p = *p + 1;p++;

Page 46: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

}for (int J = o; J < = 4;  J++){cout << A[J] << “ * “ ;if (J %3 = = 0) count << endl;}cout  << A[4] * 3 << endl;}                                                                                                        

(e) Find the output of the following program:                                [ 2]

#include < iostream.h >#include < ctype.h. >void Secret (char Msq [], int N);void main (){char SMS [] = “ rEPorTmE”;Secret (SMS, 2) ;cout  << SMS << endl;} void Secret (char Msq[], int N){for (int C = 0; Msq [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;}

(f) Study the following program and select the possible output from it:                                                                                                                        [2] #include < iostream.h ># include < stdlib.h >const int MAX=3;void main (){randomize ();int Number; Number= 50 + random (MAX) ;for (int P = Number ; P > = 50; P--)cout <

count << endl;}                          i.      53#52#51#50#                         ii.      50#51#52#

Page 47: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                       iii.      50#51                     iv.      51#50#           

                                     

                               

Marks:12

Answer:

(a) Formal Parameters:

Formal parameters are written in the function prototype and function header of the definition. Formal parameters are local variables, which are assigned values from the arguments when the function is called.Actual Parameters:When a function is called, the values (expressions) that are passed in the call are called the arguments or actual parameters (both terms mean the same thing). At the time of the call each actual parameter is assigned to the corresponding formal parameter in the function definition.Calling programs pass information to called functions in "actual arguments." The called functions access the information using corresponding "formal arguments.

Example :void func( long ex1, double ex2);int main(){    long a = 1;    double b = 2;    // Call func with actual arguments a and b.    func( a, b );}

// Define func with formal parameters ex1, ex2.void func( long ex1, double ex2 ){}

(b) The header files to which following functions belong are :setw() - It belongs to < iomanip.h>sqrt() -  It belongs to < math.h >

(c)   The errors in the above code are as follows:

1.      public - The keyword public should be followed by a colon. It should be public:2.      Register.MS()- To access the method the correct manner is MS.Register();

(d) The output of the given program code is:               12*                16*22*27*                30*90

Page 48: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(e) The output of the given program code is:               TeRmttoe

(f) The output of the given code will be:     (iv) 51#50#

 

QUESTION PAPER 2008

(a) What is the difference between #define and const? Explain with an example  [2] (b) Name the header files that shall be needed for the following code:                      [1]

                        void main()                                                 {                                    char String [] = “Peace”;                                    cout << sets (20) << String;                        }                                                                                                           

(c) Rewrite the following files after removing the syntactical errors, if any.     [2]            #include < iostream.h>           void main()            {                        First = 10, Second = 20;                        Jumpto(First; Second);                        Jumpto(Second);            }            void Jumpto ( int N1, int N2=20)            {                        N1=N1 + N2;                        cout << N1 >> N2;            }                      (d) Find the output of the following code:  [2]                             # include < iostream.h>            # include < ctype.h>            void main()            {                        char Text[]= Mind@Work!;                        for(int I=0; Text(I)!= ‘ /0’; I++)                        {                                    if(!isalpha(Text[I]!= ‘/0’; I++)                                                Text[I] = ‘*’;                                    else if(isupper(Text[I]))                                                Text[I]=Text[I] + 1;                                    else                                                Text (I) = Text[I+1];                        }                        cout<< Text;

Page 49: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

            }           (e) Find the output of the following program: [2]                        # include < iostream.h >            void main()            {                        int U=10, V=20;                        for (int I =1; I <=2; I++)                        {                                    cout << “[1]=” << U++ << “&” << V-5 << endl;                                    cout << “[2]=” << ++V << “&” << U+2 << endl;                        }            }                                         

(f) In the following program, find the correct possible output(s?) from the options:         [2] 

#include< stdlib.h >#include< iostream.h >void main(){

                        randomize();                        char City[][10]= {"DEL", "CHN", "KOL", "BOM", "BNG"};                        int Fly;                        for(int I=0;I<3;I++)                        {                                    Fly=random(2)+1;                                    cout << City[Fly] << ":";                        }

} (i)         DEL:CHN:KOL:(ii)       CHN: KOL: CHN:(iii)     KOL:BOM:BNG:(iv)     KOL:CHN:KOL:

 Marks:12

Answer: (a) The #define statement is used as a preprocessor directive that serves to merely replace a named constant in a program with another text value. E.g.,#define PI 3.14159It substitutes the text 3.14159 in every location where PI occurs in the source code. The const keyword denotes a named variable that is designated by a type (such as int) that is read-only (or constant) during the run-time of the program, and is utilized by the compiler rather than the preprocessor, whose value is subject to be changed during design time in the program.

 

Page 50: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

E.g.,const int number = 108;

 (b)             i) iostream.h

                    ii) iomanip.h  

(c) Correct code:                    void Jumpto(int N1, int N2=20);          #include < iostream.h >           void main()          {                    First = 10, Second = 20;                    Jumpto(First, Second);                    Jumpto(Second);          }          void Jumpto ( int N1, int N2=20)          {                    N1=N1 + N2;                    cout << N1 << N2;          } 

(d) The given code has certain errors due to which it will not execute. 

for(int I=0; Text(I)!= ‘ /0’; I++)The compiler will return call of nonfunction since an array’s element is accessed by Text[I] and not Text(I).

 Again the same error is in the line:Text (I) = Text[I+1];After removing these errors the output would be:

Nnd@*Xrk!*

 (e) Output:

 [1] = 10 & 15[2] = 21 & 13[1] = 11 & 16[2] = 22 & 14 

 (f) The output of the above code will be

          (ii) CHN:KOL:CHN:QUESTION PAPER 2007

Page 51: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(a) Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of each in C++.                                                                             [2]

 (b) Name the header file(s) that shall be needed for successful compilation of the following C++ code:                                                                                            [1] void main ( ){char String [20];gets (String);strcat (String, “CBSE”);puts (String);} (c) Rewrite the following program after removing the syntactical error(s) if any. Underline each correction.                                                                              [2]# include  < iostream.h >const int Max 10; void main ( ) { int Numbers [Max]; Numbers = { 20, 50,10, 30,40 } ; for (Loc= Max-1 ; Loc > = 0 ; Loc - -) cout >> Numbers [Loc]; } (d) Find the output of the following program :                                                   [ 2] # include < iostream.h> void main () { int Array[] = {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; } (e) Find the output of the following program:                                                         [3]# include < iostream.h> void Withdef (int HisNum = 30) { for (int I=20 ; I<= HisNum; I+=5) cout << I << ” , ”;

Page 52: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

cout << endl; } void Control (int &MyNum) { MyNum+=10; Withdef (MyNum); } void main () { int YourNum=20; Control (YourNum); Withdef(); Cout << ”Number=” << YourNum << endl; } (f) In the following C++ program what is the expected value of MyMarks from options (i) to (iv) given below. Justify answer.                                                                            [2 ]#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

Marks:12

Answer:

Syntax Error: These are the errors in coding which do not follow language syntax format, i.e., when statements are wrongly written violating rules of the programming language. It can occur by human mistake in typing and due to lack of knowledge of language.Example : Min +14 = FMIN is a syntax error, as an expression can not appear on the left side of an assignment operator. Run Time Error: They occur during program execution. The compilation of the program is not affected by it. Example: The exceptions like divide a number by 0, overflow and underflow. Another example is running out of memory, which can cause a runtime error.  (b)The header files needed are string.h and stdio.h. (c) # include  < iostream.h >const int Max 10; void main ( )

Page 53: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

{ int Numbers [Max] = { 20, 50,10, 30,40 } ; for (Loc= Max-1 ; Loc > = 0 ; Loc - -) cout >> Numbers [Loc]; } (d) Output: 2 @ 4@ 8 @               4# 8 # 16 # 20 #(e)Output:10, 15, 20, 25, 3010, 15, 20Number=30 (f)(ii) 92. This is because random() function generates a random number between 0 and 1, which added to 2 results in float value greater than 2 but less than 3. As a subscript is an integer value, decimal portion will be chopped off which results in the subscript to be 2.QUESTION PAPER 2005(a) Differentiate between call by value and call by reference, giving suitable               examples of each.  [2]

            (b) Name the header files to which the following belong: [1]

i)       abs()ii)     strcmp()

 (c) Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.  [2]

            # include < iostream.h >            const int Multiple 3;            void main()            {            Value=15;            for(int Counter=1; Counter =< 5; Counter ++, Value-=2)                        if ( Value % Multiple == 0)                                    cout << Value * Multiple;                                    cout << endl;                        else                                    cout << Value + Multiple << endl;            }             (d) Find the output of the following program: [3]            #include < iostream.h >

#include < conio.h >struct MyBox{

Page 54: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                        int Length, Breadth, Height;};void Dimension( MyBox M){

                        cout << M.Length << "x" << M.Breadth << "x";                        cout << M.Height << endl;

}void main(){

                        MyBox B1= {10,15,5},B2,B3;                        ++B1.Height;                        Dimension(B1);                        B3=B1;                        ++B3.Length;                        B3.Breadth++;                        Dimension(B3);                        B2=B3;                        B2.Height+=5;                        B2.Length--;                        Dimension(B2);                        getch();

}    (e) Find the output of the following code: [2]#include< iostream.h >#include< conio.h >#include< string.h >#include< ctype.h >            void Convert(char Str[],int Len)            {                        for(int Count=0;Count < Len; Count++)                        {                                    if(isupper(Str[Count]))                                                Str[Count]=tolower(Str[Count]);                                    else if(islower(Str[Count]))                                                Str[Count]=toupper(Str[Count]);                                    else if(isdigit(Str[Count]))                                                Str[Count]=Str[Count]+1;                                    else Str[Count]='*';                        }            }void main(){            char Text[]="CBSE Exam 2005";            int Size=strlen(Text);            Convert(Text,Size);            cout<< Text << endl;            for(int C=0, R=Size-1; C < = Size/2; C++, R--)            {

Page 55: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                        char Temp=Text[C];                        Text[C]=Text[R];                        Text[R]=Temp;            }            cout<< Text<< endl;            getch();} (f) Observe the following program SCORE.CPP carefully, if the value of Num entered by the user is 5, choose the correct possible output(s) from the options from (i) to (iv) and justify your option.                    [2]//Program:SCORE.CPP#include< stdlib.h >#include< iostream.h >#include< conio.h >void main(){            randomize();            int Num,Rndnum;            cin >> Num;            Rndnum=random(Num)+5;            for(int N=1;N < =Rndnum; N++)                        cout << N <<" ";getch();} i)                1 2 3 4ii)              1 2iii)            1 2 3 4 5 6 7 8 9iv)            1 2 3

Marks:12

Answer:

(a) Call by value - The values of the actual arguments are passed to the function.                  E.g.,

          void fun(int,int); //declarationfun(a,b); // call

     Call by reference - The address of the actual arguments is used in the function call.      E.g.,

          void fun(int&, int&);  // declaration                    fun(a, b);   // call (b)

 (i) abs() : math.h      (ii) strcmp(): string.h

            (c) The correct code is:                    # include < iostream.h >                    const int Multiple = 3;

Page 56: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                    void main()                    {                    int Value=15;                    for(int Counter=1; Counter <= 5; Counter ++, Value-=2)                             if ( Value % Multiple == 0)                                       cout << Value * Multiple;                                       cout << endl;                             else                                       cout << Value + Multiple << endl;                    }           (d) Output:                    10x15x6                    11x16x6                    10x16x11 (e) Output:                    cbse*eXAM*3116                    6113*MAXe*esbc(f) Output:                    The correct output will be                    (iii) 1 2 3 4 5 6 7 8 9 QUESTION PAPER 2006(a) Name the header file to which the following belong [1]              (i)  abs( )                        (ii)  isupper()

      (b) Illustrate the use of #define in C++ to define a macro.   [2]      (c)  Rewrite the following program after removing the syntactical   [2]             error(s), if any. Underline each correction.                #include < iostream.h >                void main()                {                   struct STUDENT                                   {                                        char stu_name[20];                                        char stu_sex;                                        int stu_age = 17;                                    }student;                             gets(stu_name);                             gets(stu_sex);                 }      (d)  Find the output of the following program:     [3]             #include < iostream.h >              #include < string.h >              class state              {

char *state_name;                     int size;

Page 57: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

                public:state(); { size = 0;state_name = new char[size +1];    }

                     state(char *s)                     {            size = strlen(s) ; state_nam = 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”), S1, S2;                                    S1.Replace(state1, state2);                                    S2.Replace(S1, state3);                                    S1.display();                                    S2.display();           } 

(e)    Find the output of the following program:   [2]#include < iostream.h >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;}   

(f)  What are nested structures? Give an example. [2]Marks:12

Answer:

(a)  (i)  math.h           (ii)  ctype.h .

Page 58: · Web viewf) Observe the following program GAME.CPP carefully, if the value of Num entered by the user is 14, choose the correct possible output(s) from the given options ... a) An

(b)  #define MAX 15 // Max is a macro with value 15              #include < iostream.h >              void main()              {           int arr[MAX];          //15 value is substituted in place of                                                       //macro MAX                           for(i =0;i < MAX; i++)                            {                             cout << ”n Enter the value of element” << i+1 << ”:”;                             cin >> arr[I];                             }    }//end of main() (c) Correct code is:               #include < iostream.h >               #include < stdio.h >               void main()               {          struct STUDENT                           {               char stu_name[20];                                            char stu_sex;                                            int stu_age;                            }student;                             gets(student.stu_name);                               cin >> student.stu_sex; } (d) Output is:       DelhiMumbai       DelhiMumbaiNagpur (e)  Output is:       2 (f)  A structure declared within another structure is called nested structure.       Example:             struct student{                                          int rollno;                                          struct name{                                                                        char first_name[10];                                                                        char mid_name[10];                                                                        char last_name[10];                                                                        }

                                          char st_class;                                          char section;                                  };