Anda di halaman 1dari 3

CH

E
N
N
A
I
P
U
B
L
I
C

S
C
H
O
O
L
Anna
Nagar

Chenn
ai -600
101

Worksheet – 1 – March 2017 – Review of C++


COMPUTER SCIENCE

Class  Date 

Name  Roll No. 


Class XII Computer Science Worksheet - 1 Page 1 of 2
1)a) Find the correct identifiers out of the following, which can be used for naming Variable,
Constants or Functions in a C++ program : 2
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
b) Write the related library function name based upon the given information in C++. 1
(i) Get single character using keyboard. This function is available in stdio.h file.
(ii) To check whether given character is alpha numeric character or not. This function is
available in ctype.h file.
c) Rewrite the following program after removing the syntactical errors (if any). Underline each 2
correction.
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{ Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<< 'characters' <<endl;
}
d) Write the output of the following C++ program code 2
Note : Assume all required header files are already being included in the program.
void Motivate( double x, double &y, int i, int &j)
{ x=y;
y=x;
i=2 * i;
j = 2* j;
}
void main()
{ double x=15.0, y =25.0;
int i=20,j=30;
Motivate(x,y,i,j);
cout<<x<<" "<<y<<" "<<i<<" “<<j<<endl;
i=3; j=4;
Motivate(y,x,j,i);
cout<<x<<" "<<y<<" "<<i<<" "<<j<<endl;
}
e) int between(char a, char ch, char b) 3
{
int x=(ch>=a&&ch<=b)?1:0;
}
void mycode(char msg[], char ch)
{
for(int cnt=0;msg[cnt]!='\0';cnt++)
{ if(between('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];
Class XII Computer Science Worksheet - 1 Page 2 of 2
}}
void main()
{
char mytext[]="Input Raw";
mycode(mytext,'@');
cout<<"New text:"<<mytext<<endl;
}
f) Look at the following C++ code and find the possible output(s) from the options 2
(i)
to (iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable CHANGER.
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 I=0;I<=CHANGER;I++)
{
for(int J=0;J<=I;J++)
cout<<CITY[J];
cout<<endl; }}

THE END

Class XII Computer Science Worksheet - 1 Page 3 of 2