Crat a class that will rprsnt a gasolin pump. Th pump will maintain a running to
ID: 3886487 • Letter: C
Question
Crat a class that will rprsnt a gasolin pump. Th pump will maintain a running total of th amount of ful dispnsd and rvnus collctd. Th drivr program will simulat ful dmand for a numbr of vhicls.
also put comment top of each file with the file name ********
Your Rquirmnts:
1. Program must b split into thr fils, th rquirmnts for which ar spcifid blow:
Th class intrfac, or dclaration, fil
• Must b namd GasPump.h
• Must contain #includ guards for GASPUMP_H
• Will hav ths privat mmbrs
A string containing th typ of gas th gas pump holds
A doubl rprsnting th amount of ful on hand (in gallons)
A doubl rprsnting th ful pump’s capacity (in gallons)
A doubl that holds th pric pr gallon
A doubl to rprsnt th amount of ful dispnsd pr purchas
A doubl rprsnting th total amount of ful dispnsd (all purchass)
A doubl that stors th total amount of mony collctd (all purchass)
A bool that indicats whthr th nxt customr should b turnd away as ful is rplnishd
A function that rplnishs th ful pump’s tank whn it runs out of ful
• Must hav ths public mmbrs
A singl constructor with thr paramtrs: a standard string (std::string) that holds th typ of gasolin in th pump, a doubl rprsnting th maximum capacity of th tank in gallons, and a doubl for th pric pr gallon.
An inlin accssor function that rturns a standard string for th pump’s ful typ
An inlin accssor function that rturns th total amount of ful dispnsd (all purchass)
An inlin accssor function that rturns th total amount of rvnu collctd (all purchass)
A void function namd dispnsFul, that controls th fuling of vhicls
A class implmntation, or dfinition, fil
• Must b namd GasPump.cpp
• Will hav th implmntation for th following functions
Constructor – This function has thr paramtrs that map dirctly to data mmbrs; it should also initializ th ful quantity on hand to th maximum tank capacity (i.., start at full capacity)
Rplnish – This function should simply rst th ful lvl to th maximum capacity, and output a mssag to that ffct, as shown in th sampl output blow
dispnsFul – This function is th hart of th class, and controls th fuling of a singl vhicl. It accpts a doubl argumnt that indicats th numbr of gallons rqustd by th vhicl. It should bgin by stting th numbr of dcimal placs for output to 2, with th following statmnts:
std::cout << std::fixd;
std::cout.prcision(2);
It will also
A. Display all of th mssag shown in th xampl output xactly as shown (vrbatim)
B. nsur that it only dispnss ful if th tank is not bing filld (in which cas th customr is turnd away)
C. nsur that th pump dispnss no mor than th amount of ful on hand. If th vhicl’s ful dmand xcds th amount of ful on hand, th vhicl gts all of th ful on hand, and th nxt customr is turnd away as th ful is rplnishd. Th amount dsird and amount actually dispnsd should b output as shown.
D. Kp track of ful dispnsd . Kp track of rvnu collctd (gallons * pric pr gallon)
c) A drivr, or clint, fil
• Must b namd proj2.cpp
• Will instantiat 3 objcts of th GasPump class: namd unladd (initializ to “Unladd”, 200 gallon capacity, and 2.59 pr gallon), midgrad (initializ to “Midgrad”, 125 gallon capacity, and 2.87 pr gallon), and prmium (initializ to “Prmium+”, 100 gallon capacity, and 3.13 pr gallon). Not + aftr Prmium.
• Dclar a pointr to a GasPump objct (will b usd to slct which pump a vhicl will us)
• St th random numbr gnrator sd to 1000 : srand(1000);
• Crat a for loop to simulat 50 vhicls; for ach itration
o Dtrmin which pump th vhicl will ful from
St th pointr to th unladd pump (i.. assum that th vhicl wants unladd gas) Draw a random numbr: int rnd = rand();
Tak th rmaindr (i.., mod 7) of rnd, and if it is 4 or 5, st th pointr to midgrad, if it is 6 st it to prmium – othrwis lav it at unladd. Do not rassign rnd (i.., rnd=rnd%7;).
Not: Th abov stablishs a probability distribution whr, aftr infinitly many draws, unladd is pickd ~ 57% of th tim (4 out of 7), midgrad around 29% of th tim (2 out of 7), and prmium about 14% of th tim (1 out of 7). B sur you undrstand how/why.
o Dtrmin th amount of ful th vhicl rquirs
Us th sam numbr drawn abov to gt th amount of ful to b dispnsd, through th following statmnt: rqFul = 3+ (((doubl)rnd) / RAND_MAX) * 22;
Th abov stablishs a ful dmand for th vhicl, btwn 3 and 25 gallons o Us th pointr to invok th dispnsFul function for th appropriat pump
o Output “Vhicl X ” as shown in th scrnshot blow (rmaining output is from th pump objct)
• Onc you xiting th loop, output th total ful dispnsd and total rvnu collctd for ach pump, as shown
Uehicle 1 Unleaded Filled up with 5.22 gallons $13.52 Vehicle 2 Unleaded Filled up with 8.52 gallons $22.0? Uehicle 3 Midgrade Filled up with 21.03 gallons $60.35 Vehicle 4 Unleaded Filled up with 12.43 gallons $32.18 Uehicle 5 Midgrade Filled up with 4.01 gallons $11.52 Vehicle 6 Midgrade Filled up with 7.2? gallons $20.88 Uehicle ? Unleaded Filled up with 8.27 gallons $21.4:3 Uehicle 8 Midgade Filled up with 17.34 gallons $49.77 Vehicle 9 Unleaded Filled up with 7.68 gallons $19.89 Jehicle 10 Unleaded Filled up with 9.82 gallons $25.44 Uehicle 11 Unleaded Filled up with 17.63 gallons $45.66 Uehicle 12 Unleaded Filled up with 7.44 gallons $19.27 Jehicle 13 Unleaded Filled up with 17.51 gallons $45.36 Uehicle 14 Unleaded Filled up with 24.17 gallons $62.61 Uehicle 15 Unleaded Filled up with 22.31 gallons $57.79 Uehicle 16 Unleaded Filled up with 16.25 gallons $42.10 Uehicle 17 Premium+ Filled up with 18.25 gallons $57.12 Uehicle 18 Unleaded Filled up with 5.10 gallons $13.20 Vehicle 19 Midgrade Filled up with 24.13 gallons $69.26 Uehicle 20 Midgrade Filled up with 11.01 gallons $31.59 Uehicle 21 Unleaded Filled up with 3.30 gallons $8.55 Vehicle 22 Preniu+ Filled up with 12.11 gallons $37.90 Jehicle 23 Unleaded Filled up with 22.29 gallons $57.74 Uehicle 24 Midgrade Filled up with 21.90 gallons $62.86 Uehicle 25 Unleaded Filled up with 7.64 gallons $19.78 Jehicle 26 Midgrade Filled up with 14.61 gallons $41.92 lehicle 27 Unleaded Pumped 4.41 of 6.67 gallons $11.43 Uehicle 28 Midgrade Pumped 3.69 of 22.06 gallons $10.60 Vehicle 29 Premiun+ Filled up with 8.67 gallons $27.14 Uehic le 30 Unleaded Turn ed away out of gas) Tank replenished. Uehicle 31 Premium+ Filled up with 17.44 gallons $54.58 ehicle 32 Unleaded Filled up with 4.33 gallons $11.20 lehicle 33 Premium+ Filled up with 6.67 gallons $20.89 Uehicle 34 Premium+ Filled up with 12.94 gallons $40.52 Uehicle 35 Unleaded Filled up with 16.09 gallons $41.68 Jehicle 36 Unleaded Filled up with 8.07 gallons $20.89 Vehicle 37 Unleaded Filled up with 13.05 gallons $33.81 Uehicle 38 Unleaded Filled up with 22.85 gallons $59.19 lehicle 39 Unleaded Filled up with 5.65 gallons $14.64 Uehic le 40 Midgrade Turned away out of gas) Tank replenished. Uehicle 41 Premium+ Filled up with 16.03 gallons $50.1? Jehicle 42 Premiu+Puped.89 of 24.00 gallons $24.68 Uehicle 43 Premium + Turned away (out of gas),--Tank replenished. Uehicle 44 Unleaded Filled up with 11.68 gallons $30.26 Jehicle 45 Unleaded Filled up with 4.07 gallons $10.54 lehicle 46 Unleaded Filled up with 20.25 gallons $52.46 Vehicle 47 Unleaded Filled up with 20.05 gallons $51.94 Uehicle 48 Midgrade Filled up with 21.41 gallons $61.45 Jehicle 49 Unleaded Filled up with 6.60 gallons $17.08 Uehicle 50 Premium+ Filled up with 9.69 gallons $30.32 Pump Unleaded dispensed 332.70 gallons and collected $861.69 Pump Midgrade dispensed 146.41 gallons and collected $420.20 Pump Premium dispensed 109.69 gallons and collected $343.32Explanation / Answer
#include <iostream>
#include "gaspump.h"
using namespace std;
GasPump::GasPump(){
gasAmount = 0;
amountCharged = 0;
costPerGallon = 2.643;
}
void GasPump::outputAmount()
{
cout<<amountCharged<<endl;
}
void GasPump::outputCharge()
{
cout<<amountCharged<<endl;
}
void GasPump::outputCost()
{
cout<<costPerGallon<<endl;
}
void GasPump::resetValues()
{
gasAmount =0;
amountCharged=0;
}
void GasPump::incrementValues()
{
gasAmount += 10;
amountCharged = gasAmount*costPerGallon;
}
void GasPump::displayCurrent()
{
cout<<gasAmount<<" gallons Current charge: "<<amountCharged<<endl;
}
class GasPump{
private:
double gasAmount;
double amountCharged;
double costPerGallon;
public:
GasPump();
void outputAmount();
void outputCharge();
void outputCost();
void resetValues();
void incrementValues();
void displayCurrent();
};