Fix the following c++ code so that it will work properly to display the output. It is missing a function prototype function as well, use the floor or ceil function to fix the total output. #include #include using namespace std; /* This is a function that calculates the charge of parking for the given amount of time (in hours) */ double calculateCharges(double hours) { if (hours <= 3.0) { // If the time is less than 3 hours. return 20.0; // Charge a fixed amount of $20 } else { double charge = 20.0 + (hours - 3.0) * 5; // Calculate the charge, which is $20 + ($5/hour for excess of 3 hours) if (charge >= 50.0) { // If the charge is greater than $50 return 50.0; // Charge the maximum amount of $50 } return charge; } } int main() { // Declare the variables double hoursParked[3], // For storing the number of hours parked parkingCharges[3], // For storing the parking charges totalHours = 0, // For storing the total hours all cars were parked totalCharges = 0; // For storing the total charges of all cars   for (int i = 1; i <= 3; i++) { // Prompt the user for input of hours a car was parked cout << "Enter the hours Car " << i << " was parked: "; cin >> hoursParked[i - 1];   parkingCharges[i - 1] = calculateCharges(hoursParked[i - 1]); // Calculate the parking charges totalCharges += parkingCharges[i - 1]; // Add charges to total totalHours += hoursParked[i - 1]; // Add hours to total }   // Print the information header // Use setw() to set the width of the text. We have used a width of 10 in our case cout << setw(5) << "Car" << setw(10) << "Hours" << setw(10) << "Charge" << endl;   for (int i = 1; i <= 3; i++) { // Display the values for each car cout << fixed << setw(5) << i << setw(10) << setprecision(1) << hoursParked[i - 1] << setw(10) << setprecision(2) << parkingCharges[i - 1] << "\n"; } // Display the total values cout << fixed << setw(5) << "TOTAL" << setw(10) << setprecision(1) << totalHours << setw(10) << setprecision(2) << totalCharges << "\n"; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Fix the following c++ code so that it will work properly to display the output. It is missing a function prototype function as well, use the floor or ceil function to fix the total output.

#include<iostream>

#include<iomanip>

using namespace std;

/* This is a function that calculates the charge of parking for the given amount of time (in hours) */

double calculateCharges(double hours) {

if (hours <= 3.0) { // If the time is less than 3 hours.

return 20.0; // Charge a fixed amount of $20

}

else {

double charge = 20.0 + (hours - 3.0) * 5; // Calculate the charge, which is $20 + ($5/hour for excess of 3 hours)

if (charge >= 50.0) { // If the charge is greater than $50

return 50.0; // Charge the maximum amount of $50

}

return charge;

}

}

int main() {

// Declare the variables

double hoursParked[3], // For storing the number of hours parked

parkingCharges[3], // For storing the parking charges

totalHours = 0, // For storing the total hours all cars were parked

totalCharges = 0; // For storing the total charges of all cars

 

for (int i = 1; i <= 3; i++) { // Prompt the user for input of hours a car was parked

cout << "Enter the hours Car " << i << " was parked: ";

cin >> hoursParked[i - 1];

 

parkingCharges[i - 1] = calculateCharges(hoursParked[i - 1]); // Calculate the parking charges

totalCharges += parkingCharges[i - 1]; // Add charges to total

totalHours += hoursParked[i - 1]; // Add hours to total

}

 

// Print the information header

// Use setw() to set the width of the text. We have used a width of 10 in our case

cout << setw(5) << "Car" << setw(10) << "Hours" << setw(10) << "Charge" << endl;

 

for (int i = 1; i <= 3; i++) {

// Display the values for each car

cout << fixed << setw(5) << i << setw(10) << setprecision(1) << hoursParked[i - 1] << setw(10) << setprecision(2) << parkingCharges[i - 1] << "\n";

}

// Display the total values

cout << fixed << setw(5) << "TOTAL" << setw(10) << setprecision(1) << totalHours << setw(10) << setprecision(2) << totalCharges << "\n";

}

2. **6.12 (Parking Charges)**: A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage charges an additional $5.00 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. 

Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function `calculateCharges` to determine the charge for each customer. Your outputs should appear in the following format: 

---

This task involves writing a program to compute the parking fees based on hours parked, using specified rules on pricing. The parking fee structure consists of a base rate, additional hourly rates, and a daily maximum. The calculated charges need to be formatted and totaled conveniently for review.
Transcribed Image Text:2. **6.12 (Parking Charges)**: A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage charges an additional $5.00 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function `calculateCharges` to determine the charge for each customer. Your outputs should appear in the following format: --- This task involves writing a program to compute the parking fees based on hours parked, using specified rules on pricing. The parking fee structure consists of a base rate, additional hourly rates, and a daily maximum. The calculated charges need to be formatted and totaled conveniently for review.
### Parking Charges Summary

This table presents data related to parking durations and charges for three cars, as well as the total hours and charges for all cars combined.

| **Car** | **Hours** | **Charge** |
|---------|-----------|------------|
| 1       | 1.5       | 20.00      |
| 2       | 4.0       | 25.00      |
| 3       | 24.0      | 50.00      |
| **TOTAL** | **29.5** | **95.50**  |

**Explanation:**

- **Car 1:** Parked for 1.5 hours, resulting in a charge of $20.00.
- **Car 2:** Parked for 4.0 hours, with a charge of $25.00.
- **Car 3:** Parked for 24.0 hours, accruing a charge of $50.00.

Overall, the cumulative hours parked is 29.5, with a total charge of $95.50. This summary might be useful for analyzing parking duration and associated costs for different vehicles within a given timeframe.
Transcribed Image Text:### Parking Charges Summary This table presents data related to parking durations and charges for three cars, as well as the total hours and charges for all cars combined. | **Car** | **Hours** | **Charge** | |---------|-----------|------------| | 1 | 1.5 | 20.00 | | 2 | 4.0 | 25.00 | | 3 | 24.0 | 50.00 | | **TOTAL** | **29.5** | **95.50** | **Explanation:** - **Car 1:** Parked for 1.5 hours, resulting in a charge of $20.00. - **Car 2:** Parked for 4.0 hours, with a charge of $25.00. - **Car 3:** Parked for 24.0 hours, accruing a charge of $50.00. Overall, the cumulative hours parked is 29.5, with a total charge of $95.50. This summary might be useful for analyzing parking duration and associated costs for different vehicles within a given timeframe.
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education