Question

This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...

This is C++ code for parking fee management program

#include <iostream>
#include <iomanip>

using namespace std;

void input(char& car, int& ihour,int& imin, int& ohour, int& omin);
void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total);
void parkingCharge (char car, int round, double& total);
void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total);


int main()
{
char car;
int ihour; int imin; int ohour; int omin; int phour; int pmin; int round;
double total;
input(car, ihour, imin, ohour, omin);
time(car, ihour, imin, ohour, omin, phour, pmin, round, total);
print(car, ihour, imin, ohour, omin, phour, pmin, round, total);
return 0;
}

void input(char& car, int& ihour,int& imin, int& ohour, int& omin)
{
cout << "Type of vehicle? ";
cin >> car;
cout << "Hour vehicle entered lot (0 - 24)? ";
cin >> ihour;
cout << "Minute vehicle entered lot (0 - 60)? ";
cin >> imin;
cout << "Hour vehicle left lot (0 - 24)? ";
cin >> ohour;
cout << "Minute vehicle left lot (0 - 60)? ";
cin >> omin;
cout << endl;
return ;
}

void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total)
{
if (omin < imin)
{
omin= omin + 60;
ohour = ohour - 1;
}
phour = ohour - ihour;
pmin = omin - imin;
if (pmin != 0)
{
round = phour + 1;
}
else
round = phour;
parkingCharge (car, round, total);
return ;
}

void parkingCharge (char car, int round, double& total)
{
switch (car)
{
case 'C' : if (round > 3)
total = (round - 3) * 1.50;
else
total = 0.00;
break;
case 'T' : if (round > 2)
total = (round - 2) * 2.30 + 2;
else
total = round * 1.00;
break;
case 'B' : if (round > 1)
total = 2 + (round - 1) * 3.70;
else
total = round * 2.00;
break;
default : cout << "\nVehicle not valid!\n";

break;
}
return ;
}

void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total)
{
cout << "\n\tPARKING LOT CHARGE\n\n";
cout << "Type of vehicle:\t\t";
switch (car)
{
case 'c': cout << " CAR" << endl;
break;
case 'C': cout << " CAR" << endl;
break;
case 't': cout << " TRUCK" << endl;
break;
case 'T': cout << " TRUCK" << endl;
break;
case 'b': cout << " BUS" << endl;
break;
case 'B': cout << " BUS" << endl;
break;
}
cout << " TIME-IN" << "\t\t\t " << ihour << " : " << imin << endl;
cout << " TIME-OUT" << "\t\t\t " << ohour << " : " << omin << endl;
cout << "\t\t\t\t" << "----------" << endl;
cout << " PARKING TIME" << "\t\t\t " << phour << " : " << pmin << endl;
cout << " ROUNDED TOTAL" << "\t\t\t " << round << endl;
cout << "\t\t\t\t" << "----------" << endl;
cout << fixed;
cout << " TOTAL CHARGE" << "\t\t\t " << '$' << setprecision(2) << total << endl;
return ;
}

but, I can not calculate the total charge fee... anyone help me please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Use this c++ code

// the bug was in switch case

#include <iostream>
#include <iomanip>

using namespace std;

void input(char& car, int& ihour, int& imin, int& ohour, int& omin);
void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total);
void parkingCharge(char car, int round, double& total);
void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total);


int main()
{
   char car;
   int ihour; int imin; int ohour; int omin; int phour; int pmin; int round;
   double total=0;
   input(car, ihour, imin, ohour, omin);
   time(car, ihour, imin, ohour, omin, phour, pmin, round, total);
   print(car, ihour, imin, ohour, omin, phour, pmin, round, total);
   //pause
   system("pause");
   return 0;
}

void input(char& car, int& ihour, int& imin, int& ohour, int& omin)
{
   cout << "Type of vehicle? ";
   cin >> car;
   cout << "Hour vehicle entered lot (0 - 24)? ";
   cin >> ihour;
   cout << "Minute vehicle entered lot (0 - 60)? ";
   cin >> imin;
   cout << "Hour vehicle left lot (0 - 24)? ";
   cin >> ohour;
   cout << "Minute vehicle left lot (0 - 60)? ";
   cin >> omin;
   cout << endl;
   return;
}

void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total)
{
   if (omin < imin)
   {
       omin = omin + 60;
       ohour = ohour - 1;
   }
   phour =abs( ohour - ihour);
   pmin = abs(omin - imin);
   if (pmin != 0)
   {
       round = phour + 1;
   }
   else
       round = phour;
   parkingCharge(car, round, total);
   return;
}

void parkingCharge(char car, int round, double& total)
{
   switch (car)
   {
   case 'C':
   case 'c':
       if (round > 3)
       total = (round - 3) * 1.50;
           else
       total = 0.00;
       break;
   case 'T':
   case 't':
       if (round > 2)
       total = (round - 2) * 2.30 + 2;
           else
       total = round * 1.00;
       break;
   case 'B':
   case 'b':
       if (round > 1)
       total = 2 + (round - 1) * 3.70;
           else
       total = round * 2.00;
       break;
   default:
       cout << "\nVehicle not valid!\n";

       break;
   }
   return;
}

void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total)
{
   cout << "\n\tPARKING LOT CHARGE\n\n";
   cout << "Type of vehicle:\t\t";
   switch (car)
   {
   case 'c': cout << " CAR" << endl;
       break;
   case 'C': cout << " CAR" << endl;
       break;
   case 't': cout << " TRUCK" << endl;
       break;
   case 'T': cout << " TRUCK" << endl;
       break;
   case 'b': cout << " BUS" << endl;
       break;
   case 'B': cout << " BUS" << endl;
       break;
   }
   cout << " TIME-IN" << "\t\t\t " << ihour << " : " << imin << endl;
   cout << " TIME-OUT" << "\t\t\t " << ohour << " : " << omin << endl;
   cout << "\t\t\t\t" << "----------" << endl;
   cout << " PARKING TIME" << "\t\t\t " << phour << " : " << pmin << endl;
   cout << " ROUNDED TOTAL" << "\t\t\t " << round << endl;
   cout << "\t\t\t\t" << "----------" << endl;
   cout << fixed;
   cout << " TOTAL CHARGE" << "\t\t\t " << '$' << setprecision(2) << total << endl;
   return;
}

//Output

//If you need any help regarding this solution ........ please leave a comment...... thanks

Add a comment
Know the answer?
Add Answer to:
This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class...

    Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class Product { private:    // private variables    int id_number;    char pDescription[40];    int mId;    double productPrice;    double productMarkUp;    int qty; public:    // constructor    Product() {        id_number = 0;        strcpy_s(pDescription, "");        mId = 0;        productPrice = 0.0;        productMarkUp = 0.0;        qty = 0;    }   ...

  • EXPLAIN HOW THIS PROGRAM WORKS, USING DEV C++ #include <iostream> #include <cmath> #define PI 3.1415926535897 using...

    EXPLAIN HOW THIS PROGRAM WORKS, USING DEV C++ #include <iostream> #include <cmath> #define PI 3.1415926535897 using namespace std; typedef struct ComplexRectStruct {    double real;    double imaginary; } ComplexRect; typedef struct ComplexPolarStruct {    double magnitude;    double angle; } ComplexPolar; double radToDegree (double rad) {    return (180.00 * rad) / PI; } double degToRadian (double deg) {    return (deg * PI) / 180; } ComplexPolar toPolar (ComplexRect r) {    ComplexPolar p;    p.magnitude = round(sqrt(pow(r.real,...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int...

    im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...

  • Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {...

    Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {     double distance, gravity =9.8, height;     int time, t=0;     cout<<"Please input the time of fall in seconds:"<<endl;     [ A ] // Get the user input of the time of fall in seconds (Use cin>> method)     cout<<endl;     cout<<"Please input the height of the bridge in meters:"<<endl;     [ B ] // Get the user input of the height of the bridge in meters (Use cin>>...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() {...

    Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT