You are on page 1of 17

CONFIDENTIAL CS/AUG 2020/CSC128

UNIVERSITI TEKNOLOGI MARA


FINAL ASSESSMENT (ANSWER SHEET)

COURSE : FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

COURSE CODE : CSC128

DATE : 4 AUGUST 2020

TIME : 9.00 am- 12.30 pm (including submission time)

SEMESTER : MAC – JULY 2020

INSTRUCTIONS TO CANDIDATES:

1. This question paper consists of one (1) part:

2. Answer ALL questions in this file. Start each answer on a new page.

3. Please save your file in PDF format.

*Please fill all this information below.

NAME : Mimi Nur Nabila binti Alias

STUDENT ID : 2019293128

GROUP : EC1102N

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 8 printed pages

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

PART A

QUESTION 1

Create a flowchart that calculates a Health Screening charge for a patient. Your flowchart
should prompt the user to enter patient’s category ( A – adult / C – children / S – senior citizen).
Display “Error: Invalid Patient Category” if the user enters a wrong input. Then the flowchart
will calculate and display the total charge. An additional charge of RM50.00 will be incurred if
the user selected 1-hour rapid test result. The total charge is determined by the following Table
1.1.

Table 1.1 Health Screening Charges

1-hour rapid test result


Category Screening Fee
(optional)

A RM 148.00 + RM 50.00

C&S RM 110.00 + RM 50.00

(5 marks)

Start

Display “Enter patient’s category (A-adult /


C-children / S-senior citizen) : “;

Get category

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

Display “Do you want to get 1-hour rapid


test result (Y-yes / N-no) : “;

Get rapidTest

If ( category == ‘A’ )
&& ( rapidTest == ‘Y’ )

Yes

Payment = 148 + 50 No

Else if ( category ==
‘C’ || ‘S’ ) && (
rapidTest == ‘Y’ )

Yes
Payment = 110 +50 No

Else if ( category ==
‘A’) && ( rapidTest !=
‘Y’ )

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

Yes

No
Payment = 148

Else if ( category
== ‘C’ || ‘S’ ) && (
rapidTest != ‘Y’ )

Yes

Payment = 110 No

Else

Display “Error: Invalid Patient


Category”;

Display “Total Payment is RM “,payment;

End

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

QUESTION 2

UiTM will organize an eating competition. Points will be given based on the food weight as
shown in Table 2.1 below:

Table 2.1 Point Allocation Based on Food Weight Consumed

Weight (gram) Age Points


Below or equal than 12 years 2
Below than 100
More than 12 1
Below or equal than 12 years 3
More or equal than 100
More than 12 2

Write the program segment where the weight and age will be entered by the participant.
Then display the participant’s score. The calculation of the score is based on following
formula.

Score = Point * total weight in grams

(5 marks)

#include<iostream>

using namespace std;

int main()

int weight, age, score;

cout<<”Enter weight (gram): “;

cin>>weight;

cout<<”Enter age: “;

cin>>age;

if ( weight <100 )

if ( age <= 12 )

score = 2 * weight;

else if ( age >12 )

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

score = 1 * weight;

else if ( weight >= 100 )

if ( age <= 12 )

score = 3 * weight;

else if ( age > 12 )

score = 2 * weight;

cout<<”Your Score : “<<score<<endl;

return 0;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

QUESTION 3

Subway requested to develop a program that can take orders using self-order machine for
those who wants to buy their sandwiches of the day.

You are required to write a code segment that will ask the customer, how many sets are they
ordering. By using for loop, your program will be repeated based on the number of sets that
they’ve entered. For each iteration, the program should ask the user to choose the side dish
type either [1- Chips] or [2-Cookies] to make it a meal set. Count the number of chips and
cookies that had been chosen.

Then the program will display total number of chips and cookies and total price in two decimal
places as in Figure 3.1 below where the price for each set is RM10.90.

Number of meal sets :3


Choose side for set 1 :
1- Chips, 2- Cookies
1
Choose side for set 2 :
1- Chips, 2- Cookies
1
Choose side for set 3 :
1- Chips, 2- Cookies
2
------------------------------------
Mealset with chips: 2
Mealset with cookies: 1
Total Price : RM32.70

Figure 3.1 Sample Output for the C++ Program

(5 marks)

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double total;
int meal, sides;
int calcChips=0, calcCookies=0;
cout<<"Number of meal sets: ";
cin>>meal;
for(int i=1; i<=meal; i++)
{

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

cout<<"Choose side for set "<<i<<": "<<endl;


cout<<"1- Chips, 2- Cookies "<<endl;
cin>>sides;
if(sides % 2 == 0)
{
calcChips++;
}
else
{
calcCookies++;
}
}
total=10.90 *meal;
cout<<"Meal set with chips: "<<calcChips<<endl;
cout<<"Meal set with cookies: "<<calcCookies<<endl;
cout<<"Total price : RM "<<total<<endl;
return 0;
}

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

QUESTION 4

Write a C++ program segment based on the following problems.

Display the lowest odd number among ten positive integer numbers between 1 to 100
entered by the user. Given is the sample output screen:

Enter ten positive integer numbers between 1 to 100:

1) 78

2) 65

3) 22

4) 56

5) 99

6) 2

7) 3

8) 15

9) 73

10) 85

The lowest odd number is = 3

Figure 4.1 Sample Output for the C++ Program

(5 marks)

#include<iostream>

using namespace std;

int main()

int num, n = 1, i = 0;

int minimum = 9999999;

cout<<"Enter ten positive integer numbers between 1 to 100: "<<endl;

while ( i < 10 )

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

cout<<n++<<") ";

cin>>num;

i++;

if ( num % 2 != 0 )

if ( num < minimum )

minimum = num;

cout<<"\nThe lowest odd number is = "<<minimum<<endl;

return 0;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

QUESTION 5

Johor Taekwondo Club is organizing Johor Open Taekwondo Championship. The following
Table 5.1 shows the details of the championship:

Table 5.1 Johor Open Taekwondo Championship Registration Charges

Disciplines Categories Fee (RM)


15 – 17 years old
50
(Junior)
Kyorugi (K)
18 – 30 years old
60
(Senior)
12 – 14 years old
45
(Cadet)
Poomsae (P)
15 – 17 years old
55
(Junior)
* 10% discount is given if the team is registered under Johor Taekwondo Club

As a programmer hired by the club, you are required to write a C++ program for the
championship registration system based on the following tasks:

a) Write a function definition named participant(...) that executes the following


tasks:
i. Ask user to enter discipline code (K/P), participant’s name and participant’s
age.
ii. This function will assign fee for each of the discipline categories and display
PARTICIPANT’S SLIP as shown in the given sample input/output.
iii. The program should display “Invalid age!!” and “Invalid discipline code!!” error
messages if the user enters an invalid range of age and discipline code.
iv. This function also will calculate and then return total Kyorugi fee and total
Poomsae fee through its parameters.
b) 10% discount will be given if the team is registered under Johor Taekwondo Club.
Write function discount(...) that receives membership status and total fee before
discount. The function will calculate and return the discount fee given.
c) Write a main() program which performs the following tasks:
i. Ask users to enter their team’s name.
ii. Call the function named participant(...)and send total Kyorugi fee and
total Poomsae fee through its parameter to get and display participant’s details.
The function will be called repeatedly until user requests to stop.
iii. Calculate the total fee by sump up the total Kyorugi fee and total Poomsae fee
that returned by function participant(...).
iv. Ask user to enter the team’s Johor Taekwondo Club membership status.
v. Call the function named discount(...)and send team’s membership status
and total fee.
vi. Calculate the total fee after discount and display TEAM’S REGISTRATION
SLIP as shown in the given sample input/output.
vii. Format your outputs to two decimal places.

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

The sample input and output of the program shown as below (The shaded texts are the inputs
for the system) :

-----------------------------------------------------
JOHOR OPEN TAEKWONDO CHAMPIONSHIP REGISTRATION SYSTEM
-----------------------------------------------------

Team Name: EXCELLENT TAEKWONDO CLUB

Discipline code <K|P>: K


Participant's name: MOHD ARIS BIN MOHD ABU
Participant's age: 17

-----------PARTICIPANT'S SLIP------------
Name : MOHD ARIS BIN MOHD ABU
Discipline : Kyorugi
Category : Junior
Fee : RM50
-----------------------------------------

Do you want to add new participant for your team? <Y|N> : Y

Discipline code <K|P>: L


Participant's name: KALAI A/L MUTHU
Participant's age: 18

-----------PARTICIPANT'S SLIP------------
Name : KALAI A/L MUTHU
Discipline : Invalid Code!!
Category : N/A
Fee : RM0
-----------------------------------------

Do you want to add new participant for your team? <Y|N> : Y

Discipline code <K|P>: K


Participant's name: KALAI A/L MUTHU
Participant's age: 18

-----------PARTICIPANT'S SLIP------------
Name : KALAI A/L MUTHU
Discipline : Kyorugi
Category : Senior
Fee : RM60
-----------------------------------------

Do you want to add new participant for your team? <Y|N> : Y

Discipline code <K|P>: P


Participant's name: CHERYL TAN
Participant's age: 15

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

-----------PARTICIPANT'S SLIP------------
Name : CHERYL TAN
Discipline : Poomsae
Category : Junior
Fee : RM55
-----------------------------------------

Do you want to add new participant for your team? <Y|N> : Y

Discipline code <K|P>: K


Participant's name: SITI AISHAH BINTI AHMAD
Participant's age: 14

-----------PARTICIPANT'S SLIP------------
Name : SITI AISHAH BINTI AHMAD
Discipline : Kyorugi
Category : Invalid age!!
Fee : RM0
-----------------------------------------

Do you want to add new participant for your team? <Y|N> : N

Is your team registered under Johor Taekwondo Club? <Y|N>: Y

********EXCELLENT TAEKWONDO CLUB REGISTRATION SLIP********

Total Kyorugi Fee : RM110.00


Total Poomsae Fee : RM55.00
Discount Fee : RM16.50
Total Fee (Before Discount) : RM165.00
Total Fee (After Discount) : RM148.50
Figure 5.1 Sample Output for the C++ Program

(20 marks)

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

double participant(double, double);


double discount(char, double);

int main()
{
char choice;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

string team;
double total, discountFee, totalFee;
double totalKyorugi = 0, totalPoomsae = 0;
cout<<"-----------------------------------------------------"<<endl;
cout<<"JOHOR OPEN TAEKWONDO CHAMPIONSHIP
REGISTRATION SYSTEM"<<endl;
cout<<"-----------------------------------------------------"<<endl;
cout<<"\nTeam Name: ";
getline(cin,team);
cout<<endl;
total = participant(totalKyorugi, totalPoomsae);
cout<<endl;
cout<<"Is your team registered under Johor Taekwondo
Club? <Y|N>: ";
cin>>choice;
discountFee = discount(choice, total);
totalFee = total - discountFee;
cout<<endl;
cout<<"******EXCELLENT TAEKWONDO CLUB
REGISTRATION SLIP*******"<<endl<<endl;
cout<<"Total Kyorugi Fee :
RM"<<setprecision(2)<<totalKyorugi<<endl;
cout<<"Total Poomsae Fee :
RM"<<totalPoomsae<<endl;
cout<<"Discount Fee :
RM"<<discountFee<<endl;
cout<<"Total Fee (Before Discount): RM"<<total<<endl;
cout<<"Total Fee (After Discount) :
RM"<<totalFee<<endl;
}
double participant(double totalKyorugi, double totalPoomsae)
{
char code, choice;
string name, discipline, category;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

double fee, age, total;


do
{
cout<<"Discipline code <K|P>: ";
cin>>code;
cout<<"Participant's name: ";
cin.ignore();
getline(cin, name);
cout<<"Participant's age: ";
cin>>age;
if(code == 'K')
{
discipline = "Kyorugi";
if(age >= 15 && age <= 17)
{
category = "Junior";
fee = 50;
}
else if(age >= 18 && age <= 30)
{
category = "Senior";
fee = 60;
}
else
{
cout<<"Invalid age!!"<<endl;
break;
}
totalKyorugi = totalKyorugi + fee;
}
else if (code == 'P')
{

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

discipline = "Poomsae";
if (age >= 12 && age <= 14)
{
category = "Cadet";
fee = 45;
}
else if (age >= 15 && age <= 17)
{
category = "Junior";
fee = 55;
}
else
{
cout<<"Invalid age!!"<<endl;
break;
}
totalPoomsae = totalPoomsae + fee;
}
else
{
cout<<"----------PARTICIPANT'S SLIP----------"<<endl;
cout<<"Name :"<<name<<endl;
cout<<"Discipline : Invalid Code!!"<<endl;
cout<<"Category : N/A"<<endl;
cout<< "Fee : RM0"<<endl;
cout<< "--------------------------------------"<<endl;
break;
}
cout<< "\n----------PARTICIPANT'S SLIP----------
"<<endl;
cout<< "Name :"<<name<<endl;
cout<< "Discipline :"<<discipline<<endl;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/AUG 2020/CSC128

cout<< "Category :"<<category<<endl;


cout<<"Fee :RM"<<fee<<endl;
cout<<"--------------------------------------"<<endl;
cout<<endl;
cout<<"Do you want to add new participant for your
team? <Y|N>: ";
cin>>choice;
}
while (choice == 'Y');
total = totalKyorugi + totalPoomsae;
return total;
}

double discount(char choice, double total)


{
double discountFee = 0;
if (choice == 'Y')
{
discountFee = 0.1 * total;
}
return discountFee;
}

END OF QUESTIONS

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like