Question

// 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. */

/* The cost of gas for a trip is displayed. */

//header files

/* use the correct preprocessor directives for input/output */

#________ <________>

_____ _________ ___;

_____ _________();

int main()

{

            // declare variables

            /* an integer pointer variable ptrMiles to point to

               the number of miles of the trip, an integer pointer

               variable ptrMpg to point to the number of miles per

               gallons your car gets, an integer miles the number of

               miles of your trip, an integer mpg the number of miles

               per gallon your car gets, a double pointer variable

               ptrCost that points to the cost of a gallon of gas,

               a double pointer ptrTotal that points to the total

               your trip will cost, a double variable cost for the

               cost of your gas, and a double variable total for

               the cost of your trip. */

            int *______, *______, miles, mpg;

            double *______, cost, *_______, total;

            /* assign the address of each variable to the

               appropriate pointer variable */

            _______ = &____;

            _______ = &_____;

            _______ = &____;

            _______ = &____;

            instruct();

            // prompt the user for the input for each variable

            ____ << "________________________________________: ";

            cin >> *_______;

            ___ << "______________________________: ";

            cin >> *_______;

            _____ << "_____________________________: ";

            cin >> *________;

            // calculate the cost of the trip

            *____________ = *____________/ *__________* *____________;

            cout << "_____________________ $" << *____________<< endl;

            return 0;

}

/* instruct function to instruct the user

   on the use of the program */

void instruct()

{

            cout << "______________________________________ "

                        << "______________________________________\n"

                        << "_______________________________________, "

                        << "__________________________________________\n"

                        << "______________________.\n\n";

}

result:

Enter the number of miles in your trip: 890

Enter the mpg your car gets: 23

Enter the cost of gasoline: 1.79

Your trip will cost $68.02

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

​​​​​

 

Explanation:

Code in C++ is given below

Note : In instruct() method kindly write the instructions as per your need

Output is given at the end of the code

Code in C++:

// 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. */

/* The cost of gas for a trip is displayed. */

//header files

/* use the correct preprocessor directives for input/output */

#include <iostream>

using namespace std;

void instruct();

int main()

{

            // declare variables

            /* an integer pointer variable ptrMiles to point to

               the number of miles of the trip, an integer pointer

               variable ptrMpg to point to the number of miles per

               gallons your car gets, an integer miles the number of

               miles of your trip, an integer mpg the number of miles

               per gallon your car gets, a double pointer variable

               ptrCost that points to the cost of a gallon of gas,

               a double pointer ptrTotal that points to the total

               your trip will cost, a double variable cost for the

               cost of your gas, and a double variable total for

               the cost of your trip. */

            int *ptrMiles, *ptrMpg, miles, mpg;

            double *ptrCost, cost, *ptrTotal, total;

            /* assign the address of each variable to the

               appropriate pointer variable */

            ptrMiles = &miles;

            ptrMpg = &mpg;

            ptrCost = &cost;

            ptrTotal = &total;

            instruct();

            // prompt the user for the input for each variable

            cout << "Enter the number of miles in your trip: ";

            cin >> *ptrMiles;

            cout << "Enter the mpg your car gets: ";

            cin >> *ptrMpg;

            cout << "Enter the cost of gasoline: ";

            cin >> *ptrCost;

            // calculate the cost of the trip

            *ptrTotal = *ptrMiles/ *ptrMpg * *ptrCost;

            cout << "Your trip will cost $" << *ptrTotal<< endl;

            return 0;

}

/* instruct function to instruct the user

   on the use of the program */

void instruct()

{

            cout << "Welcome! Below we calculate the total cost"

                        << " of the trip\n"

                        << "miles travelled in the trip is entered by user, "

                        << "miles per gasoline is then taken\n"

                        << "finally we ask for cost of gasoline.\n\n";

}

OUTPUT::

Welcome! Below we calculate the total cost of the trip

miles travelled in the trip is entered by user, miles per gasoline is then taken

finally we ask for cost of gasoline.

Enter the number of miles in your trip: 890

Enter the mpg your car gets: 23

Enter the cost of gasoline: 1.79

Your trip will cost $68.02

Please provide the feedback!

Thank You!!

Add a comment
Know the answer?
Add Answer to:
// Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter...
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
  • 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...

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

    // Enter your name as a comment for program identification // Program assignment testEmployeeAB.cpp // Enter your class section, and time /* The program testEmployeeAB.cpp tests the class Employee. The class Date is included so that the Employee class can use the Date data type. */ /* Data is entered to create an employee data file. */ /* A payroll report and equal employment opportunity report showing ethnicity data is displayed. */ //header files /* use the correct preprocessor directives...

  • //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS ...

    Complete the incomplete code provided //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and...

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls....

  • Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE...

    Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and return...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

  • Hi, Hi, I need someone to write a program in Phython 3.6, and please I will...

    Hi, Hi, I need someone to write a program in Phython 3.6, and please I will appreciate if the code is error free and indented correctly. The output would be preferable. thanks Write a GUI program that translates the Latin words to English. The window should have three buttons, one for each Latin word. When the user clicks a button, the program displays the English translation in a label. 3. Miles Per Gallon Calculator Write a GUI program that calculates...

  • Your car gets 25 miles per gallon (mpg at 60 miles per hour (mph) and 18...

    Your car gets 25 miles per gallon (mpg at 60 miles per hour (mph) and 18 mpg at 70 mph At what speed should you make a 600-mile trip: a. If gas costs $3 per gallon and your time is worth S12 per hour? b. If gas costs S4 per gallon and your time is worth $15 per hour? allon and your time is worth S10 per hour? d. Build a spreadsheet to calculate the total trip cost for gas...

  • Compute for Miles Per Gallon in C++

    Make a program that will calculate and compute for the quotient of miles and gallons (mpg: miles per gallons). Your program should must ask the user to specify the size of the array (using dynamic array) for the following variable: miles ,gallons and mpg. Prompt the user to Initialize  the value of miles (value for miles should be 100-250) and gallons (values should be from 5-25). Use pointer galPtr for gallons, milPtr for miles and mpgPtr for mpg.  Use function...

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