Anda di halaman 1dari 4

Requirements for this paper:

Multi-choice cards: Non-programmable calculator: Open book examination? NO

Graph paper: Laptop / PC: YES

EXAMINATION/TEST: Examination QUALIFICATION: BSc


(1st Opp)

MODULE CODE: CISM 122 DURATION: 3 hour


MODULE DESCRIPTION: Programming and Problem Solving MAX: 100

EXAMINER(S): MR. T. J. MOEMI DATE: 2016/10/27

TIME: 14:00
MODERATOR: MR. F. L. LUGAYIZI

Student name: ........................................................................ University number: ....................................

Examination Instructions
1. Students are not allowed to handle cell phones in the examination room and cell phone accessories including but
not limited to earpieces, are not allowed.
2. Students must put their bags in front of the venue.
3. Students are subject to disciplinary procedures should they:
3.1 have books or notes in their possession (except during open book examinations);
3.2 make notes on question papers or any paper whatsoever except the official answer scripts they are provided
with;
3.3 attempt to assist another student, or attempt to obtain assistance from any student.
4. No student is allowed to leave the examination venue before half an hour of the examination session has elapsed.
5. No refreshments are allowed in the examination venue.
6. No pages may be removed from the answer scripts.
7. Before students leave the examination venue, answer scripts must be handed to the invigilators.
8. The attendance slip that also serves as an undertaking must be completed.
9. All examination answers must be written in black or blue ink.
10. NB. Multiple choice cards must be completed in pencil.

Eksamenvoorskrifte
1. Studente mag nie selfone in die eksamenlokaal hanteer nie en selfoontoebehore wat insluit maar nie tot oorfone
beperk is nie, is nie toelaatbaar nie.
2. Studente moet hul drasakke voor in die lokaal neersit.
3. Studente stel hulle aan dissiplinêre optrede bloot indien hulle:
3.1 enige boeke of notas by hulle sou hê (behalwe by oopboekeksamens);
3.2 aantekeninge maak op vraestelle of enige papier hoegenaamd buiten die antwoordskrifte aan hulle voorsien;
3.3 ‘n ander student probeer help of probeer om hulp te kry.
4. Geen student word toegelaat om die eksamenlokaal te verlaat binne die eerste halfuur van ‘n eksamensessie nie.
5. Geen verversings word in ‘n eksamenlokaal toegelaat nie.
6. Geen bladsye mag uit die antwoordskrif verwyder word nie.
7. Voordat studente die eksamenlokaal verlaat, moet die antwoordskrifte aan die toesighouers oorhandig word.
8. Die presensiestrokie wat ook as onderneming geld, moet voltooi word.
9. Studente moet slegs met swart of blou penne skryf.
10. NB. Multikeusekaarte moet slegs in potlood voltooi word.

CISM 122 1/4


Instructions: 1. Answer All Questions
2. Print your Name, Surname and Student Number at the end of each program
3. Answer Question 1 and Question 2 in you answer booklet
4. Submit .cpp files and Screenshots of the outputs on efundi

QUESTION 1 [30 MARKS]

1. Write a C++ statement that allows you to use cin, cout, and endl without the prefix std::.
[2 Marks]
2. What action must be taken before a variable can be used in a program? [2 Marks]
3. Which header file must be included to use the function steprecision()? [2 Marks]
4. Which header file must be included to use the function pow()? [2 Marks]
5. Suppose the input is 5. What is the value of alpha after the following C++ code executes?
cin >> alpha;
switch (alpha)
{
case 1:
case 2:
alpha = alpha + 2;
break;
case 4:
alpha++;
case 5:
alpha = 2 * alpha;
case 6:
alpha = alpha + 5;
break;
default:
alpha--;
} [2 Marks]

6. Write a for statement to add all the multiples of 3 between 1 and 100. [6 Marks]
7. Write the definition of a function that takes as input the three numbers. The function returns
true if the first number to the power of the second number equals the third number;
otherwise, it returns false. (Assume that the three numbers are of type double.) [4 Marks]

CISM 122 2/4


8. Consider the following function prototype:
void testDefaultParam(int a, int b = 7, char z = '*');
Which of the following function calls is correct?
a. testDefaultParam(5);
b. testDefaultParam(5, 8);
c. testDefaultParam(6, '#');
d. testDefaultParam(0, 0, '*'); [2 Marks]
9. What is array index out of bounds? Does C++ check for array indices within bounds?
[4 Marks]
10. Classify the following as classes or objects:
a) Maple trees
b) SAS Boeing 767 planes
c) Student
d) The chair you’re sitting on [4 Marks]

QUESTION2 [20MARKS]

a) List the four steps of the program development and design phase. [4 Marks]
b) Define the following terms:
 Algorithm [3 Mark]
 Array [3 Mark]
 Abstract data Type (ADT) [3 Marks]
c) Name three ways which an algorithm can be represented. [3 Marks]
d) Write a set of two statements that declares the following objects as ifstream objects, and
then opens them as text input files: inData.txt, prices.txt. [4 Marks]

QUESTION 3 [20 MARKS]

Write a program that mimics a calculator. The program should take as input two integers and the
operation to be performed. It should then output the numbers, the operator, and the result. (For
division, if the denominator is zero, output an appropriate message.) Some sample outputs follow:
3+4=7
13 * 5 = 65

CISM 122 3/4


QUESTION 4 [30 MARKS]

a) Construct a class named Rectangle that has double-precision data members named length and
width. The class should have member functions named perimeter() and area() to calculate a
rectangle’s perimeter and area, a member function named setdata() to set a rectangle’s length
and width, and a member function named showdata() that displays a rectangle’s length, width,
perimeter, and area. [20 Marks]
b) Include the Rectangle class constructed in Question 4 a) in a working C++ program.
[10 Marks]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TOTAL: 100

CISM 122 4/4

Anda mungkin juga menyukai