Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: 1) Use classes; 2) Split interface and implementation into files; 3) Use an array of pointers to objects; 4) Instantiate objects using parameterized constructors;

Objectives: 1) Use classes; 2) Split interface and implementation into files; 3) Use an array of pointers to objects; 4) Instantiate objects using parameterized constructors; 5) Use objects in a client/driver function. 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 simulates fuel demand for a number of vehicles.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Sample Input File: gas.txt

500 25 Unleaded 100 2.0 0.5 Midgrade 50 2.5 0.2 Premium+ 75 5.0 0.3
Language: C++
Please only create 3 files using C++: gaspump.h/gaspump.cpp/main.cpp
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 simulates 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 declaration, file Must be named gaspump.h Must contain #include guards for GASPUMP_H 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) iii. A double representing the fuel pump's 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 viii. A void function that replenishes the fuel pump's underground tank 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. ii. An inline accessor function that returns a standard string for the pump's fuel type iii. An inline accessor function that returns a double for the pump's fuel price per gallon iv. An inline accessor function that returns a double for the pump's 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 (in this order): fuel type (string), tank capacity (double), and price per gallon (double). 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. It should be invoked anytime there is less than 10% fuel remaining in the tank, after dispensing fuel. iii. dispenseFuel - This function is the heart of the class, and controls the fueling of a single vehicle. 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 o) 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 vehicle (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. Converting the purchase amount to gallons of fuel. B. Ensuring that it only dispenses fuel if the tank is not being replenished (in which case the customer is turned away) C. Ensuring that the pump dispenses no more than the amount of fuel on hand. If the vehicle's fuel demand exceeds the amount of fuel on hand, the vehicle gets all of the fuel on hand. D. Turning away the next customer whenever fuel is replenished. E. Keeping track of fuel total dispensed F. 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 The first line is a random number seed (integer) o The second line is the number of vehicles to be run through the simulation o The 3rd through 5th 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.00 0.3- Note that in this case, the percentage values in the other two lines (Midgrade and Premium+) must sum to 0.7 Instantiates an array of pointers to three (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: o Determine which pump the vehicle will fuel from, by drawing a random number between 0 and 1, [use (double) rand()/RAND_MAX] and comparing it against the "stacked" percentages read from the file, to select the pump pointer array index. Example: Index 1.0 Fuel Type 1 Percentage (line 3): 0.3 If random number drawn is 0.64, this would lead to the selection of fuel type at index 1 1 Fuel Type 2 Percentage (line 4): 0.6 0.1 Fuel Type 3 Percentage (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. o Use the pointer at the index to invoke the dispenseFuel function in the appropriate pump O Output a single line containing the following (in order): . 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 shown below. Example 1 of fueling results (for Unleaded pump) Vehicle gets entire purchase (all Unleaded here and above) Vehicle gets only remaining fuel tank now empty) Vehicle gets no fuel - tank replenished (tank was empty) 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 10.00 10.00 16.00 22.00 17 Unleaded 2.00 50.00 0.00 0.00 100.00 18 Midgrade 2.50 30.00 30.00 12.00 10.00 19 Unleaded 2.00 35.00 35.00 17.50 82.50 20 Unleaded 2.00 50.00 50.00 25.00 57.50 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 32.50 24 Premium+ 5.00 40.00 40.00 8.00 18.00 25 Unleaded 2.00 35.00 35.00 17.50 15.00 Unleaded 282.50 565.00 Midgrade 40.00 100.00 Premium+ 57.00 285.00 Example 2 of fueling results (for Unleaded pump) Vehicle gets entire purchase (tank now

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

What is meant by immunizing a bond portfolio? AppendixLO1

Answered: 1 week ago

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago