subject

Driving costs (with pointers)
Complete the program below using pointers.

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles.

Output each floating-point value with two digits after the decimal point, which can be achieved by executing
cout << fixed << setprecision(2); once before all other cout statements. This line is included for you.

Ex: If the input is:

20.0 3.1599
the output is:

3.16 11.85 79.00
Note: Real per-mile cost would also include maintenance and depreciation.

#include
#include
using namespace std;

int main() {

/* Update the declarations below so that each variable points to a
* double on the heap.
*/

double *milesPerGallon;
double *dollarsPerGallon;
double *dollars20Miles;
double *dollars75Miles;
double *dollars500Miles;

/* Write the statements here to:
* 1) Read a value from the keyboard into the variable pointed to by
* milesPerGallon.
* 2) Read a value from the keyboard into the variable pointed to by
* dollarsPerGallon.
*/

/* Write the appropriate statements here to:
* 1) Assign the proper calculated value to the variable pointed to by
* dollars20Miles.
* 2) Assign the proper calculated value to the variable pointed to by
* dollars75Miles.
* 3) Assign the proper calculated value to the variable pointed to by
* dollars500Miles.
*/

cout << fixed << setprecision(2);

cout << *dollars20Miles << " " << *dollars75Miles << " " << *dollars500Miles << endl;

return 0;
}

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:30, fickllyd000
In this lab, you complete a prewritten c program that calculates an employee’s productivity bonus and prints the employee’s name and bonus. bonuses are calculated based on an employee’s productivity score as shown below. a productivity score is calculated by first dividing an employee’s transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked.
Answers: 3
image
Computers and Technology, 22.06.2019 22:50, youngboymark123
Assume the existence of a bankaccount class. define a derived class, savingsaccount that contains two instance variables: the first a double, named interestrate, and the second an integer named interesttype. the value of the interesttype variable can be 1 for simple interest and 2 for compound interest. there is also a constructor that accepts two parameters: a double that is used to initialize the interestrate variable, and a string that you may assume will contain either "simple", or "compound", and which should be used to initialize the interesttype variable appropriately. there should also be a pair of functions getinterestrate and getinteresttype that return the values of the corresponding data members (as double and int respectively).
Answers: 2
image
Computers and Technology, 23.06.2019 06:30, wwesuplexcity28
To become an audio technician, the most successful tactics might include the following. (select all that apply). learning how to persuade other people gaining different types of experience in audio technology learning as much as possible about art history establishing a reputation as a reliable professional
Answers: 1
image
Computers and Technology, 23.06.2019 11:20, 1tzM3
Http is the protocol that governs communications between web servers and web clients (i. e. browsers). part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. some of the codes and their meanings are listed below: 200, ok (fulfilled)403, forbidden404, not found500, server errorgiven an int variable status, write a switch statement that prints out the appropriate label from the above list based on status.
Answers: 2
You know the right answer?
Driving costs (with pointers)
Complete the program below using pointers.

Driving i...

Questions in other subjects: