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

Computer Programming Exit Exam Answers With Explanation Version

The document provides explanations for answers to a computer programming exit exam. It covers topics like generations of programming languages, C++ basics including control statements, arrays, pointers, structures and functions. The document is intended to help students prepare for an exam on computer programming fundamentals.

Uploaded by

sale msg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Computer Programming Exit Exam Answers With Explanation Version

The document provides explanations for answers to a computer programming exit exam. It covers topics like generations of programming languages, C++ basics including control statements, arrays, pointers, structures and functions. The document is intended to help students prepare for an exam on computer programming fundamentals.

Uploaded by

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

Assosa University

College of Computing and Informatics

Department of Computer Science

COMPUTER PROGRAMMING
EXIT EXAM ANSWERS WITH EXPLANATION - VERSION FEB-2024

GEBREIGZIABHER ABADI (MSC IN COMPUTER SCIENCE)

[email protected], [email protected]

Computer Programming Exit Exam Answers with Explanation – Version Feb-2024

APRIL 4, 2024
Computer Programming Exit Exam Answers with Explanations

Chapter 1: Introduction

1. Which generation of programming languages is designed to solve problems by providing


constraints rather than algorithms?
A. First generation C. Third generation
B. Second generation D. Fifth generation

Explanation:
• Fifth-generation programming languages are designed to be more like human language and are well-
suited for solving complex problems in artificial intelligence and expert systems.
• First generation: Low-level machine language (bit: 0’s & 1’s), no abstraction.
• Second generation: Assembly language (uses symbols: mnemonics), slight abstraction.
• Third generation: High-level languages (HLL - e.g., C, Java, Python, PHP), focus on algorithms.
• Fifth generation: Constraint-based problem solving, emphasizing constraints over algorithms.

2. Machine language is grouped under which generation of programming languages?


A. 3rd generation languages C. 2nd generation languages
B. 1st generation languages D. 4th generation languages

Explanation:
• Machine language, the most basic (1GL) language of 1s and 0s, directly understood by
computers.
3. Which of the following represents the typical order of tasks performed in a language processing
system to convert a high-level program into a format executable by a computer?
A. Source program -> Linker/Loader -> Assembler -> Compiler -> Preprocessor
B. Preprocessor -> Compiler -> Assembler -> Linker/Loader -> Source program
C. Source program -> Compiler -> Assembler -> Linker/Loader -> Preprocessor
D. Source program -> Preprocessor -> Compiler -> Assembler -> Linker/Loader -> target machine
code
Explanation:
• The sequence in Choice D reflects the typical compilation process, transforming human-
readable code into machine-executable instructions: Source Code => Machine Code(Bits: 0’s
& 1’s).
Chapter 2: C++ Basics

4. Which program puts together the entire executable object files into memory for execution or
running?
A. Editor C. Linker
B. Debugger D. Loader
Explanation:
Loader is responsible for placing the executable object files and any necessary libraries into
memory, preparing them for execution by the CPU.
• Editor: Crafts source code (the human-readable instructions).
• Debugger: Hunts down bugs (errors) in the running program.
• Linker: Assembles object files (combines code pieces).
• Loader: Prepares program for CPU (loads and sets up for execution).

5. What is the output of the following C++ fragment code?

int t = 16, m = 20;


int n = t++ - m % 4 + m;
cout << n;

A. -15 C. 4
B. 36 D. -5

Explanation:
Step Expression Value
Initial Values t = 16, m = 20 t = 16, m = 20
1 t++ t++ = post-increment 16
2 m % 4 20%4 0
3 t++ - m % 4 16 – 0 16
4 t++ - m % 4 + m 16 - 0 + 20 36
Output cout << n; n = 36 36
6. What is the output of the following C++ fragment code?
int t = 16, m = 20;
int n = t++ - ++m;
cout << n;
A. -15 C. 4
B. 36 D. -5
Explanation:
Step Expression Value
Initial Values t = 16, m = 20 t = 16, m = 20
1 t++ = t t++ = post-increment = 16 16
2 ++m = 1 + m ++m = pre-increment = 21 21
3 n = t++ - ++m n = 16 – 21 = -5 -5
Output cout << n; n = -5 -5
7. What is the output of the following C++ fragment code?
int p, q, n;
p = q = n = 8;
p += n;
p /= q + 1;
cout << p;

A. 16 C. 2
B. 1 D. 24

Explanation:
Step Expression Value
Initial p = q = n = 8 p = 8, q = 8, n = 8 integer values
1 p += n p = p + n => p = 8 + 8 = 16 16
2 p /= q + 1 p = p/q+1 => ≈ 1.7778 (approx.), but due to
p = 16/8+1 = 16/9 = 1.7778 ≈ 1 integer division in C++, p = 1
Output cout << p n = 1 1
8. Look at the following fragment code:

int a = 6;
int b = 5:

while(a > b) {
cout<<"Computer Science program"<<endl;
}

A. Feasibility C. Definiteness
B. Finiteness D. Sequential

Explanation:
• The while loop condition a > b is always true in this code snippet (since a is 6 and b is 5). This
creates an infinite loop, violating the property of finiteness which states an algorithm should
terminate after a finite number of steps.
Chapter 3: Control Statements

9. Which one of the following is false about break statement in C++?


A. The break statement in nested loops terminates its nearest loop.
B. The break statement can be used in if … else statement assuming the if … else statement are
not inside any loop
C. The break statement can be used in a do while loop
D. The break statement can be used in a switch-case statement.
Explanation:
• The break statement cannot be used directly within an if...else statement. It is used to exit
loops or switch-case statements, not if...else statements. break controls loops/switch, not if-
else. Use return in functions or adjust if-else logic.

10. What is the output of the following C++ code fragment?


goto c;
a:
cout<<"Graduating ";
goto b;
c:
cout<<"Year ";
goto a;
b:
cout<<"Fourth";

A. Graduating Year Fourth C. Year Graduating Fourth


B. Year Fourth Graduating D. Graduating Fourth Year

Explanation:
• The program uses goto statements to jump between different labels (a, b, and c). It starts at
label c, prints "Year", then jumps to label a and prints "Graduating", and finally reaches label
b to print "Fourth".
• The execution jumps from c to a, then from a to b, printing "Year Graduating Fourth".

Step Line Executed Output


1 goto c; (Jumps to label c)
2 c: cout<<"Year "; Prints "Year "
3 goto a; (Jumps to label a)
4 a: cout<<"Graduating "; Prints "Graduating "
5 goto b; (Jumps to label b)
6 b: cout<<"Fourth\n"; Prints "Fourth"
• Recommendations:
o Avoid goto: In most cases, goto can make code harder to read and maintain. It's generally
recommended to use control flow structures like if, else, for, and while for better
readability and maintainability.
o Structured Programming: Strive for well-structured code that follows a logical flow using
loops and conditional statements. This enhances code clarity and reduces the risk of
unintended behavior.

Chapter 4: Arrays and String Manipulation

11. Which one of the following is correct array initialization?


A. int list[3] = {2, 4, 6, 8, 10};
B. int list[] = {23, 24, 5, 7, 14};
C. int list[6];
list[] = {12, 1, 13, 2, 3, 5};
D. int list[4] = {1, 6, 3, 9};
int arr[4] = list;
Explanation:
• Option B: int list[] = {23, 24, 5, 7, 14}; is the correct array initialization syntax in both C++
and Java.

Option Array Initialization


A Incorrect (Syntax Error and Mismatched Size)
B Correct: int list[] = {23, 24, 5, 7, 14};
C Incorrect (Syntax Error and Incorrect Initialization after Declaration)
D Incorrect (Cannot Directly Initialize One Array with Another)

Chapter 5: Pointers

Chapter 6: Functions
Chapter 7: Structures

12. Look at the following code fragment?

struct car {
char car_model[25];
float price;
};
car *c1;

Which one of the following is correct C++ statement?

A. cout<<c1->car_mode; C. c1.price = 150000;


B. cin>>c1.car_model; D. cout<<c1<<price;

Explanation:
• Option C correctly assigns the value 150000 to the price member of the car struct pointed to
by c1. It uses the dot operator (.) to access the member of the struct.

Chapter 8: File Management

You might also like