COMPUTER SCIENCE C++

1. 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.

//Program: SCORE.CPP
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
int Num,Rndnum;
cin>>Num;
Rndnum = random(Num) + 5;
for(int N = 1;N<=Rndnum;N++)
cout<<N<<” “; }

Output Options:

(i) 1 2 3 4
(ii) 1 2
(iii) 1 2 3 4 5 6 7 8 9
(iv) 1 2 3

2

Ans:Expected Output:

(iii) 1 2 3 4 5 6 7 8 9

2005 Outside Delhi :

1.b) Name the header files to which the following belong:(i) puts( ) (ii)isalnum( )

1

Ans) (i) puts( ) - stdio.h (isalnum( ) - ctype.h

1.c) Rewrite the following program after emoving the syntactical error(s), if any. Underline each correction.

#include<iostream.h>
const int dividor 5;
void main( )
{ Number = 15;
for(int Count=1;Count=<5;Count++,Number -= 3)
if(Number % dividor = = 0)
cout<<Number / Dividor;
cout<<endl;
else
cout<<Number + Dividor <<endl;

2

Ans:

#include<iostream.h>
const int dividor= 5;
void main( )
{ int Number = 15;
for(int Count=1;Count<=5;Count++,Number -= 3)
if(Number % dividor = = 0)
{ cout<<Number / Dividor;
cout<<endl;
}
else
cout<<Number + Dividor <<endl;
}

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )