AACS1084 PCD II (Question) - Final 202201
AACS1084 PCD II (Question) - Final 202201
AACS1084 PCD II (Question) - Final 202201
APRIL/MAY EXAMINATION
Instructions to Candidates:
Question 1
a) By using typedef, declare a structure named Customer with the following members:
name (example: Lily Tan)
telNo (example: 012-3456789)
(2 marks)
d) Define a variable reserve of type Reservation (as declared in Question 1c) and initialize it with
the values given in the above examples. (4 marks)
e) Write a C program segment to display the reservation’s details with suitable labels as shown in
Figure 1.
***Reservation Details***
Customer Name: Lily Tan
Tel No: 0123456789
Arrival Date: 27-5-2022
Arrival Time: 18:30
Total Pax: 8
Figure 1: sample output
(5 marks)
(i) Update the reservation arrival month of the variable reserve to 9. (2 marks)
(ii) Change the first letter of the customer’s name of the variable reserve to ‘B’. (2 marks)
(iii) Define an array called reserveArr of type Reservation which can hold 50 reservation
details. Assign all the contents of variable reserve to the last element of reserveArr.
(4 marks)
[Total: 25 marks]
Question 2
Refer to Figure 2: coursework.txt, which contains the coursework records for a course.
Figure 2: coursework.txt
b) Use fpR file pointer to open the text file coursework.txt for reading and fpW file pointer to open
another text file repeat.txt for writing. (4 marks)
c) By using a loop, read each record from the coursework.txt file and calculate the total coursework
marks based on the formula below:
total coursework marks = assignment mark + test mark
Write the student id and student name of students with total coursework marks below 50 into
the repeat.txt file as shown in Figure 3. At the end of the file, display the total number of repeat
students.
[Note: Your answer shall include declaring the necessary variables.]
Figure 3: repeat.txt
(15 marks)
Question 2 (Continued)
[Total: 25 marks]
Question 3
a) In the context of binary file, write C statements to perform the following tasks:
Declare a file pointer named fptr to open the binary file movies.bin for appending.
Check if the movies.bin file is opened successfully. Otherwise display an error message
and exit the program.
Assume the following variables have been defined, append the variables’ values into
the movies.bin file by using THREE (3) separate statements:
char name[50] = “Happy Holiday”;
int releaseYear = 2022;
double rating = 7.8;
c) Identify the visibility and storage classes for each of the variables in the following program
skeleton and complete the table given below:
1 #include <stdio.h> 8
2 void function1(); 9 int b;
3 10
4 main() { 11 void func() {
5 int a 12 static int c;
6 … 13 …
7 } 14 }
[Total: 25 marks]
Question 4
(i) Write a function named calCommission that accepts totalSale as double data type input
parameter. The function should calculate the commission and return the value to the calling
function. The formula used to perform the calculation is shown below:
commission = totalSale × 0.02
(4 marks)
(ii) Write another function named getBonus that receives totalSale as double data type input
parameter. Return the bonus as output parameter based on the following:
Total sale Bonus
Below 5000 0.00
5000 – 7999 300.00
8000 and above 500.00
(7 marks)
[Total: 25 marks]