Sunteți pe pagina 1din 2

VELAMMAL BODHI CAMPUS, THENI

COMPUTER SCIENCE
WORKSHEET – I
CH.1 C++ REVISION TOUR
DOI : 20-02-19 DOS:22-02-19

1. Name the header file, to which followings built-in function belong to

a. (i) cos() (ii) setw() (iii) toupper() (iv) strcpy() b. (i) strcat () (ii) scanf () (iii) getchar() (iv) clrscr ()
c. (i) isupper() (ii) frexp () (iii) exp() (iv) strcmp() d. (i) write() (ii) arc() (iii) open() (iv) strlen()
e. (i) gets ( ) (ii) strcmp( ) (iii) abs( ) (iv) isalnum( ) f. (i) strcmp() (ii) fabs() (iii) getchar() (iv) putchar

2. Which C++ header file(s) will be essentially required to be included to run / execute the following C++
code

b. void main ( ) c. void main()


a. void main()
{ void main ( )
{
int Last =25 ; {
char Msg[ ]="Sunset
for ( int C=9 ; C <= char TEXT [ ] =
Gardens";
Last ; C ++ ) “Something” ;
for (int
cout<< C << “ : “ cout<< “Remaining SMS
I=5;I<strlen(Msg);I++
<<sqrt ( C ) <<endl; Chars : “
)
} << 160-
puts(Msg);
} strlen(TEXT)<<endl;
}

3. Rewrite the corrected code for the following program. Underline each correction (if any)

a. #include <iostream.h> b. #include <iostream.h> c. # include <iostream.h>


void main() void main () void main()
{ { {
int R;W = 90; int s1, s2, num;
s1 = s2 = 0; int x;
while W > 60
{
for (x = 0; x<11; x++) cin<< x;
{ for(int y = 0; y<10; y++);
R = W- 50; cin << num;
switch(W) if (num>0) cout>>x + y;
{ 20:cout << "Lower Range"<<endl; s1 += num; }
30:cout<< "Middle Range"<< endl; else
40: cout<< "Higher Range"<<endl; s2 = /num;
} }
} cout << s1 << s2;
} }

4. Write a function name SUMFUN(), with arguments x and N, which returns the sum of the following series

a. 1 - x2/2 + x3/3 - x4/4 + x5/5 - x6/6+….+xN/N

b. 1/x-3!/x2 + 5!/x3 - 7!/x4 + 9!/x5+....

c. 1 + x / 2! + x2 / 4! + x3 / 6! + x4 / 8! + x5 /10! + ... + xn / (2n)!

5. Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or
Functions in a C + + program: Total*Tax, double, case, My Name, New switch, Column31, _Amount
6. Look at the following C++ code and find 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 Taker

a. b.
void main() void main()
{ {
randomize(); int GuessMe[4]=
int Taker; {100,50,200,20};
Taker =random(3); int Taker = random(2)+2;
char for(int
COLOUR[][5]={"BLUE","PINK","GR Chance=0;Chance<=Taker;Chance
EEN","RED"}; ++)
for(int 1=0;I<= Taker;I++) cout<<GuessMe[Chance]<<"#";
{ }
for(int J=0;J<=I;J++)
cout<<COLOR[J];
cout<<endl;
}
}

7. 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 Trick used in the code at the time when
value of count is 3 :

a. b. void main()
void main() {
{ int Begin=3,Stop;
char status[][10]={"EXCEL","GOOD", "OK"};
for(int Run=l;Run<4;Run++)
int Turn = 10, Trick;
for(int Count=1;Count<4;Count++) {
{ Stop=random(Begin)+6;
Trick = random(Count); cout<<Begin++<<Stop<<"*";
cout<<Turn-Trick<<Status[Trick]<<"#"; }
} }
} (i) 36*46*57*
(i) 10EXCEL#EXCEL#8OK# (ii) 37*46*56*
(ii) 10EXCEL#8OK#9GOOD#
(iii) 37*48*57*
(in) 10EXCEL#9GOOD#10EXCEL#
(iv) 10EXCEL#10GOOD#8OK# (iv) 35*45*57*

8. Write the output from the following C+ + program code :


b.
a.
#include<iostream.h> #include<stdlib.h>
includecctype.h> #include<iostream.h>
void strcon(char s[])
{ #include<string.h>
for(int i=0,1= 0;s[i]! = '\0' ;i++,1++) ; void main()
for(int j=0;j<l;j++) {
{
if (isupper(s[j])) randomize();
s[j]=tolower(s[j])+2; char P[]="C++PROGRAM";
else if(islower(s[j]))
s[j]=toupper(s[j])-2;
long L;
else for(int 1=0;P[I]!='R';I++)
s[j]='@'; {
}
} L=random(sizeof(L))+5;
void main() cout<<P[L]<<";
{ }
char *c="Every moment is a fresh beginning";
strcon(c); }
cout<<"Text= "<<c<<endl; (i) R-P-O-R
c=c+3;
cout<<"New Text= "<<c<<endl;
(ii) P-0-R-+-
c=c+5-2; (iii) O-R-A-G
cout<<"last Text= "<<c (iv) A-G-R-M-
}

S-ar putea să vă placă și