You are on page 1of 4

INSTITUTE OF INFORMATION AND COMMUNICATION TECHNOLOGY

MIDTERM EXAMINATION
Computer Programming 1 (IT 112/IT 31)

Seek GOD’s help and guidance…

Name: ________________________________ Course/Yr: BSIT Date: ______ Score: _______


Note: Erasure means wrong.

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;

cout << "Enter an integer: ";


cin >> n;

if (n < 10)
cout << "less than 10" << endl;

else if (n > 5)
cout << "greater than 5" << endl;

else
cout << "not interesting" << endl;
}

A. less than 10 B. greater than 5 C. not interesting D. none of the choices

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

3. Which of these are selection statements in C++?


A. if B. for C. while D. break

4. Which of this statement is incorrect?


A. switch statement is more efficient than a set of nested ifs
B. two case constants in the same switch can have identical values
C. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
D. it is possible to create a nested switch statements
5. What are the three basic control structures used in programming?
A. int, double, string B. while, do..while, for
C. sequence, decision, repetition D. input, output, and calculation

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

7. What will be the output of the following code? (2 pts)


int x = 2;
int y = 1;
if (y % x == 1)
{
cout<<y<<" ";
if (y == 8)
{
cout<<y<< " ";
}
else
{
cout<<y<< " ");
}
else
{
cout<<y<< " ";
}
A.13 B. 11 C. 1 D. 2

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

12. Consider the following code: (2 pts)


int x = 10, y = 0;
if (x && y) {
cout<<“TRUE”; }
else {
cout<<“FALSE”; }
What will be the output?
A. TRUE B. FALSE C. Press any key to continue D. Syntax error

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

16. Consider the following code: (2 pts)


int x = 8;
if(x==1);
cout<<“Eight”;
cout<<“Five”;

What will be the output?

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.

1. Display a Fibonacci series of n. 2. Factorial Digital Sum

Sample Output: Sample Output:

Input a number: 6 Input a number: 4


1 1 2 3 5 8 Sum: 6

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

Sample Output: Sample Output:

Input a number: 4 Input a number: 6

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:

MARY JANE C. BANIQUED, MEng’g, MIT


Asst. Prof. 2
Checked by:

MA. VALEN D. ALZATE, Ph D, DIT


Program Chair, IICT

Approved by:

CHARIBEL R. SARTE, MST


Director, ARA
ISUR-ICT-MJE-086
September 1, 2015

You might also like