ETHIOPIAN TECHNICAL UNIVERSITY
DEPARTMENT OF INFORMATION TECHNOLOGY
Course Title: *Basic Programming*
Final exam
Date: April 29, 2021
Name: Time allowed: 2:15 hrs
Max Weight: 50%
ID. No:
Department: Section:
Program: Regular Extension
GENERAL DIRECTIONS:
1. Make sure that the exam paper contains 9 pages including the cover page.
2. Read the instructions carefully for each part of the exam and attempt accordingly.
3. Use of pencils and red pens is not allowed.
4. Mobile phones should be switched off.
5. Any action taken by exam invigilator during exam time will not be compromised.
6. Any form of cheating will result in the cancelation of your results
For Instructors Use only
PartI (5%) PartII (20%) PartIII (5%) PartIV (9 %) Part V (11) Total (50%)
IIIIII
April, 2021
Page 1 of 10
Part I: Write true if the statement or false if the statement is incorrect, put
the answer on the space provided on the attached sheet. (1 point each)
1. C++ is a type of low-level language.
2. All variables in a C++ program must be declared before they are used.
3. A program is a set of instructions a computer follows in order to perform a task.
4. In C++, key words are written in all lowercase.
5. The = operator and the = = operator perform the same operation when used is a Boolean
expression.
Part II: Choose the correct answer from the given alternative and put the
answer on space provided on the attached answer sheet. (1 point each)
1. If you want to store a single letter on a variable. What should be its data type?
A. char C. float
B. int D. double
2. Which of the following is a correct identifier in C++?
A. 16_num C. 7var_1234
B. first.name D. var_1234
3. One of the following data types is used to hold data with decimal digits:
A. int C. char
B. float D. long
4. Which data type is best suited to represent logical values in c++?
A. integer C. float
B. character D. Boolean
5. In your code if there is a statement x+=y, which one of the following is true about it?
A. It assigns the value of x+y on x. C. It compares the value of x and y.
B. It assigns the value of y on x. D. It assigns the value of x+y on y.
6. Which of the following is the correct syntax to print the message in C++ language?
A. COUT<<Hello world!; C. Out <<"Hello world!;
B. cout<< “Hello world!” ; D. None of the above
7. Which one the following is a loop with the condition tested at the end?
A. for loop C. while loop
B. do-while loop D. A and B
Page 2 of 10
8. A statement in c++ that allows us to specify more than two alternative statements each will be
executed based on testing multiple conditions.
A. Simple if C. For loop
B. if else D. if -else if -else
9. What value will be assigned to the variable x after the execution of the following expression?
Assume i has a value of 2 and j has a value of 3
x = 5 * i++ – 10 % ++j;
A. 9 C. 8
B. 6 D. 0
10. For inserting a new line in C++ program, which one of the following statements can be used?
A. \a and endl C. \n and endl
B. \r and endl D. None
11. Which one of the following is the correct C++ statement?
A. int 16; C. char my_var;
B. cin>>”Hello World”; D int 2nd_Num;
12. Which one of the following is true about the prefix operator ++x?
A. Return the value of x and then add one to the variable x.
B. Add one to the variable x and then return the value.
C. Subtract one to the variable x and then return the value.
D. A and B.
13. Which of the selection statement is suit for menu driven application?
A. if statement C. switch statement
B. if-else statement D. nested if statement
14. Which one of the following symbol represent a single line comment which is ignored by the
compiler?
A. Two forward slashes (//) C. A slash and a star (/*).
B. Three forward slashes (///) D. A star and a slash (*/)
15. What is the only function all C++ programs must contain?
A. start () C. main ()
B. system () D. program ()
Page 3 of 10
16. Which of the following is Programmer given name?
A. Directives C. Identifiers
B. Keywords D. None
17. The statement i++; is equivalent to?
A. i = i + i; C. i +=1;
B. i = i + 1; D. B and C
18. What's wrong with the following line of code? for (int k = 2, k <=12, k++)
A. The commas should be semicolons
B. The variable must always be the letter i when using a for loop
C. There should be a semicolon at the end of the statement
D. The increment should always be ++k
19. Which of the following must tbe placed at the beginning and the ending of the loop block?
A. parentheses ( ) C. brackets [ ]
B. braces { } D. arrows < >
20. In the c++ fragment code written below the statement count=11 represents_______
for (count = 11; count <= 10; count++)
A. condition C. iteration
B. definition D. initialization
Part III: Match the following from Column “A” to column “B” and write the
answers on the answer sheet (1 pt. each)
“A” “B”
1. = = A. Logical Operator
2. = B. Reference operator
3. % C. Dereference operator
4. || D. Assignment operator
5. + E. Arithmetic operators
F. Relational operator
G Modulus operator
H. Division operator
Page 4 of 10
Part IV: Write the answers for the following questions on the spaces provided
(3 points each)
1. The following program should print the text below to the screen. Determine if there is an error
in the code. If there is an error, circle the error in the code and write the corrected code in the
space provided after each problem. If the code does not contain an error, write “no error.”
2. Write the output of the following piece of code exactly as it appears on the computer screen
using the space provided (assume the code is free of error).
#include<iostream>
using namespace std;
int main() Output
{
int x=15;
cout<<x<<endl;
x++;
cout<<x<<endl;
x=x*2;
++x;
cout<<x;
return 0;
3. What is the output of this program? Output
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<5;i++)
{
cout<<"ETU"<<" "
}
return 0;
}
Page 5 of 10
Part Five: Write a program for the following questions.
1. Write an algorithm using a flowchart to calculate the sum of three input numbers from the
Keyboard? (3 point)
2. Write a program the takes two numbers from keyboard, the program then displays the sum of
the numbers to the screen? (4 points)
3. Write a c++ program that checks a number inserted from a keyboard is odd or even number.
(4 point)
Page 6 of 10
Part Four
1.
No error
No error
int main()
{ // change [ into {
int x=50; //the variable should be first declared
cout<<"Good luck !"; //put the semicolon at the end of the sentence
cout<<"You must score: "<<x; // change the insertion operator into extraction operator
return 0;
} // change ] into }
2.
15
16
33
3.
ETU,ETU,ETU,ETU,ETU
Part Five
1.
Start
Input
num1,num2,num3
Sum=num1+num2+num3
Display sum
END
Page 7 of 10
Page 8 of 10
Page 9 of 10
Answer Sheet
Name____________________________________ID____________________
Part I: True or false
1. ____False_______
2. ____ True______
3. _____True_______
4. _____True_______
5. _____False_______
Part II: Choose the Best Part III: Matching
1. _____A_______
1. _____F_______
2. _____D_______
2. _____D_______
3. _____B_______
4. _____D_______ 3. _____G_______
5. _____A_______ 4. _____A_______
6. _____B_______ 5. _____E_______
7. _____B_______
8. _____D_______
9. _____C_______
10. ____C________
11. ____C________
12. ____B________
13. ____C________
14. ____A________
15. ____C________
16. ____C________
17. ____D_______
18. ____A________
19. ____B________
20. ____D________
Page 10 of 10