Question

I'm a C++ beginner, I'm not sure how to do this.

Calculate the amount a customer should be charged at a gas station.

Fees for the car wash are $4.25 with gasoline purchase of $35.00 or more and $10.00

otherwise. Three kinds of gasoline are available: regular at 3.39, unleaded at 3.55 and

premium at 3.65 per gallon. Input consists of the customer number, number of gallons

purchased, kind of gasoline purchased (R, U, P, or, for no purchase, N), and car wash

desired (Y or N).

You are in charge of completely testing the program. Do not forget to include input

validation for incorrect values. Run your program at least six times with the test data

shown below for gas type, gallons, and car wash in this order:

1. P 10.02 Y

2. r 15.50 N

3. U 19.00 y

4. R 6.50 y

5. n Y

6. N n

The program is to prompt the user for the input as shown below:

Gas type (R, U, P, N) : P

Number of gallons : 10.02

Car wash? [Y/N] : Y

Write the bill to an output file as shown below. Be careful to align the decimal points. Prompt the user to enter the name ofIf the user chooses gas type: 'N', the number of gallons should be set to 0.

Write the bill to an output file as shown below. Be careful to align the decimal points.

Prompt the user to enter the name of the output file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

if you have any query comment down below and Thumbs Up

Code:

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

void writeData(double gallonePurchased, double pricePerGallon, double totalGasolinecost, double carWashCost,double totalDue) {

cin.ignore();

  cout << "Enter the Name Of Output file : ";

  string outputFile;

  getline(cin, outputFile);

  outputFile = outputFile + ".txt";

  ofstream outFile;

  outFile.open(outputFile.c_str(),ios::app);

  outFile << "********************************\n";

  outFile << "* Best Gas And Wash *\n";

  outFile << "* Service Station *\n";

  outFile << "********************************\n";

  outFile << "\n\n";

  outFile << "\tGallons Purchased:\t" << gallonePurchased << "\n";

  outFile << "\tPrice per gallon :\t" << pricePerGallon << "\n";

  outFile << "\n\n";

  outFile << "\tTotal gasoline cost :\t" << totalGasolinecost << "\n";

  outFile << "\tCar Wash cost : \t\t\t" << carWashCost << "\n";

  outFile << "\t\t\t\t\t\t\t\t\t\t\t------\n";

  outFile << "\t\t\t\t\t\tTotal due : " << totalDue << "\n";

  outFile << "********************************\n";

  outFile << " * Thank you for stopping ! *\n";

  outFile << " * Have a nice day *\n";

  outFile << " * and *\n";

  outFile << " * come again! *\n";

  outFile << " **********************\n";

  outFile.close();

}

int main() {

  char choice,choice2;

  double gallonePurchased=0, pricePerGallon=0, totalGasolinecost=0, carWashCost=10, totalDue=0;

  cout << "Gas Type (R,U,P,N) : ";

  cin >> choice;

  switch (choice)

  {

  case 'R':

  case 'r':

    cout << "Number of gallons :";

    cin >> gallonePurchased;

    pricePerGallon = 3.39;

    totalGasolinecost = pricePerGallon * gallonePurchased;

    break;

  case 'U':

  case 'u':

    cout << "Number of gallons :";

    cin >> gallonePurchased;

    pricePerGallon = 3.55;

    totalGasolinecost = pricePerGallon * gallonePurchased;

    break;

  case 'P':

  case 'p':

    cout << "Number of gallons :";

    cin >> gallonePurchased;

    pricePerGallon = 3.65;

    totalGasolinecost = pricePerGallon * gallonePurchased;

    break;

  case 'N':

  case 'n':

    totalGasolinecost = pricePerGallon * gallonePurchased;

    break;

  default:

    cout << "You Enter the Wrong Choice So It considered as No \n";

    break;

  }

  cout << "Car Wash[Y/N] :";

  cin >> choice2;

  switch (choice2)

  {

  case 'Y':

  case 'y':

    if (gallonePurchased >= 35) {

      carWashCost = 4.25;

      totalDue = totalGasolinecost +carWashCost;

    }

    else

    {

      totalDue = totalGasolinecost + carWashCost;

    }

    break;

  case 'N':

  case 'n':

carWashCost=0;

totalDue = totalGasolinecost + carWashCost;

    break;

  default:

    cout << "You Enter the Wrong Choice So It considered as No \n";

    break;

  }

  writeData(gallonePurchased, pricePerGallon,totalGasolinecost,carWashCost,totalDue);

  return 0;

}

SS of output:

Gas Type (R,U,P,N) :P Number of gallons : 10.02 Car Wash[y/N] :Y Enter the Name Of Output file : output

Best Gas And Wash Service Station Gallons Purchased: 10.02 Price per gallon : 3.65 Total gasoline cost : 36.573 Car Wash cost

Gas Type (R,U,P,N) : 1 Number of gallons -15.50 Car Wash[y/N] :N Enter the Name of Output file : output

* * * * ** * ** * * ** * * ** * ** * * * ** * * * * * Best Gas And Wash Service Station Gallons Purchased: Price per gallon :

.Gas Type (R,U,P,N) : U Number of gallons - 19.00 Car Wash(Y/N) :Y Enter the Name of Output file : output

Best Gas And Wash Service Station Gallons Purchased: Price per gallon : 19 3.55 Total gasoline cost : 67.45 Car Wash cost : 1

Gas Type (R,U,P,N) : R Number of gallons :6.50 Car Wash[y/N] =y Enter the Name of Output file : output

Best Gas And Wash Service Station Gallons Purchased: 6.5 Price per gallon : 3.39 Total gasoline cost: 22.035 Car Wash cost :

Gas Type (R,U,P,N) :n Car Wash[y/N] :Y Enter the Name of Output file : output

Best Gas And Wash Service Station Gallons Purchased: 0 Price per gallon : 0 Total gasoline cost : 0 Car Wash cost : 10 Total

Gas Type (R,U,P,N) : 0 Car Wash(Y/N) :D Enter the Name of Output file : output

Best Gas And Wash Service Station Gallons Purchased: 0 Price per gallon : 0 Total gasoline cost : 0 Car Wash cost : Total due

Add a comment
Know the answer?
Add Answer to:
I'm a C++ beginner, I'm not sure how to do this. Calculate the amount a customer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash...

    The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon. User Request: Write a program that prints a statement for a customer. Analysis: Input consists of number of gallons purchased (R, P, S, or N for no purchase), and car wash desired (Y...

  • // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter...

    // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter your class section, and time /* The program TripCost.cpp uses pointers to calculate    the cost of a trip depending on the cost of a gallon    of gas, the number of miles, and the number of miles    per gallon a car gets. */ /* The cost of gas, the number of miles, and number of    miles per gallon is entered. */...

  • please do the program in simple programming it is for my first c++ computer class i...

    please do the program in simple programming it is for my first c++ computer class i posted the example on pic 2,3 which is how this should be done Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for...

  • A liter is 0.264179 gallons. Write a program that will read in the number of liters...

    A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon. After doing this... Modify your...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • I need to write a paint job estimator program in python. I have most of it...

    I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...

  • This is a c++ question note: not using  namespace std; at the beginning of the program Writing...

    This is a c++ question note: not using  namespace std; at the beginning of the program Writing Data to a File This program will write a series of letters, starting with 'A', to an external file (letters.txt). The user will decide how many letters in total get saved to the file. ** IMPORTANT: The test cases will evaluate your code against .txt files that I uploaded. You do NOT have to upload your own txt files. Input: Including 'A', how many...

  • I'm still trying to learn how to use matlab but I'm not sure how to do this at all. I am to imple...

    I'm still trying to learn how to use matlab but I'm not sure how to do this at all. I am to implement three different explicit methods for approximating an IVP using Eulers, Runge-Kutta 4th order method, and the trapezoidal method using the same parameters. I'd much appreciate having just the Euler methods. but having all three done would be greatly appreciated and will give a great rating! function y forward_euler (n, m, a, b, eta,F) % Use the forward...

  • Hello Sorry but I'm stuck in this lab. LAB - Dollar Bills Distributed: week3, Lab Session...

    Hello Sorry but I'm stuck in this lab. LAB - Dollar Bills Distributed: week3, Lab Session A Due: week3, Friday 11:59pm (late date is Sunday) PROGRAM DESCRIPTION User will input a whole number between 1 and 10, and the program will output that number as a dollar value. For example, if the user enters the number 4, the program will output the associated real value as currency: $ 4.00. Your program should prompt the user to enter in a number...

  • I have this class determines how much petrol is being purchased and the cost. The gas...

    I have this class determines how much petrol is being purchased and the cost. The gas is divided between regular, premium, and super unleaded. The program reads (R, P, or S) that designates which kind of gasoline was purchased. class Petrol { private static final double Premium = 0; private static final double Super = 0; char gas; String type; double amount, cost; private String free; private double regular; Petrol(char ch, double a) { gas = ch; amount = a;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT