Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ Program using Classes that simulates the arrival of 10 customers to

ID: 656540 • Letter: W

Question

Write a C++ Program using Classes that simulates the arrival of 10 customers to the gas station and the amount of gas requested. Each customer should arrive randomly between 1 and 15 minutes and request between 3 and 15 gallons of gas. Assume there are three grades of gas: 87 octane, 89 octane, and 93 octane. Display the arrival time, the numbers of gallons of gas each customer requests, and octane rating of the gas should be displayed. After the last customer, your program should display the total number of gallons requested for each grade of gas.

(Not an assignment already have a working prgram, this is just a survey for the best answer)

Explanation / Answer

Program:-

#include <iostream>

#include <iomanip>

#include<ctime>

#include<cmath>

using namespace std;

class Customer

{

private:

     static double Arrival_Time;

     static int No_Of_Gallons;

     static int Grade;

public:

     double get_Time();

     int get_Gas();

     int get_Grade();

     void tally_Grade(int,int);

};

static int Grade_One=0, Grade_Two=0, Grade_Three=0;

double Customer::get_Time()

{

     Arrival_Time=(1+double(rand())/RAND_MAX <0.5)*14;

     return Arrival_Time;

}

int Customer::get_Gas()

{

     No_Of_Gallons=((3+double(rand())/RAND_MAX <0.5)*12);

          return No_Of_Gallons;

}

int Customer::get_Grade()

{

     Grade=(double(rand())/RAND_MAX <0.5)*3;

     return Grade;

}

void Customer::tally_Grade(int gas_grade, int gallons)

{

     int Grade,gallons;

     if(Grade==1)  

          Grade_One+=gallons;

     else if (Grade==2)

          Grade_Two+=gallons;

     else Grade_Three+=gallons;

     return;

}

int main()

{

     Customer *anewCustomer;

     int i=0, howMany, gas_grade,gallons;

     cout<<"Enter the number of customers: ";

     cin>>howMany;

     while (++i<=10)

     {

          anewCustomer= new Customer;

          gallons=anewCustomer->get_Gas();

          cout<<"Customer Number "<<i<<"Arrived at " <<anewCustomer->get_Time()<<"and ordered "<<gallons<<"Gallons of Grade: ";

          cin>>gas_grade;

          anewCustomer->tally_Grade(gas_grade,gallons);

          delete anewCustomer;

     }

     cout<<"In All, there were "<<Grade_One<<"Gallons sold of 87 Octane, "<<Grade_Two<<" Gallons sold on 93 Octane and"<<Grade_Three<<" gallons sold of 97 Octanes";

     return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote