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”...
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...
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...
You will design a program to keep track of a restaurants waitlist using a queue implemented...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue b. Return the last person in the queue c. Add a person to...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT