1. Engineering
  2. Computer Science
  3. c...

Question: c...

Question details
Project description: In this assignment you will create a class representing a gasoline pump. The pump will maintain a running total of the amount of fuel dispensed and revenues collected. The driver program will simulate fuel demand for a number of vehicles. Requirements: 1. Your program must be split into three files, the requirements for which are specified below: a) The class interface, or dedaration, file Must be named gaspump.h Must contain #include guards for GASP UMPH Class must be named GasPump . Will have these private members i. A string containing the type of gas the gas pump holds ii. A double representing the amount of fuel on hand (in gallons) ii. A double representing the fuel pumps capacity (in gallons) iv. A double that holds the price per gallon v. A double representing the total amount of fuel dispensed (all purchases) vi. A double that stores the total amount of money collected (all purchases) vii. A bool that indicates whether the next customer should be turned away as fuel is replenished vii. A void function that replenishes the fuel pumps tank when it runs out of fuel Must have these public members . i. A single constructor with three parameters (in order): a standard string (std::string) that holds the type of gasoline in the pump, a double representing the maximum capacity of the tank in gallons, and a double for the price per gallon. An inline accessor function that returns a standard string for the pumps fuel type i An inline accessor function that returns a double for the pumps fuel price per gallon iv. An inline accessor function that returns a double for the pumps fuel on hand v. An inline accessor function that returns the total amount of fuel dispensed (all purchases) vi. An inline accessor function that returns the total amount of revenue collected (all purchases) vii A void function dispenseFuel, that controls the fueling of vehicles b) A class implementation, or definition, file .Must be named gaspump.cpp Will have the implementation for the following functions i. Constructor- This function has three parameters that map directly to data members; it should also initialize the fuel quantity on hand to the maximum tank capacity (i.e., start at full capacity)
ii. replenish This function resets the fuel tank level to the maximum capacity ii. dispenseFuel- This function is the heart of the class, and controls the fueling of a single vehide. It accepts a pointer to a double (to the fueling outcome array), and a double that indicates the purchase amount desired by the vehicle. It uses the pointer to set the values in the 2-element array: actual purchase amount (element 0) and actual quantity of fuel dispensed to the vehicle (element 1). The amount of fuel a vehicle gets is one of the following: 1) the full amount requested by the vehide (if it is available);or 2) the remaining amount in the tank (if the tank has less than the requested amount); or 3) Zero, if the vehicle is being turned away so the tank can be replenished it does this by A. B. Converting the purchase amount to gallons of fuel. Ensuring that it only dispenses fuel if the tank is not being replenished (in which case the customer is turned away) Ensuring that the pump dispenses no more than the amount of fuel on hand. If the vehicles fuel demand exceeds the amount of fuel on hand, the vehicle gets all of the fuel on hand, and the next customer is turned away as the fuel is replenished. C. D. Keeping track of fuel total dispensecd E. Keeping track of total revenue collected c) A driver, or client, file . Must be named proj2.cpp Reads input data from a file named gas.txt, that will be formatted as follows: o o o The first line is a random number seed (integer) The second line is the number of vehicles to be run through the simulation The 3rd through Sth lines represent individual gas pumps (one per line), composed of: Gasoline type (string) -Tank capacity (double) - Cost per gallon (double) . Percentage of vehicles requiring this type of gas (double between 0 and 1)-Note: this field must sum to 1 across the three gas pump lines Example line: Unleaded 100.0 2.000. S- Note that in this case, the percentage values in the other two lines must sum to 0.5 . . . . Instantiates an array of pointers to 3 GasPump objects, using data read from the input file. Declares a 2-element double array that is passed to the dispenseFuel function to get the outcome of fueling Sets the random number generator seed [using srand)] to the value read from the input file: Creates a loop for the number of vehicles to be simulated -one vehicle per iteration: Determine which pump the vehicle will fuel from, by drawing a random number between 0 and 1, use ((double) rand)1)/RANDMAX to prevent a divide by zero error] and comparing it against the stacked percentages read from the file, to select the pump pointer array index. Example: o Index 1.0 Fuel Type 1 Percentage (line 3):0.3 0.7 Random draw 0.64 results in selection of index 1 for the fuel type Fuel Type 2 Percentage (ne 4):0.6 0.1 Fuel (line 5): 0.1 0.0
o Determine the amount of money the vehicle wants to spend on fuel Select random values from $30 to $55 in increments of $5, by drawing a random integer with rand, modding it by 6, multiplying the result by 5, and adding 30 to it. Use the pointer at the index to invoke the dispenseFuel function in the appropriate pump Output a single line containing the following (in order) o o vehicle #, fuel type, price per gallon, desired purchase amount, actual purchase amount, gallons dispensed, gallons remaining Upon exiting the loop, output the total fuel dispensed and total revenue collected for each pump (in order) 2. Sample Output (with explanation) This is the output from running with the provided sample input file. The format of your output MUST MATCH EXACTLY the output in this specification. DO NOT add any verbiage or information beyond what is called for 1 Unleaded 2.00 45.00 45.00 22.50 77.50 2 Premium+ 5.00 40.00 40.00 8.00 67.00 3 Unleaded 2.00 50.00 50.00 25.00 52.50 4 Midgrade 2.50 30.00 30.00 12.00 38.00 5 Unleaded 2.00 30.00 30.00 15.00 37.50 6 Premium+ 5.00 40.00 40.00 8.00 59.00 7 Unleaded 2.00 50.00 50.00 25.00 12.50 8 Premium+ 5.00 40.00 40.00 8.00 51.00 9 Unleaded 2.00 40.00 25.00 12.50 0.00 10 Unleaded 2.00 45.00 0.00 0.00 100.00 11 Premium+ 5.00 35.00 35.00 7.00 44.00 12 Unleaded 2.00 55.00 55.00 27.50 72.50 13 Unleaded 2.00 55.00 55.00 27.50 45.00 14 Unleaded 2.00 45.00 45.00 22.50 22.50 15 Unleaded 2.00 40.00 40.00 20.00 2.50 16 Midgrade 2.50 40.00 40.00 16.00 22.00 17 Unleaded 2.00 50.00 5.00 2.50 0.00 18 Midgrade 2.50 30.00 30.00 12.00 10.00 19 Unleaded 2.00 35.00 0.00 0.00 100.00 20 Unleaded 2.00 50.00 50.00 25.00 75.00 21 Premium+ 5.00 50.00 50.00 10.00 34.00 22 Premium+ 5.00 40.00 40.00 8.00 26.00 23 Unleaded 2.00 50.00 50.00 25.00 50.00 24 Premium+ 5.00 40.00 40.00 8.00 18.00 25 Unleaded 2.00 35.00 35.00 17.50 32.50 Unleaded 267.50 535.00 Midg rade 40 . 00 100. 00 Premium+ 57.00 285.00 Examples of fueling results (for Unleaded pump) Vehicle gets entire purchase (all Unleaded here and above) Vehicle gets only remaining fuel Vehicle gets no fuel and tank is replenished
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution