Professional Documents
Culture Documents
CSC404 FEB 2023
CSC404 FEB 2023
COURSE PROGRAMMING II
COURSE CODE CSC404
EXAMINATION FEBRUARY 2023
TIME 3 HOURS
INSTRUCTIONS TO CANDIDATES
2. Answer ALL questions in the Answer Booklet. Start each answer on a new page.
3. Do not bring any material into the examination room unless permission is given by the
invigilator.
4. Please check to make sure that this examination pack consists of:
PART A
QUESTION 1
a) The following program segment contains three (3) errors. Rewrite the correct program
segment.
i n t number;
i n t *p;
s t r i n g player="Mokhtar D a h a r i " ;
p = namel;
cout«&p; / / d i s p l a y t h e a d d r e s s of a p l a y e r u s i n g a p o i n t e r
c o u t « " t h e a d d r e s s of p i s " « & p ; / / d i s p l a y t h e a d d r e s s of p
(5 marks)
i) Write a function named getMarks() to prompt user to input marks for 5 subjects. The
function uses only 1 variable named marks and for loop statement to input and find
the average of marks obtained by the students. Then, the average of marks is
returned to the calling function using passing by value method.
(5 marks)
(5 marks)
iii) The following program segment is used to call the functions named getMarks ()
and d i s p l a y R e s u l t ( ) . However, the program segment contains errors. Find and
correct the errors.
#include <iostream>
using namespace std;
void getmarks(float&) ;
void displayResult(int & ) ;
int main ()
{
float average;
getMarks();
displayResult(&average) r
cout<<"The average is"«average;
}
(5 marks)
QUESTION 2
Given the following table that stores the marks of 3 courses for 3 students:
(2 marks)
b) Next, find the total marks for each student and store them in 1 dimensional array named
t o t a l [ ] . Display all values in t o t a l [ ] .
(8 marks)
QUESTION 3
a) Table 3 listed the amount spend per day for food of five students in a week. For example,
for day one, Student 1 spend RM90, while for the same day, Student 2 spend RM35
and so on as shown in the Table 3.
i) Declare and initialize a two-dimensional array to store the amount spend as in Table
3.
(2 marks)
ii) Write a program segment to compute and display the average spending by each
day.
(4 marks)
iii) Write a program segment to find and display the day with the highest spending for
the third person. The output should look like as the following example:
The highest spending for the third person is RM XXX on Day XXX
(4 marks)
Write a function definition named muisame ( ) that receives both arrays. The function
compares each element of both arrays at the same index. If both values are even,
multiply both values and store into an array named Group. Then, display the contents
of the array Group.
(10 marks)
QUESTION 4
struct Books
{ string title;
float price;
string publisher;
};
i) Write a function named inputBookDataO that asks the user to enter all information
of a book.
(4 marks)
ii) Given the declaration:
Book b o o k l ;
(1 mark)
struct Lecturer
{ string name;
double salary;
int university; // codes used: 1-UiTM, 2-UKM
};
Lecturer people[MAX];
Assuming the array already contains data, write the codes to display the list of UiTM
lecturers and UKM lecturers separately, then calculate and compare the average
salary of lecturers from the 2 universities to see which university has the higher
average salary.
(15 marks)
PARTB
QUESTION 1
a) Write a program in C++ to declare two dynamic integer variables named numl and
num2. Input a number into each numl and num2. Find and display the sum of the
numbers.
(5 marks)
i) Declare a string pointer variable named pText. Set the value of pText to the
address of t e x t . Use the pointer pText to do the operations in Question 1 b) ii and
b) iii.
ii) Use a loop to count and display how many strings "a" in string t e x t .
iii) Use a loop to determine and display if there are any vowels in string t e x t . Vowels
are letters a, e, i, o and u.
(10 marks)
QUESTION 2
a) Write C++ statement(s) to declare an integer array named marks with size 30 and an
integer pointer variable named pMarks. Set the value of pMarks to the address of marks.
Using a loop, store marks values into the array using pointer pMarks.
(5 marks)
(5 marks)
c) Write C++ statements to find and display the grade from the array in 2a. The grade is
determined based on Table 4.
Table 4: Grade
Marks Grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
(5 marks)