0% found this document useful (0 votes)
3 views

cpp code 1 2024 (2)

This document is a final exam paper for a programming course at CPU Business and Information College, dated February 2024, with a total weight of 50%. It consists of multiple-choice questions, programming code fragments, and programming tasks that assess students' understanding of fundamental programming concepts. The exam includes directions, questions on code output, and programming assignments to be completed by the students.

Uploaded by

Alemseged Mammo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

cpp code 1 2024 (2)

This document is a final exam paper for a programming course at CPU Business and Information College, dated February 2024, with a total weight of 50%. It consists of multiple-choice questions, programming code fragments, and programming tasks that assess students' understanding of fundamental programming concepts. The exam includes directions, questions on code output, and programming assignments to be completed by the students.

Uploaded by

Alemseged Mammo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CPU BUSINESS AND INFORMATION COLLEGE

* *
DEPARTMENT OF COMPUTER SCIENCE * *
FUNDAMENTAL OF PROGRAMMING
FINAL EXAM (DEGREE PROGRAM)

Date: Febrary 2024


Time Allowed: 2:00hrs
Total weight: 50%

Name: _______________________________ Instructor: Tewodros G.

ID No : _____________________________

Section: _______________________________

GENERAL DIRECTIONS:
1. Make sure that the exam paper contains 7 pages including the cover page and answer
sheet.
2. Read the instructions carefully for each part of the exam and attempt accordingly.
3. Use of pencils and red pens are not allowed.
4. Mobile phone should be switched off.
5. Any action taken by exam invigilator during exam time will not be compromised.
6. Put any materials not allowed on the instructor’s desk.
7. Write your answers on the question Paper.

Education is not preparation for life; education is life itself. – John Dewey

1
Part I
Multiple Choice (1 points each Total of 23 Points)
________1.What is the output of this program segment?

1. int main()
2. {
3. int a = 10;
4. if (a <= 10) {
5. for (i = 0; i < 10; i++)
6. cout << i;
7. }
8. else {
9. cout << i;
10. }
11. return 0;
12. }
a) 0123456789 b) 123456789 c) 0 d) None of the above
________2. Which of the following correctly declares an array?
a) int array[10]; b) int array; c) array{10}; d) array array[10];
_______3.What is the index number of the last element of an array with 9 elements?
a) 9 b) 8 c) 0 d) Programmer-defined
______4.What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element of the different type in contiguous memory
locations
c) An array is a series of elements of the same type placed in non-contiguous memory
locations
d) None of the mentioned
_______5.Which of the following accesses the seventh element stored in array?
a) array[6]; b) array[7]; c) array(7); d) array;
______6.What is the output of this program segement?
1. int main()
2. {
3. int a;
4. a = 5 + 3 * 5;
5. cout << a;
6. return 0;
7. }
a) 40 b) 20 c) 25 d) 30
________7.What is the output of this program segment?
1. int main ()
2. {
3. int n;
4. for (n = 5; n > 0; n--)
5. {

2
6. cout << n;
7. if (n == 3)
8. break;
9. }
10. return 0;
11. }
a) 543 b) 54 c) 5432 d) 53
____8. Which for-loop will run a variable from 5 to 105 in steps of 4?
a. for(int i = 5; i <= 105; i += 4)
b. for(int i == 5; i > 105; i = i + 4)
c. for(int i == 5; i < 105; i = i + 4)
d. for(int i = 5; i > 105; i += 4)
_____9.Which expression will cause the while-loop to loop until x equals 1 or init is
not 'g'?
a.while(x == 1 && init != 'g')
b.while((x == 1) || (init != 'g'))
c.while((x != 1) && (init == 'g'))
_____10.A do-loop is different from a while loop because
a. do-loops have a preset number of cycles for looping.
b. the code in a do-loop is executed at least one time.
c. while loops will only check the condition after each pass.
d. the break statement works in while-loops but not in do-loops
_____11.Which statement checks that an integer dig falls between the
integers 1and 9?
a. if(dig >= 1 && dig <= 9)
b. if(dig >= 1) else (dig <= 9)
c. if(dig > 1 || dig < 9)
d. None of the above
______12.You wants to display "too short" if height is less than 4 and "okay"
otherwise. Your best choice is to use a(n)
a. for-loop
b. switch-statement
c. if/else-statement
d. array
_____13.To loop through an array of size 6, a proper for-loop statement would be
a. for(i = 0; i < 6; i++)
b. for(i = array[0]; i < array[5]; i++)
c. for(array[0] = i = 0; i < array[5]; i += 1)
d. for(i = 0; i <= 6; i++)
Answer the questions from 14 - 16 based on the following code.

int id = 0;
cout << “Id “;
cin>> id;
if ( id < =2)

3
cout<<”Janet”;
else if ( id>2 && id <=5)
cout<<”Mark”;
else
cout<<”Sue”;
____14.What will the code display when the id variable contains the number 2?
a. Janet b.Mark c.Sue
____15.What will the code display when the id variable contains the number 4?
a. Janet b.Mark c.Sue
____16.what will the code display the id variable contains the number 7?
a. Janet b.Mark c.Sue
____17.What numbers will the following code display on the computer screen?
int x = 1;
do
{
cout<<x++<<” “;
x = ++x+1;
} while (x < =5);
a. 1 3 4
b. 1 3 4 5
c. 1 4
d. 1 5
____18.Which of the following is false?
a. The elements in an array are related in some way.
b. All the elements in an array have the same data type.
c. All the elements in one dimensional array have the same subscript.
d. The first element in a one-dimensional array has a subscript of 0(zero).
____19.Which of the following increases the total variable by the contents of the second
element in the orders array? The total variable and the orders array have the int data
type.
a. Orders[1] += total;
b. Orders [2] += total;
c. Total +=orders[1];
d. Total +=orders[2];
_____20.How many times will the computer process the cout<<numtimes<<endl; statement in
the following code?
int numtimes = 5;
while (numtimes > = 0)
{
cout<<numtimes<<endl;
numtimes = numtimes - 1;
}
a. 0 b.1 c.5 d.6
_____21.What number will the following code display on the computer screen?

4
int sum = 0, y = 0;
do
{
sum = 0;
for (int x = 1; x<=5;x = x +1)
sum = sum + x;
y= y + 1;
} while(y < 3);
a. 5 b.8 c.15 d.30
______22. 91 % 7 evaluates to
a. 0 b.1 c.2 d. 3
_____23.Which of the following statements will not affect the value of x?
a. X++
b. X += X --;
c. X = X++;
d. X = --X+1;
Part II
Write the output of the following code fragments in the space
provided (Total 12 pts)

1. Write is the exact output that produced by the following program segment. (2 pts)

int k, max = 10;


for(k=1; k <= max; k++) Write the output Here
{
k++;
k +=max;
cout << "k = " << k <<”\n”;
}
cout << "All done!" ;

2. Write output of the following program Segment. (2 pts)


Write the output Here
int X = 0, Y = 4;
Y++;
X + = Y;
cout<< “ X = \t ”<<X++;
cout<<” Y= \t ”<<X + Y;

3. Write the output. (2 pts)


Write the output Here
1. int billy[] = {0, 2, 4, 6, 7, 5, 3};

5
2. int n, result = 0;
3. for (n = 0 ;n < 5 ;n++) {
4. result += billy[n];
5. }
6. cout << result;
4. What is the output when the following code fragment is executed?(2 pts)

int found = 1, count = 5; Write the output Here


if (!found || --count == 0)
cout << "danger" << “\n”;
cout << "count = " << count ;
3. Answer the questions below concerning the following fragment of code.(1 pt each: Total of 4 Points)

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. What will be the output of the fragment above if the interactive user enters the integer value
0?
Your Answer Here:- ____________________________________________

b. What will be the output of the fragment above if the interactive user enters the integer value 15
?
Your Answer Here:- ____________________________________________

c. What will be the output of the fragment above if the interactive user enters the integer value
7?
Your Answer Here:- ____________________________________________
d. What values for n will cause the output of the fragment above to be "not interesting"?
Your Answer Here:- ____________________________________________

Part III
Write a complete CPP Program on the attached Sheet of paper clearly.(Total of 15 Points)
1. Write a CPP program which accepts sex as M or F and display Male if sex is M or
m and Female if sex is F or f. Use CPP’s Switch case statement. (3 points)
2. Write a CPP program which reads Salary and display tax. Tax is calculate as 10 %
of salary if salary is above 5000 else 5% of salary. (3 points)
3. Write a CPP program that takes two integer arguments, call them "First" and
"Last", and displays as its value the sum of all the integers between first and last
inclusive. Thus, for example,

6
First = 4 Last = 7 // will print 22 because 4+5+6+7 = 22 (3 points)
4. Write a program which stores test scores in two int variables named myScore and
expectedScore. Both these variables should be read from the keyboard. The
program should compare the two scores and then display one of the following
messages:”I met my expectation”, “I scored higher than expected”, or “I scored
lower than expected”. (3 points)
5. Write a CPP program to read an integer and display “ Its Even” or “Its Odd”
depending on the vale.(3 Points)

You might also like