Question

In: Computer Science

A gas station wants a program to keep track of sales. Your gas station sells diesel...

A gas station wants a program to keep track of sales. Your gas station sells diesel for 107.9 cents per litre and regular gas for 112.9 cents per litre. Have the user enter the type of fuel (1 = Regular gas, 2 = Diesel) and number of litres sold. Print out a total for each sale (remember fuel prices already include the GST). Once you enter a 0 for the type of fuel your program should stop and print out a table summarizing the totals for each fuel type as shown in the print out below

The following is a sample run, user input is shown as bold underline:

Enter type of sale (1=Regular, 2=Diesel, 0=exit): 1

How many litres? 40.2

Regular Gas

Litres Sold = 40.2

Sale total $45.39

Enter type of sale (1=Regular, 2=Diesel, 0=exit): 2

How many litres? 100

Diesel

Litres Sold = 100.0

Sale total $107.90

Enter type of sale (1=Regular, 2=Diesel, 0=exit): 2

How many litres? 5

Diesel

Litres Sold = 5.0

Sale total $5.40

Enter type of sale (1=Regular, 2=Diesel, 0=exit): 1

How many litres? 10

Regular Gas

Litres Sold = 10.0

Sale total $11.29

Enter type of sale (1=Regular, 2=Diesel, 0=exit): 0

Station Totals

      Type     Litres      Total

   Regular       50.2      56.68

    Diesel      105.0     113.30

    Totals      155.2     169.98

Solutions

Expert Solution

C++ code for the given program specification is provided below. File name: gas_station.cpp

#include<iostream>
#include<iomanip>

using namespace std;

int main() {
    float diesel_per_lt = 107.9, gas_per_lt = 112.9, lt_fuel, Total, Reg_lt = 0, diesel_lt = 0, Reg_total = 0, diesel_total = 0;
    int input = 3, i=0;
    float sales[100][3];
    while(input != 0) {
        cout << "\nEnter type of sale (1=Regular, 2=Diesel, 0=Exit): ";
        cin >> input;
        if(input == 0) 
            break;
        
        if(input == 1) {
            cout << "How many litres? ";
            cin >> lt_fuel;
            Reg_lt += lt_fuel;
            sales[i][0] = input;
            sales[i][1] = lt_fuel;
            sales[i][2] = lt_fuel * gas_per_lt / 100;
            Reg_total += sales[i][2];
            cout << "Regular Gas\nLitres Sold = " << lt_fuel << "\nSale Total = " << fixed << setprecision(2) << sales[i][2];
            i++;
        }
        else if(input == 2) {
            cout << "How many litres? ";
            cin >> lt_fuel;
            diesel_lt += lt_fuel;
            sales[i][0] = input;
            sales[i][1] = lt_fuel;
            sales[i][2] = lt_fuel * diesel_per_lt / 100;
            diesel_total += sales[i][2];
            cout << "Diesel\nLitres Sold = " << lt_fuel << "\nSale Total = " << sales[i][2];
            i++;
        }
    
    }

    cout << "\nStation Totals\n";
    cout << setw(15) << "Type" << setw(15) << "Litres" << setw(15) << "Total" << endl;
    cout << setw(15) << "Regular" << setw(15) << fixed << setprecision(1) << Reg_lt << setw(15) << fixed << setprecision(2) << Reg_total << endl;
    cout << setw(15) << "Diesel" << setw(15) << fixed << setprecision(1) << diesel_lt << setw(15) << fixed << setprecision(2) << diesel_total << endl;
    cout << setw(15) << "Totals" << setw(15) << fixed << setprecision(1) << Reg_lt + diesel_lt << setw(15) << fixed << setprecision(2) << Reg_total + diesel_total << endl;
    return 0;
}

Instructions to execute the code:

1. Move to the directory where source file is saved in your command line.

2. Compile the code using the following command:

> g++ gas_station.cpp

3. Run the code using the following command:

> ./a.out

-------------------------------------------------------------------------------------------------------------------------------------


Related Solutions

Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
FMEA (Failure Mode and Effect Analysis) Smelly Gus’s Gas Station sells gasoline. Each non-diesel station carries...
FMEA (Failure Mode and Effect Analysis) Smelly Gus’s Gas Station sells gasoline. Each non-diesel station carries 87, 89, and 93 octane unleaded gasoline. Customers must prepay for gasoline by inserting a credit card or by prepaying with cash inside the station. Instructions Complete a FMEA. Identify the pump’s: function(s), potential failures, potential effects of failures, potential causes of failures, and any possible process controls. Determine Criticality for each potential failure.
You are tasked to design an application to keep track of sales for your company. Sales...
You are tasked to design an application to keep track of sales for your company. Sales should be tracked for two types of accounts: supplies and services. Complete the following:     Create a UML class diagram for the Account inheritance hierarchy. Your subclasses should be Supplies and Services.     All sales accounts will have an account ID (accountId).     You will need attributes to keep track of the number of hours (numberOfHours) and rate per hour of services provided (ratePerHour)....
Write a Java program that lets the user keep track of their homemade salsa sales. Use...
Write a Java program that lets the user keep track of their homemade salsa sales. Use 5-element arrays to track the following. The salsa names mild, medium, sweet, hot, and zesty. The number of each type sold. The price of each type of salsa. Show gross amount of money made (before tax). Calculate how much the user owes in sales tax (6% of the amount made). Then display the net profit (after subtracting the tax).
In this assignment, the program will keep track of the amount of rainfall for a 12-month...
In this assignment, the program will keep track of the amount of rainfall for a 12-month period. The data must be stored in an array of 12 doubles, each element of the array corresponds to one of the months. The program should make use of a second array of 12 strings, which will have the names of the months. These two arrays will be working in parallel. The array holding the month names will be initialized when the array is...
It is rare that you will find a gas station these days that only sells gas....
It is rare that you will find a gas station these days that only sells gas. It has become more common to find a convenient store that also sells gas. The data named “Convenient Shopping data” the sales over time at a franchise outlet of the major US oil company. Each row summarize sales for one day. This particular station sells gas and has a convenient store and car awash. The column labeled Sales gives the dollar sales of the...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
Accounting Program in c++ Write a class to keep track of a balance in a bank...
Accounting Program in c++ Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not...
Although gas station owners lock their tanks at night, a gas station owner in your neighborhood...
Although gas station owners lock their tanks at night, a gas station owner in your neighborhood was the victim of theft because his employee had a key to the tank. The owner of the gas station wants to bury the gasoline so deep that no vacuump pump, no matter how powerful, will be able to extract it. He has hired you as a general contractor to dig the holes for the tanks. What is the minimum depth needed for the...
Ava wants to use a database to keep track of the data recordsfor her insurance...
Ava wants to use a database to keep track of the data records for her insurance company and to enforce the following business policies/requirements: USE MS ACCESS TO CREATE A DATABASE & RELATIONASHIP-Every customer must be uniquely identified.-A customer can have many insurance policies.-Every insurance policy must be uniquely identified.-An insurance policy must belong to a valid customer.-Every customer must be served by a valid insurance agent (employee).-An insurance agent (employees) serves many customers.-Every insurance agent (employee) must be uniquely...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT