1 CS 215 – Fall 2020 Project 1 Version 1 Learning Objectives: - implementing an application using decisions and loops - validating user input and formatting output General Description: Write a program...

1 answer below »
code in C++ and the due date is sept 14th 12:pm


1 CS 215 – Fall 2020 Project 1 Version 1 Learning Objectives: - implementing an application using decisions and loops - validating user input and formatting output General Description: Write a program that simulates the action of a gasoline pump. At startup, the pump asks the user (Pump Technician) for the number of gallons available and price per gallon of three octanes of gas (High, Medium and Low). For each customer, the pump starts by displaying a logo and asking the customer if they are a rewards customer or not. If yes, the rewards number is entered and a per-gallon discount is determined. The customer then selects an octane (H/M/L) and enters a number of gallons, or indicates a “fill up”. For a “fill up”, an estimate is simulated as a random number of gallons between 1 and 8. If not enough gas is available to satisfy the customer’s request, the number of gallons is changed to the amount remaining in the pump and the customer is informed. The pump then simulates dispensing gasoline by printing the amount dispensed on the screen after each ½ gallon is dispensed, reporting approximately every two seconds, until the number of gallons indicated has been dispensed. Finally, a receipt is printed on the screen and, after a pause, the process repeats for the next customer. The pump technician can shut down the pump by entering “shutdown” to the question “Are you a rewards customer?” This is a corporate secret and not to be revealed to the customer. On shutdown, the pump reports the gallons of each octane currently available on the screen, and the total amount (dollars) of gas sold since startup for each octane. General Formatting: - All floating point calculations should be rounded to two digits past the decimal point. Use the C++ round() function. Note: round() rounds a float value to an integer, so a little algebra will be required. Ex: round(12.3456) = 12, but you need 12.35. Rounding is not required for some mathematical operations (ex: +, -) when the operands are already rounded. - All floating point values should be printed with two digits past the decimal point. 2 On Startup: The program should display a Pump Startup logo and then ask the Pump Technician to enter the number of gallons in the pump and price per gallon for each of the three octanes. The user enters two floating point values with a space between for each octane on one line. The user input should line up on the left, as shown in the example. The program should then simulate starting up by printing “Starting pump”. About every second, a dot (“.”) should be printed after this until 4 dots are printed. After the fourth dot is printed, there is another (fifth) one second delay, followed by the printing of a blank line. Coding requirements: - use a loop to print the dots….do not copy/paste 4 copies of the code for one dot. - Use the Windows Sleep() function to perform the “wait”: o #include is needed o declare and use a constant value of 1000 (milliseconds). Ex: const int second = 1000; o Sleep(second); // or Sleep(3*second); for 3 seconds o The following is reported to work on a Mac:  include  sleep(1); // 1 second; not 1000 as with Windows Sleep() Repeat for each customer until “shutdown” is entered for the first question: Asking if rewards customer: Display a logo as shown. Make up your own name of the gas station, and include your name somewhere in the logo. Ask the user Are you a rewards customer? (Y/N): Valid responses are Y,y,N,n and shutdown. When an invalid response is entered, display Please enter Y or N.and repeat the question. Repeat this until the customer enters a valid answer. Note the user may enter more than one character (use string not char for the variable). Design Hint: note that at this point, one of two options will happen: the program continues with a customer sale, or the shut down is performed and the program ends. This segment of code acts as “Input” for a Sentinel-Controlled Loop, where the Sentinel Value is shutdown. See the course notes for the form of a Sentinel-Controlled Loop. Asking Rewards Number and Calculating PPG (Price Per Gallon) Discount: If this customer is a rewards customer, ask the customer Enter customer rewards number: You may assume they will enter an integer number. 3 Calculate the PPG discount as: the modulus (%) of the customer number by 10, then add 1. This results in a number 1-10. Divide this result by 100 to get the discount in cents. Example: customer number = 2135679 2135679 % 10 is 9 9 + 1 is 10 10 / 100 = 0.10 = PPG discount Of course, if the customer is NOT a rewards customer, do not ask them to enter a number and the PPG Discount is 0.00. Whether a rewards customer or not, print the PPG Discount as shown in the examples. The $ should line up with the customer’s input for both “Are you a…” and “Enter rewards..” as shown. Also, print a blank line before displaying the prices per gallon in the next section. Displaying Prices Per Gallon: The prices are the prices entered at startup, minus the PPG Discount calculated above. Format the price list as shown here. There should be a blank line above and another below the price list. Selecting an Octane: Ask the user Select octane (H/M/L): as shown in the example. Valid entries are H,h,M,m,L, and l. When the user enters an invalid entry, print Please enter H, M or L. Repeat this until the user enters a valid entry. After a valid entry is entered, print a blank line. Getting the number of gallons: Ask the user Enter number of gallons (-1 to Fill it up): The number of gallons may be a floating point number. When -1 (or any number less than 0) is entered, simulate the number of gallons as a random number between 1 and 8. Use the rand() function, which returns a random number (use modulus to get a number 0 to 7, then add 1). Report this number as “detected by a sensor” with the message: Sensor reports g gallons needed to fill up, where g is the random number of gallons calculated. Check for empty tanks: It is possible this pump is almost empty for some octane of gasoline. The inventory amount is entered at startup. When gasoline is dispensed to a customer, the amount dispensed is subtracted from the tank’s current total. If the number of gallons requested is more than is available, give the customer all the remaining supply by changing the number of gallons requested to the amount left in the pump’s tank (emptying the tank). Print Sorry, our tank is nearly empty. We only have g gallons available. Note that if the tank 4 is empty, the amount requested will be 0 gallons and the pump will continue delivering 0 gallons at 0 cost. Simulate Pumping Gas: A message on the total number of gallons pumped so far is printed every 2 seconds. The pump pumps ½ gallon every two seconds. Note that the last message should report the original number of gallons requested, and so may not be an equal ½ gallon. Start with the message Pumping gas... with a blank line before and after the set of messages. Printing a receipt: Format the receipt as shown here, including lining up the values as shown. The octane value printed should NOT be simply H, M or L as originally entered by the user, but should be fully-spelled out as High, Medium or Low. The decimal points for the PPG and total cost should always line up. You may assume no one purchase will exceed $999.99. Feel free to change the text on the Thank You line, but it must have a Thank You line. There should be a pause (press any key…) after printing the receipt. In Windows, the following code will work: system("pause"); The following should work in both C++ and Mac (not tested in Mac): cout < "enter any key to continue..."; cin.clear(); cin.ignore(999, '\n'); char c = getchar(); tracking report values: - subtract the number of gallons sold to this customer from the tank’s inventory number (hi, med or low inventory, initially set at pump start up) - accumulate (add) the total price sold to a sum for each octane (ex: dollarshisold, dollarsmedsold, dollarslowsold). note some customers get a discounted price!! these will be needed for printing the report at shutdown. after the pause, the process should repeat for the next customer, starting with printing the logo. 5 shut down: when the user enters shutdown to the “are you a rewards customer” prompt, the pump performs the following shut down operations and the program ends. first, it prints a message shutting down pump... followed by a 3 second delay. it then prints a report of the number of gallons of each octane sold along with the dollar amount for each and the gallons remaining in the inventory. a final total line contains the total amount sold in dollars for all octanes. finally, the program ends with a message pump shut down. style and grading rubric: all of this program will be written in the main() function (if you want to divide it into functions, "enter="" any="" key="" to="" continue...";="" cin.clear();="" cin.ignore(999,="" '\n');="" char="" c="getchar();" tracking="" report="" values:="" -="" subtract="" the="" number="" of="" gallons="" sold="" to="" this="" customer="" from="" the="" tank’s="" inventory="" number="" (hi,="" med="" or="" low="" inventory,="" initially="" set="" at="" pump="" start="" up)="" -="" accumulate="" (add)="" the="" total="" price="" sold="" to="" a="" sum="" for="" each="" octane="" (ex:="" dollarshisold,="" dollarsmedsold,="" dollarslowsold).="" note="" some="" customers="" get="" a="" discounted="" price!!="" these="" will="" be="" needed="" for="" printing="" the="" report="" at="" shutdown.="" after="" the="" pause,="" the="" process="" should="" repeat="" for="" the="" next="" customer,="" starting="" with="" printing="" the="" logo.="" 5="" shut="" down:="" when="" the="" user="" enters="" shutdown="" to="" the="" “are="" you="" a="" rewards="" customer”="" prompt,="" the="" pump="" performs="" the="" following="" shut="" down="" operations="" and="" the="" program="" ends.="" first,="" it="" prints="" a="" message="" shutting="" down="" pump...="" followed="" by="" a="" 3="" second="" delay.="" it="" then="" prints="" a="" report="" of="" the="" number="" of="" gallons="" of="" each="" octane="" sold="" along="" with="" the="" dollar="" amount="" for="" each="" and="" the="" gallons="" remaining="" in="" the="" inventory.="" a="" final="" total="" line="" contains="" the="" total="" amount="" sold="" in="" dollars="" for="" all="" octanes.="" finally,="" the="" program="" ends="" with="" a="" message="" pump="" shut="" down.="" style="" and="" grading="" rubric:="" all="" of="" this="" program="" will="" be="" written="" in="" the="" main()="" function="" (if="" you="" want="" to="" divide="" it="" into="">
Answered Same DaySep 13, 2021

Answer To: 1 CS 215 – Fall 2020 Project 1 Version 1 Learning Objectives: - implementing an application using...

Aditya answered on Sep 14 2021
150 Votes
#include
#include
#include
using namespace std;
int main()
{
cout<<"+-------------------------------------------------+"< cout<<"| PUMP START UP
|"< cout<<"+-------------------------------------------------+"< float lowQuantity,mediumQuantity,highQuantity;
float lowPrice,mediumPrice,highPrice;
float lPrice = 0,mPrice = 0,hPrice = 0;
float lQuantity =0,mQuantity=0,hQuantity=0;
float lq,mq,hq;
float lsold,msold,hsold;
const int second = 1000;
cout<<"Enter gallon in pump and today's price per gallon for: "< cout <<"High octane: ";
cin>>highQuantity>>highPrice;
cout <<"Medium octane: ";
cin>>mediumQuantity>>mediumPrice;
cout <<"Low octane: ";
cin>>lowQuantity>>lowPrice;
lq = lowQuantity;
hq = highQuantity;
mq = mediumQuantity;
cout<<"Starting pump";
for(int i =0;i<4;i++)
{
Sleep(second);
cout<<".";
}
bool main = true;
while(main)
{
cout<<""< cout<<"+-------------------------------------------------+"< cout<<"| WELCOME TO HUCKABILLY'S SELF SERVE |"< cout<<"| ASH,OWNER |"< cout<<"+-------------------------------------------------+"< string choice;
bool repeat = true;
while(repeat)
{
cout<<"Are you a rewards customer? (Y/N): ";
cin>>choice;
if(choice == "Y")
{
repeat = false;
break;
}
else if(choice == "N")
{
repeat = false;
break;
}
else if(choice == "shutdown")
{
const int stop = 3000;
cout<<""< cout<<"Shutting down pump..."< Sleep(stop);
cout<<"---------------------------------------------------"< cout<<"Octane \t Gallon Sold \t Dollars Sold \t...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here