Professional Documents
Culture Documents
MIDTERM EXAMINATION
Computer Programming 1 (IT 112/IT 31)
I. MULTIPLE CHOICE. Write the letter of the correct answer on the space provided before each item. (26 pts)
1. What will be the output of the fragment above if the interactive user enters the integer value 12? (2 pts.)
main()
{
int n;
if (n < 10)
cout << "less than 10" << endl;
else if (n > 5)
cout << "greater than 5" << endl;
else
cout << "not interesting" << endl;
}
2. Assume that the user enters 5 for the input. What is the output of the program below? (2 pts.)
main()
{
int input;
cout<<”Enter an integer:”;
cin>>input;
if(input != 7)
{
cout<<”Hi”<<endl;
if(input == 7)
cout<<”Hello”<<endl;
if(input > 7)
cout<<”Goodbye”<<endl;
}
return 0;
}
A. 7 B. Hi C. Hello D. Goodbye
ISUR-ICT-MJE-086
September 1, 2015
6. What will be the output of the following code? (2 pts)
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
cout<<var2;
else
cout<<++var2;
A. 1 B. 2 C. 6 D. 7
8. From item 7, what is the output if y = 10? (refer to choices in item 7) (2 pts)
9. What would be the output of the following code if variable a=10? (2 pts)
if(a<=0) {
if(a==0) {
cout<<"1 "); }
else {
cout<<"2 "; } }
cout<<"3 ";
A. 1 2 B. 2 3 C. 3 D. 1 3
10. What would be the output of the following code if variable a=-1? (refer to choices in item 9 )(2 pts)
11. In C++, _______ can only test for equality, where as _______ can evaluate any type of the Boolean expression.
A. if, switch B. if, break C. switch, if D. break, if
13. What will be the value of y after the execution of switch statement? (2 pts)
int x = 3, y = 4;
switch(x + 3)
{
case 6: y = 0;
case 7: y = 1;
default: y+= 1;
}
A. 1 B. 2 C. 3 D. 0
14. Which of the following control expressions are valid for an if statement?
A. an integer expression B. a Boolean expression
C. either A or B D. neither A nor B
ISUR-ICT-MJE-086
September 1, 2015
15. The _____________ looks only for a match between the value of the expression and one of its case constants.
A. if B. switch C. if else D. case
A. Eight B. 8 C. Five D. 1
II. PROGRAMMING.
A. DEBUGGING. Debug the following C++ codes and show the exact output. (6 pts each)
1. 2. main
main() {
{ int x, y, z;
Int ct = 10; x = 3;
While (ct > 0); y = 9;
{ z = 77;
cuot>>ct
ct=ct – 1 if (x == (y/3));
} cuot>> "H");
Return 0
} if (z != 77)
cuot>> ("q");
if (z == 77)
cuot>> ("e");
if (z * y + x < 0)
cuot<< ("g");
if (y == (x * x))
cuot>> ("ll")
cuot>>("o!");
return 0
{
3. 4.
int Main()
Main{}
{
)
Int x; int i = 0;
For (x=0; x<10;x++);
Do {
{
cuot>>x cout<<i<< " ";
x=x + 1
i=i+2
}
Return 0 }While (i<= 15)
}
return 0
}
Rating:
Criteria 3 2 1 0
- Free from syntax error
0 element are 1 element is 2 elements 3 elements
- Free from any serious warning
non- non- are non- are non-
- Contains proper prompts for user
compliant compliant compliant compliant
input
- Gives correct/desired output (3)
TOTAL
ISUR-ICT-MJE-086
September 1, 2015
B. PROGRAM CREATION. Choose one problem from the four boxes and create a C++ source code using while (10
pts), for (10 pts) and do – while (10 pts) statements. Note: Use the same problem in all those statements.
Solution: Solution:
1+ 1 =2 4! = 4*3*2*1
2+ 1 =3 = 24
3+ 2 =5
5+ 3 =8 Sum = 2 + 4
=6
3. Display a multiplication table of n 4. Input a number and display a figure
MULTIPLICATION TABLE OF 4 6
1 1 3 4 55
2 4 5 6 444
3 5 6 7 3333
4 6 7 8 22222
111111
Rating:
Criteria 5 4 3 2 1 0
Coding Style
- Comments on important
line of codes (optional) Program
is
- Nicely written codes with
4 2 1 incomple
consistent indention 5 elements 3 elements
elements elements element te and
- Organized and readable are used are used
are used are used is used does not
(code grouping) correctly correctly
correctly correctly correctly fulfill the
- Consistent naming scheme
problem
- Compact and effective given
codes
Program Debugging and Output
- Free from syntax error
- Free from any serious 4 All
3
warning 0 element 1 element 2 elements elements elements
elements
- Contains proper prompts are non- are non- are non- are non- are non-
are non-
for user input compliant compliant compliant complian complian
compliant
- Gives correct/desired t t
output (2)
TOTAL
GOODLUCK!
Prepared by:
Approved by: