REVIEW OF C++
- CLASS TEST - TOTAL MARKS – 25 –
DURATION – 1 HR
a) Name the
header file to which the following belong:
(1)
i. pow( )
ii.
random( )
b) Find the
output of the following program: (2)
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>0);
cout<<First-Second;
}
c) Illustrate the use of local and global
variables in C++. (2)
d) Differentiate
between a Run Time Error and Syntax Error. Also give suitable
examples of each in C++. (2)
e) 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);
}
f) 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];
}
g) 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<<" ";
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main ()
{
int YourNum=15;
Control (YourNum);
Withdef();
cout<<"Number="<<YourNum<<endl;
}
h) 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
i)Differentiate between a Logical
Error and Syntax Error. Also give suitable examples
of each in C++. (2)
j) Name the header file(s) that
shall be needed for successful compilation of the
following C++ code : (1)
void main( )
{
char Text[40];
strcpy(Text,”AISSCE”);
puts(Text);}
K) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. (2)
#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];
}
l) In the following C++ program
what is the expected value of Myscore from Options
(i) to (iv) given below. Justify
your answer. (2)
#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
m) Find the output
of the following program : (3)
#include<iostream.h>
struct POINT
{int X, Y, Z;};
void StepIn(POINT & P, int
Step=1)
{
P.X+=Step;
P.Y -=Step;
P.Z+=Step;
}
void StepOut(POINT & P, int
Step=1)
{
P.X-=Step;
P.Y+=Step;
P.Z-=Step;
}
void main ( )
{
POINT P1={15, 25, 5}, P2={10, 30,
20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<","<<P1.Y<<","<<P1.Z<<endl;
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
}
No comments:
Post a Comment