AACS1084 PCD II (Question) - Final 202201

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

KOLEJ UNIVERSITI TUNKU ABDUL RAHMAN

FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY

ACADEMIC YEAR 2021/2022

APRIL/MAY EXAMINATION

AACS1084 PROGRAMMING CONCEPTS AND DESIGN II

MONDAY, 9 MAY 2022 TIME: 2.00 PM – 4.00 PM (2 HOURS)

DIPLOMA IN SCIENCE (INTERNET TECHNOLOGY)


DIPLOMA IN COMPUTER SCIENCE
DIPLOMA IN INFORMATION TECHNOLOGY
DIPLOMA IN INFORMATION SYSTEMS
DIPLOMA IN SOFTWARE ENGINEERING

Instructions to Candidates:

Answer ALL questions. All questions carry equal marks.


2
AACS1084 PROGRAMMING CONCEPTS AND DESIGN II

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)

b) Declare a tagged structure named DateTime with the following members:


 day (example: 27)
 month (example: 5)
 year (example: 2022)
 hour (example: 18)
 minutes (example: 30)
(2 marks)

c) Declare a tagged structure named Reservation with the following members:


 customer (structure of Customer as declared in Question 1 a)
 arrival (structure of DateTime as declared in Question 1 b)
 totalPax (example: 8)
(4 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)

f) Write C statements to perform the following tasks:

(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)

This question paper consists of 4 questions on 5 printed pages.


3
AACS1084 PROGRAMMING CONCEPTS AND DESIGN II

Question 1(f) (Continued)

(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.

<student id>|<student name>|<assignment mark>|<test mark>

Figure 2: coursework.txt

a) Declare two file pointers named fpR and fpW. (2 marks)

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)

This question paper consists of 4 questions on 5 printed pages.


4
AACS1084 PROGRAMMING CONCEPTS AND DESIGN II

Question 2 (Continued)

d) Give a common purpose for using a file in C programming. (2 marks)

e) State 2 characteristics of a text file. (2 marks)

[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;

 Close the movies.bin file for appending.


(13 marks)

b) Explain the following types of coupling:

(i) Data coupling (2 marks)

(ii) Control coupling (2 marks)

(iii) Common coupling (2 marks)

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 }

This question paper consists of 4 questions on 5 printed pages.


5
AACS1084 PROGRAMMING CONCEPTS AND DESIGN II

Question 3(c) (Continued)

Variable Visibility Storage Class


a at line 5
b at line 9
c at line 12
(6 marks)

[Total: 25 marks]

Question 4

a) State THREE (3) benefits of using a function in C programming. (6 marks)

b) Write C statements to perform the following functions:

(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)

(iii) Write a main function to accomplish the following:


 Declare all the necessary variables.
 Prompt the user to enter a totalSale.
 Call the calCommission function defined in Question 4 b) (i) to obtain the
commission value.
 Call the getBonus function defined in Question 4 b) (ii) to determine the bonus.
 Display the commission and bonus values on the output screen.
(8 marks)

[Total: 25 marks]

This question paper consists of 4 questions on 5 printed pages.

You might also like