Computer Programming Exit Exam Answers With Explanation Version
Computer Programming Exit Exam Answers With Explanation Version
COMPUTER PROGRAMMING
EXIT EXAM ANSWERS WITH EXPLANATION - VERSION FEB-2024
[email protected], [email protected]
APRIL 4, 2024
Computer Programming Exit Exam Answers with Explanations
Chapter 1: Introduction
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.
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).
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
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".
Chapter 5: Pointers
Chapter 6: Functions
Chapter 7: Structures
struct car {
char car_model[25];
float price;
};
car *c1;
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.