Tuesday, September 9, 2014

C++ Midterm Exam (Set B)

Viral Stuff and Trending News


Test I. CONCEPTS (34 pts)

A. Enumeration (3 pts each, a total of 9)
Syntax/ General Format of while, for and do-while loop structure, in order.
1.         
2.         
3.         

B. Program Tracing (5 pts each, a total of 25)
Determine the output of the following code snippet through program tracing.
1.  for (int var1=5;  var1<=10; var1++){

       var1 = var1 + 3;

       cout << var1;

}

2.  int x=0;

do{

       if ( x ==5)

             x=10;

       cout << x;

}while (x <= 5);

3.  for (int j=0; j >= 5; j++){

       cout  << j;

}cout << j;

4.  int i=11;

while( i <= 20){

       cout << i;

}

5.  for (int i=1; i<=10; i+=3){

cout << i;

i=i+3;

}


Test II. CODE WRITING (25 pts)

Problem:

Write a program to require an integer input between 1 and 10. Vary and display the control variable of a for-loop statement starting from 1 to 10 and put a dollar ($) sign in place of all variation except for that number.

Sample output #1:
Enter an integer value between 1 and 10: 6
$$$$$6$$$$

Sample output #2:
Enter an integer value between 1 and 10: 10
$$$$$$$$$10

Sample output #3:
Enter an integer value between 1 and 10: 3

No comments:

Post a Comment