Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Marks: 100
Time: 2 hours
Instructions:
(1)
(2)
(3)
Question 1:
a) Define the following terms
i) A computer program
ii) A compiler
iii) An interpreter
.................................................................................................................................. [2+2+2]
b) Write a C++ program or a function that uses a FOR loop to find a product of integer
numbers between any two integers,
(
) with a specified incremental
step, k.
........................................................................................................................................ [14]
Question 2:
a) Identify all syntax errors in the following program
#include <iostream >
int m ain()
{
cout << CS2431 Test 01';
}
.......................................................................................................................................... [9]
b) The computation
, is the arithmetic
and n.
Write a C++ program or function that uses a WHILE loop to compute
.
........................................................................................................................................ [11]
Question 3:
a) Consider the following program segment
int sum = 0;
for(int k = 1; k <= n; k++)
{
cout << k = << k << sum = << sum << endl;
sum += k;
}
Test 01
Page -1/5-
.......................................................................................................................................... [8]
b) A factorial of a natural number n is defined as:
........................................................................................................................................ [10]
Question 5:
a) Say whether true (T) or false (F) in the following
i) A C++ variable can be an underscore character
ii) In C++, any arithmetic expression evaluating to a non-zero value is regarded as
representing the truth value: true.
iii) The two Boolean constants: true or false are integer expressions.
.................................................................................................................................. [2+2+2]
b) In a college, graduates are classified as Pass with Credit, Pass or Fail. The
classification is based upon the performance mean mark of the student. The
classification is as follows:
Mean Mark
Classification
65 or above
50 64
Pass
below 50
Fail
Using an IF statement construct, write a program or a function that accepts a mean mark
(type int) from the user and then outputs the appropriate classification message.
........................................................................................................................................ [14]
Test 01
Page -2/5-
Question 6:
Write a C++ program or function that can determine if the given number is prime or not as
follows:
1. The program accepts a number, N, from the user
2. The program then outputs a message whether N is prime or that N is not prime
HINT:
1.
Classification
75 or above
First Class
70 74
60 69
50 59
Pass
0 49
Fail
Write a C++ program or function that can classify students at NUL as follows:
1. The program allows the user to enter each course mark (type int) and its corresponding
credit hours (type int) a pair at the time, until the user has finished all the courses for this
particular student.
2. The program then displays the classification of the student based on the calculated
OWM and the given classification rules.
3. The program then allows the user to enter course information for the next student or quit
the program.
........................................................................................................................................ [20]
CS 2431 - Programming Fundamentals
Test 01
Page -3/5-
Test 01
Page -4/5-
Test 01
Page -5/5-