Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 3, Problem 1PP

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 traveled by the car and will then output 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.

Expert Solution & Answer
Check Mark
Program Plan Intro

List of variables:

number_of_miles: Store the number of miles travelled.

liter_of_gas: Store the quantity of gasoline consumed.

List of functions used:

cout.setf(ios::showpoint): For controlling the floating and trailing zeros.

cout.precision(2): Dislay the values up to two digits.

cin(): To take input from input streams like keyboard, files etc.

cout(): To display the output.

Summary Introduction:

Program will use the Main () method to prompt the user to enter the number of miles traveled and the number of gasoline consumed to find the number of miles per gallon car delivered. A liter is equal to 0.264179 gallons.

Program Description:

The purpose of the program is to find the number of miles per gallon car delivered.

Explanation of Solution

Program:

Following is the C++ program to find the number of miles per gallon car delivered.

/*

* Program: The program asks user to provide the number of miles car travelled and the amount of gasoline consumed to find the number of miles per gallon car delivered.

*/

#include <iostream>
Usingnamespacestd;
constdouble LITRE =0.264179;
// A liter is equal to 0.264179 gallons
doublemiles_per_gallons(float,float);
intmain(){
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
charans;
do{
// declare the variables.
Floatnumber_of_miles,liter_of_gas;
cout<<"Enter the number of miles traveled: ";
cin>>number_of_miles;
cout<<"\nEnter the number of liters of gasoline consumed: ";
cin>>liter_of_gas;
cout<<endl<<miles_per_gallons(number_of_miles,liter_of_gas);
cout<<endl<<"Do you want to calculate again? ";
cin>>ans;
}while(ans=='Y'||ans=='y');
cout<<"\nThank You!";
return0;
}
// function to calculate the miles per gallon car delivered.
doublemiles_per_gallons(floatnumber_of_miles,floatliter_of_gasoline){
returnnumber_of_miles/(liter_of_gasoline*LITRE);
}

Explanation:

The above program prompts the user to enter the number of miles traveled and the number of gasoline consumed and after that function miles_per_gallons() is defined to find the number of miles traveled by gasoline consumed in liter. Then cout() function is used to show the output of the program.

Sample Output:

Following is the sample output for the given program:

Enter the number of coupons: 25 
The number of Candy bars: 2 
The number of Gum Balls: 1 
The remaining coupons are: 2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Whentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."
Activity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.
2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Computer Programming for Beginners | Functions, Parameters & Arguments | Ep24; Author: Programming With Avelx;https://www.youtube.com/watch?v=VXlh-qJpfw0;License: Standard YouTube License, CC-BY