Computer Programming theory quiz 2


QUIZ NO. 02

Date:    /03/2017
Time: 20 Minutes
Total Marks: 10
Obtained Marks: _______
Enrollment No:
___________
Student_Name:
____________________________________

1.       Suppose that scores is an int variable. Consider the following c++ code:                 [1 mark]

int score;
cin>>score;
switch(score % 7)
{
case 0:
score =score/2-1;
break;
case 1 : case 3:
score =3 * score + 1;
break;
case 2:
++score;
break;
case 4:
break;
case 5 : case 6:
score =score % 3;
break;
default:
score = score/2;
}
cout<<score;

a)      What is the output if the input is 12?    _______0_________
b)     What is the output if the input is  4?     ________4________
c)      What is the output if the input is  3?     ________10________
d)     What is the output if the input is 25?    ______25__________





2.      Writethe outputof the following statements.                                                                  [5 marks]

S.NO
CODE BLOCK
OUTPUT
a.       
int main(){
int x = 1;
for(;x<=15;x++){
if(x%2 == 0)
continue;
cout<<” “ <<x;
}
return 0;}



1 3 5 7 9 11 13 15
b.       
int main(){
int x = 1;
while(1) {
cout<<” “ <<x;
if(x==8)
break;
x++;
}
return 0; }



1 2 3 4 5 6 7 8
c.        
int main() {
int i = 1999;
for(;i++<=2012;){
if(i%4 ==0 && i%100 != 0)
cout<<i<<””;
else if(i%100==0 && i%400 == 0)
cout<<i<<””;
}
return 0;
}




2000  2004  2008  2012
d.       
int x =5, y = 12;
if(x + y >20 | | y –x <10){
x = y + 6 ;
y = 2 * ( x + y );
cout << x << “” << y << “”<<x-y <<”” << x+y<<endl;
}
else {
y = (5 * x + 20 ) % y ;
cout<<x<<””<<y<<””<<x*x+y*y<<endl;
}




18 60 -42 78
e.        
const int M = 5; const int N = 5;
for(int i =1 ; i <= M ; i++){
for(int j= 1 ;j <=N;j++)
cout<<setw(3)<< M* (i-1) + j;
cout<< endl;}
  1  2  3  4  5
  6  7  8  9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25


3.      State wheather true or false . Provide answers in given answer sheet.                       [4 marks]

a.      In c++ ,= , is the equality operator.
b.      In a one way selection, if a semicolon is palced after the expression in an if statement , the expression in the if statement is always true.
c.       Every if statement must have a corresponding else.
d.      The result of a logical expression can not be assigned to an int variable.
e.       It ispossible that the body of a while loop may not execute at all.
f.       In an infinite while loop, the while expression isinitially false, but after the first iteration it is always true.
g.      A loop is a control structure that causes certain statements to execute over and over.
h.      In a counter –controlled while loop, it is not necessary to initialize the loop control variable.

ASWER SHEET FOR QUESTION NO. 3

Q.No
Answer
a.       
F
b.       
F
c.        
F
d.       
T
e.        
T
f.        
F
g.       
T
h.       
F


Comments

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4