CS Assignments Class-XII Q-1
Class – XII
                             Subject-Computer Science (083)
                                     Assignment – 1
                     C++ Revision Tour (Q. No. – 1) Weightage – 12 Marks
Q1.    (a) Explain in brief the purpose of function prototype with the help of a suitable          2
           example.
       (b) Name the header files that shall be needed for successful compilation of the            1
           following C++ code :
           void main() {char str[20],str[20];
           gets(str);
           strcpy(str1,str);
           strrev(str);
           puts(str);
           puts(str1); }
       (c) Deepa has just started working as a programmer in STAR SOFTWARE company.                2
           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.
           Int find(int a[],int n)
           { int s=a[0];
           for(int x=1;x<n;x++)
           if(a[x]>s)
           a[x]=s;
           return(s);
           }
       (d) Find output of the following program segment :                                          2
           #include<iostream.h>
           #include<ctype.h>
           void Mycode(char Msg[],char CH) { for(int cnt=0;Msg[cnt]!=„\0‟;cnt++)
           { if(Msg[cnt]>=„B‟&& Msg[cnt]<=„G‟)
           Msg[cnt]=tolower(Msg[cnt]);
           else
           if(Msg[cnt]==„N‟ || Msg[cnt]==„n‟ || Msg[cnt]==„‟)
           Msg[cnt]=CH;
           else
           if(cnt%2==0)
           Msg[cnt]=toupper(Msg[cnt]);
           else
           Msg[cnt]=Msg[cnt–1];
           }}
           void main()
           {
           char MyText[]=”Input Raw”;
           Mycode(MyText,„@‟);
           cout<<”NEW TEXT:”<<MyText<<endl;
           }
       (e) Find the output of the following program :                                              3
           #include<iostream.h>
Page 1 of 18
                                                                              CS Assignments Class-XII Q-1
               void in(int x,int y, int &z)
               { x+=y;
               y - -;
               z*=(x–y);
               }
               void out(int z,int y, int &x)
               { x*=y;
               y++;
               z/=(x+y);
               }
               void main()
               {
               int a=20, b=30, c=10;
               out(a,c,b);
               cout<<a<<”#”<<b<<”#”<<c<<”#”<<endl;
               in(b,c,a);
               cout<<a<<”@”<<b<<”@”<<c<<”@”<<endl;
               out(a,b,c);
               cout<<a<<”$”<<b<<”$”<<c<<”$”<<endl;
               }
       (f)     Write a user defined function DIVT() which takes an integer as parameter and             2
               returns whether it is divisible by 13 or not. The function should return 1 if it is
               divisible by 13, otherwise it should return 0.
Q2.    (a)     What is the difference between actual and formal parameter? Give a suitable              2
               example to illustrate using a C++ code.
       (b)     Observe the following C++ code and write the name(s) of the header fiIe(s)‟              1
               which will be essentially required to run it in a C++ compiler :
               void main ( )
               {
               char Text, [20] , C;
               cin>>Text;
               C=tolower (Text [0] ) ;
               cout<<C<<” is the first char of “ <<Text<<end1;
               }
       (c)     Rewrite the following C++ code after removing all the syntax error(s;, if present        2
               in the code. Make sure that you underline each correction done by you in the code.
               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 [50] STRTNG;
               void main ( )
               {
               City STRING;
               gets (City) ;
               cout<<City [0] <<‟ \ t <<City [2] ;
               cout< <City< <endline ;
               }
       (d)     Obtain the output from the following C++ program as expected to appear on the            2
               screen after its execution.
               Important Note :
               - All the desired header files are already included in the code, which are required to
Page 2 of 18
                                                                      CS Assignments Class-XII Q-1
           run the code.
           Void main ( )
           {
           char *String = ”SARGAM”;
           int *ptr, A[i]={1,5,7,9} ;
           ptr=A;
           cout << *ptrs<<String< <endl ;
           String++;
           Ptr+=3;
           cout<< *ptr<< String<<endl;,
           }
       (e) Obtain the output of the following C++ program, which will appear on the screen      3
           after its execution.
           Important Note :
                 All the desired header files are already included in the code, which are
           required to run the code.
           class Player
           {
           int Score, Level ;
           char Game;
           public :
           Player (char Ggame=‟A‟ )
           {Score=0; Level=1; Game=Ggame; } void Start (int SC) ;
           void Next( ) ;
           void Disp( )
           {
           cout<<Game< < “ @” < <Leve1< <endl;
           cout<<Score<<endl ;
           }
           };
           void main ( )
           {
           Player P,Q („B‟) ;
           P.Disp( );
           Q. Start (75) ;
           Q.Next( ) ;
           P. Start (120);
           Q.Disp( );
           P.Disp( );
           }
           void Player::Next()
           { Game = (Game = = „A‟): „B‟: „A‟; }
           void Player: :Start (int SC)
           {
           Score+=SC;
           if (Score >= 100 )
           Level=3;
           else if (Score>=50 )
           Level=2;
           else
           Level=1;
           }
Page 3 of 18
                                                                              CS Assignments Class-XII Q-1
       (f)     Read the following C++ code carefully and find out, which out of the given               2
               options (i) to (iv) are the expected correct output(s) of it. Also, write the
               madmum 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) 150#20#
               (iii) 150#20#250#                  (iv) 20#250#
Q3.    (a)     What is the difference between call by reference and call by value with respect to       2
               memory allocation? Give a suitable example to illustrate using C++ code.
       (b)     Observe the following C++ code and write the name(s) of the header file(s), which        1
               will be essentially required to run it in a C++ compiler :
               void main()
               {
               char CH,STR[20];
               cin>>STR;
               CH=toupper(STR[0]);
               cout<<STR<<”starts with”<<CH<<endl;
               }
       (c)     Rewrite the following C++ code after removing all the syntax error(s), if present in     2
               the code. Make sure that you underline each correction done by you in the code.
               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;
               }
       (d)     Obtain the output from the following C++ program as expected to appear on the            2
               screen after its execution. 2
               Important Note :
               - All the desired header files are already included in the code, which are required to
               run the code.
               void main()
               {
               char *Text=”AJANTA”;
               int *P, Num[ ]={1,5,7,9};
               P=Num;
               cout<<*P<<Text<<endl;
               Text++;
               P++;
               cout<<*P<<Text<<endl;
Page 4 of 18
                                                                        CS Assignments Class-XII Q-1
           }
       (e) Obtain the output of the following C++ program, which will appear on the screen        3
           after its execution.
           Important Note :
           ● All the desired header files are already included in the code, which are required to
           run the code.
           Class Game { int Level, Score;
           char Type;
           public:
           Game(char Gtype=‟P‟)
           { Level=1;Score=0;Type=Gtype;}
           void Play(int GS);
           void Change();
           void Show()
           {
           cout<<Type<<”@”<<Level<<endl;
           cout<<Score<<endl;
           }
           };
           void main()
           {
           Game A(„G‟),B;
           B.Show();
           A.Play(11);
           A.Change();
           B.Play(25);
           A.Show();
           B.Show();
           }
           void Game::Change()
           {
           Type=(Type==‟P‟)?‟G‟:‟P‟;
           }
           void Game::Play(int GS)
           {
           Score+=GS;
           if(Score>=30)
           Level=3;
           else if(Score>=20)
           Level=2;
           else
           Level=1;
           }
       (f) Read the following C++ code carefully and find out, which out of the given options 2
           (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]<<”#”;
Page 5 of 18