4.5k views
2 votes
A Water Amusement Park parking lot charges $24.00 minimum fee to park for up to 8 hours. The meter charges an additional $3.25 per hour for each hour in excess of eight hours. In addition, an extra $10 is charged if it's a recreational vehicle (RV). The maximum charge for any 24-hour period, for any type of vehicle is $70 .

Write a program that calculates and prints the customer information and parking charges to a text file (charge-report.txt) for each of five customers who parked their cars using the Water Amusement Park parking lot . The program should use the following functions:


getNameAndHoursParked(): a void function that asks for the employee’s full name and Number of Hours Parked. Use pass-by-reference to send these two items to main(). (10 points)

isVehicleNotAnRV: a value returning function that asks if vehicle is not a Recreational Vehicle and returns true or false. (5 points)

getFinalCharge(): a value returning function that calculates and returns the final charge for a customer to main(). (15 points)

The main() function should print the customer's full name, an indication of whether vehicle is a Recreational Vehicle, hours and charge for each customer to an output file (charge-report.txt) . (10 points)

in c++

User Grizzly
by
4.7k points

2 Answers

6 votes

Answer:

See explaination for the program code

Step-by-step explanation:

Program code below;

#include<iostream>

#include<fstream>

#include<iomanip>

using namespace std;

//function to return name and hours

void getNameAndHoursParked(string &name, int &hours)

{

cout<<"Enter the employee's full name: ";

getline(cin, name);

cout<<"Enter Number of Hours Parked: ";

cin>>hours;

}

//function to check if vehicle is not a Recreational Vehicle

bool isVehicleNotAnRV()

string rv;

cout<<"Is the vehicle is not a Recreational Vehicle: (Y/N)";

cin>>rv;

cin.ignore();

if(rv=="Y"

//function to calculates the parking charges

float getFinalCharge(int hours, bool rv)

{

float charge;

if(hours<=8)

charge = 24;

else

charge = 24 + (hours-8)*3.25;

if(rv) charge += 10;

if(hours<=24 && charge>70) charge = 70;

return charge;

}

//main function

int main()

{

//variable declaration

string name;

int hours;

ofstream ofs;

//open the file

ofs.open("charge-report.txt");

ofs<<left<<setw(15)<<"Full Name"<<setw(15)<<"Parking-Hours";

ofs<<setw(10)<<"Is-RV"<<"Charge"<<endl;

for(int i=0; i<5; i++)

{

//get name and parking hours

getNameAndHoursParked(name, hours);

//check if vehicle is not a Recreational Vehicle

bool rv =isVehicleNotAnRV();

//calculates the parking charges

float charge = getFinalCharge(hours, rv);

ofs<<left<<setw(20)<<name<<setw(10)<<hours;

ofs<<setw(10)<<boolalpha<<rv<<"$"<<charge<<endl;

}

//close the file

ofs.close();

return 0;

}

User Samyer
by
5.1k points
2 votes

Answer:

  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. void getNameAndHoursParked(string &name, int &hour){
  5. cout<<"Enter employee name: ";
  6. cin>>name;
  7. cout<<"Enter parking hours: ";
  8. cin>>hour;
  9. }
  10. bool isVehicleNotAnRV(){
  11. int response;
  12. cout<<"Is vehicle an RV: (1) Yes (2) No: ";
  13. cin>>response;
  14. if(response == 1){
  15. return true;
  16. }else{
  17. return false;
  18. }
  19. }
  20. double getFinalCharge(int hour, bool rv){
  21. double charge;
  22. if(hour <=8){
  23. charge = 24;
  24. }
  25. else{
  26. hour = hour - 8;
  27. charge = 24 + hour * 3.25;
  28. }
  29. if(rv==true){
  30. charge += 10;
  31. }
  32. if(charge > 70 ){
  33. charge = 70;
  34. }
  35. return charge;
  36. }
  37. int main()
  38. {
  39. string employeeName;
  40. int hour;
  41. bool rv;
  42. double final_charge;
  43. getNameAndHoursParked(employeeName, hour);
  44. rv = isVehicleNotAnRV();
  45. final_charge = getFinalCharge(hour, rv);
  46. ofstream file;
  47. file.open ("charge-report.txt");
  48. file << "Customer name: " + employeeName + "\\";
  49. file << "Parking charge $"<< final_charge;
  50. file.close();
  51. return 0;
  52. }

Step-by-step explanation:

Firstly, write the function getNameAndHoursParked to get employee name and number of parking hour. To enable pass by reference, the two parameters of this function are the reference variables (Line 6 - 11). These reference variables, name and hour, are associated with the variable employeeName and hour in the Main Program. Any values assigned to the two reference variables in the function will directly be set to employeeName and hour in the Main Program.

Next create a function isVehicleNotAnRV to enable user to input if a vehicle is a RV or not and return either true or false (Line 13 - 23).

Next create getFinalCharge function and create if else if statements to consider multiple parking hour options and apply the formula to calculate and return the total charge (Line 25 -45).

In the main program, declare all the required variables and call the functions to get all the required parking info (Line 49 - 56). Lastly output employee name and final charge to a file (Line 58 - 62).

User Michael Bobick
by
5.4k points