A liter is 0.264179 gallons. Write a
- Include required header files.
- Declare and initialize a constant value “lpg = 0.264179”.
- Define a function named “calc()” to calculate “milage”.
- Declare a variable “gal”.
- Compute “gal” and “milage”
- Function to return “milage”.
- Define a “main()” function.
- Declare the variables “lit” and “miles”.
- Declare a variable “ch”.
- “do… while” loop to get the user input repeatedly.
- Get the “lit” and “miles” from the user.
- Call “calc()” with an arguments “lit” and “miles” values and print the “milage”.
- Get the user input to repeat the program or not.
- The input is checked with the condition and repeat or exit the program.
Explanation of Solution
Program to compute number of miles per gallon the car delivered:
// Include required header files
#include <iostream>
using namespace std;
// Assign const value
float const lpg=0.264179;
// Function definition of calc()
float calc(float liters, float miles)
{
// Declare gal
float gal;
// Compute gal
gal = lpg * liters;
// Compute milage
float milage = miles/gal;
// Return milage
return(milage);
}
// Function definition of main()
int main()
{
// Declare lit and miles
float lit, miles;
// Declare ch
char ch;
// do... while loop
do{
// Get the liters
cout<<"\nEnter the number of liters of gasoline: ";
// Assign the user input to lit
cin>>lit;
// Get the miles
cout<<"\nEnter the number of miles Travelled: ";
// Assign the user input to miles
cin>>miles;
// Display the miles per gallon the car delivered
cout<<"\nNumber of miles per gallon the car delivered: ";
// Call the function cal() and return the result
cout<< calc(lit, miles) << endl;
// Get the user input
cout<<"\nDo you want to repeat(y/n)??: ";
// Assign the user input to ch
cin>>ch;
// While loop condition to check ch is equal to y
}while(ch=='y' || ch=='Y');
// Return 0
return 0;
}
Enter the number of liters of gasoline: 5
Enter the number of miles Travelled: 30
Number of miles per gallon the car delivered: 22.7119
Do you want to repeat(y/n)??: n
Want to see more full solutions like this?
Chapter 4 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- 4. def modify_data(x, my_list): X = X + 1 my_list.append(x) print(f"Inside the function: x = {x}, my_list = {my_list}") num = 5 numbers = [1, 2, 3] modify_data(num, numbers) print(f"Outside the function: num = {num}, my_list = {numbers}") Classe Classe that lin Thus, A pro is ref inter Ever dict The The output: Inside the function:? Outside the function:?arrow_forwardpython Tasks 5 • Task 1: Building a Library Management system. Write a Book class and a function to filter books by publication year. • Task 2: Create a Person class with name and age attributes, and calculate the average age of a list of people Task 3: Building a Movie Collection system. Each movie has a title, a genre, and a rating. Write a function to filter movies based on a minimum rating. ⚫ Task 4: Find Young Animals. Create an Animal class with name, species, and age attributes, and track the animals' ages to know which ones are still young. • Task 5(homework): In a store's inventory system, you want to apply discounts to products and filter those with prices above a specified amount. 27/04/1446arrow_forwardOf the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.arrow_forward
- Management Information Systemsarrow_forwardQ2/find the transfer function C/R for the system shown in the figure Re དarrow_forwardPlease original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinksarrow_forward
- Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinksarrow_forwardWhat is cloud computing and why do we use it? Give one of your friends with your answer.arrow_forwardWhat are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr