Your question
STARFORD INTERNATIONAL UNIVERSITY UNIVERSITY EXAMINATION MAY 2025 COURSE
NAME: INTRODUCTION TO COMPUTER PROGRAMMING CODE: SCI 1125 YEAR: ONE
SEMESTER: TWO DURATION: 3 HRS
Instructions: Answer three questions in total and question one is compulsory Answer any other two
questions
Question 1. (30 mks) a) Write the description of the following statements i) If statement ii) If-Else
statement iii) switch statement b) Explain the difference between compiler and interpreter by using
diagram c) What is a loop? Explain three types of loops? d) Write a C++ program to read 15
numbers, 5 numbers per row, then print them. e) What is the different between functions overloading
and Recursive?
Question 2. (20mks) a) What are the four general rules for declaring a variable? b) What do you
understand by term algorithm? c) Give three types of comments with their symbols d) Write a simple
C++ program to print message on the screen "Hello My Friend".
Question 3. (20mks) a) What are the four major uses of computer program? b) With the help of
examples, who is a computer programmer? c) Explain three composition of functions? d) What is the
important of program design to other programmer?
Question 4. (20mks) a) Define the term operator b) Explain five types of operators use in computer
programming c) What is the different between Arithmetic and Relational operators with examples? d)
Give the difference between local and global variable by giving two example
Show more
Natural Writing
SuperAI
Question 1: Intro to programming concepts and C++ tasks
a) Descriptions of control statements:
(i) If statement:
Used for decision-making. Tests a condition; if condition is true, executing a block,
otherwise skipping.
(ii) If-Else statement:
Two-way decision. If condition is true, executing first block; else executing alternative
block.
(iii) Switch statement:
Multi-way selection based on an integral or enum expression. Matching a case label
and executing its block; using break to prevent fall-through; default runs if no case
matches.
b) Compiler vs Interpreter (with diagram idea):
Compiler: Translating entire source code to machine code once, producing an
executable. Faster runtime, detecting many errors at compile-time.
Interpreter: Reading code line-by-line, executing immediately without a separate
executable. Slower runtime, easier debugging.
Diagram (textual):
Source Code → [Compiler] → Machine Code (Executable) → Run
Source Code → [Interpreter] → Execute line-by-line (No separate exe)
c) Loop and three types:
Loop: Repeating a block while a condition is true.
(i) for loop: Counting/definite iterations.
(ii) while loop: Pre-test loop, repeating while condition remains true.
(iii) do-while loop: Post-test loop, executing body at least once, then checking condition.
d) C++ program: read 15 numbers, 5 per row, then print:
Copy
#include <iostream>
using namespace std;
int main() {
int a[15];
for (int i = 0; i < 15; i++) cin >> a[i];
for (int i = 0; i < 15; i++) {
cout << a[i] << " ";
if ((i + 1) % 5 == 0) cout << "\n";
return 0;
}
e) Function overloading vs Recursion:
Function overloading: Multiple functions sharing a name but differing in parameter
types/count, chosen at compile-time.
Recursion: A function calling itself, breaking a problem into smaller subproblems,
requiring a base case to terminate.
Question 2: Variables, algorithm, comments, basic C++ output
a) Four general rules for declaring a variable:
(i) Declaring before use with a valid type.
(ii) Using a valid identifier (letters, digits, underscore; not starting with digit; no
keywords).
(iii) Initializing before reading its value.
(iv) Scope and lifetime following the block where declared; avoiding redeclaration
conflicts.
b) Meaning of algorithm:
A finite, ordered set of clear steps for solving a problem, producing correct output for
valid inputs.
c) Three types of comments with symbols:
(i) Single-line: // comment
(ii) Multi-line: /* comment /
(iii) Documentation/Doxygen style: /// or /* */ with tags (tooling-friendly)
d) Simple C++ program printing "Hello My Friend":
Copy
#include <iostream>
using namespace std;
int main() {
cout << "Hello My Friend" << endl;
return 0;
Question 3: Uses of programs, programmer, function
composition, design importance
a) Four major uses of a computer program:
(i) Automating tasks and workflows.
(ii) Processing, storing, and retrieving data.
(iii) Communication and interaction (UIs, networks).
(iv) Control and monitoring in systems (embedded, scientific, business).
b) Who is a computer programmer (with examples):
A person writing, testing, and maintaining code to solve problems. Examples: building a
payroll system in C++; writing Python scripts to analyze sales; implementing firmware in
C for sensors; developing a web API in Java.
c) Three compositions of functions:
(i) Sequential composition: Output of one becoming input of next: g(f(x)).
(ii) Nested composition: Multiple layers, h(g(f(x))).
(iii) Modular composition: Combining independent functions via interfaces, composing
behavior through calls.
d) Importance of program design to other programmers:
Improving readability, maintainability, and extensibility; reducing bugs; enabling
collaboration and onboarding; simplifying testing and reuse of modules.
Question 4: Operators and variables
a) Operator:
A symbol performing an operation on operands to produce a result (e.g., +, ==, &&).
b) Five types of operators used in programming:
(i) Arithmetic: +, -, *, /, %
(ii) Relational/Comparison: ==, !=, <, >, <=, >=
(iii) Logical: &&, ||, !
(iv) Assignment: =, +=, -=, *=, /=, %=
(v) Bitwise: &, |, ^, ~, <<, >>
c) Difference: Arithmetic vs Relational (with examples):
Arithmetic: Computing numeric results.
Examples: 7 + 3 = 10, 9 % 2 = 1.
Relational: Comparing values, yielding boolean.
Examples: 7 > 3 is true, 4 == 5 is false.
d) Local vs Global variables (two examples):
Global: Declared outside functions, accessible throughout program.
Example:
int g = 10; // global
int main() { cout << g; }
Local: Declared within a block/function, accessible only there.
Example:
int main() {
int x = 5; // local
if (true) { int y = 2; cout << x + y; }
// y not accessible here
}