0% found this document useful (0 votes)
79 views

Problem 3

The document describes an assignment to write a C++ program that calculates parking fees based on duration. It includes the parking rate table, a flowchart showing the program logic, the source code, and a section for the output. The program uses if/else statements to calculate the fees based on hourly rates that decrease after 1 hour, 4 hours, and 6 hours. It displays the total charges and handles errors if duration exceeds 10 hours.

Uploaded by

Athirah Kamil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Problem 3

The document describes an assignment to write a C++ program that calculates parking fees based on duration. It includes the parking rate table, a flowchart showing the program logic, the source code, and a section for the output. The program uses if/else statements to calculate the fees based on hourly rates that decrease after 1 hour, 4 hours, and 6 hours. It displays the total charges and handles errors if duration exceeds 10 hours.

Uploaded by

Athirah Kamil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1

CSC 425 (C++ Programming): Assignment 2

Question

The following table shows the car parking rate according to parking duration.

PARKING DURATION First hour (1st hour) The next 3 hours (2nd, 3rd and 4th hours) The next 2 hours (5th and 6th hours) The next 4 hours (7th, 8th, 9th and 10th hours)

PARKING RATE (RM) 1.00 50 cents/hour 40 cents/hour 30 cents/hour

Write a program that obtains the duration of parking in hour from the user. Assume that the parking duration cannot exceed 10 hours. Display the output as the following format.

CSC 425 (C++ Programming): Assignment 2

Flowchart

START

write Duration of Parking

read hr

(hr<=1) and (hr>0) F (hr>=2) and (hr<=4) F (hr>=5) and (hr<=6) F (hr>=7) and (hr<=10)

RM 1

T sub = hr - 1 tot_c = (sub*0.5) + 1

T sub = hr - 4 tot_c = (sub*0.4) + 2.50

T sub = hr - 6 tot_c = (sub*0.3) + 3.30

F write Error! You Have Reached The Quota

write Thank you

END

CSC 425 (C++ Programming): Assignment 2

Source code :

#include<iostream> #include<cmath> using namespace std; int main() { cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<"\n\tSyarikat Parking Mesra Sdn. Bhd"; cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++";

float hr, sub, tot_c; cout<<"\n\tDuration of Parking \t:"; cin>>hr; if ((hr<=1)&&(hr>0)) { cout<<"\tTotal Charges \t\t:RM 1 "; } else if ((hr>=2)&&(hr<=4)) { sub = (hr-1); tot_c = (sub * 0.5) + 1; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }

CSC 425 (C++ Programming): Assignment 2

else if ((hr>=5)&&(hr<=6))` { sub = hr-4; tot_c = (sub*0.4) + 2.5; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }

else if ((hr>=7)&&(hr<=10)) { sub = hr-6; tot_c = (sub*0.3) + 3.30; cout<<"\tTotal Charges \t\t:RM "<<tot_c; }

else cout<<"\n\t\tError! You Have Reached The Quota."; cout<<"\n\n\t\t\t==Thank you=="; cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++";

cout<<"\n"; system("pause"); return 0; }

CSC 425 (C++ Programming): Assignment 2

Output

CSC 425 (C++ Programming): Assignment 2

CSC 425 (C++ Programming): Assignment 2

CSC 425 (C++ Programming): Assignment 2

CSC 425 (C++ Programming): Assignment 2

You might also like