Open the project or solution named mpg in this folder: ex_starts\ch07_ex1_mpg Review the code and run the program to refresh your memory on how it works. Notice that, unlike the program in this chapter, this program lets the user perform more than one calculation, it stores the values the user enters in a text file, and it displays the total miles, total gallons, and average miles per gallon when the program starts and after each entry. Add a function that calculates the miles per gallon Define a function named calculate_mpg() before the main() function that calculates the miles per gallon. This function should accept two double values for the miles and gallons, round the result to two decimal places, and return the result as a double type. Modify the code in the main() function so it uses the calculate_mpg() function. Note that the miles per gallon is calculated in three different places. Move the definition for the calculate_mpg() function after the main() function. When you run the program, you’ll get a compile-time error that the function is not found. To fix this problem, add a declaration for the calculate_mpg() function before the main function. Add a function that displays the totals Declare a function named display_file_data() that will display the data in the text file. This function won’t accept any parameters or return any data. Define the display_file_data() function after the main() function. To do that, you can copy one of the occurrences of the code in the main() function that defines and opens the file and processes the data. Adjust the code as needed so it works within the function. Modify the code in the main() function so it uses the display_file_data() function.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter8: Arrays
Section: Chapter Questions
Problem 9E
icon
Related questions
Question
  1. Open the project or solution named mpg in this folder: ex_starts\ch07_ex1_mpg
  2. Review the code and run the program to refresh your memory on how it works. Notice that, unlike the program in this chapter, this program lets the user perform more than one calculation, it stores the values the user enters in a text file, and it displays the total miles, total gallons, and average miles per gallon when the program starts and after each entry.

Add a function that calculates the miles per gallon

  1. Define a function named calculate_mpg() before the main() function that calculates the miles per gallon. This function should accept two double values for the miles and gallons, round the result to two decimal places, and return the result as a double type.
  2. Modify the code in the main() function so it uses the calculate_mpg() function. Note that the miles per gallon is calculated in three different places.
  3. Move the definition for the calculate_mpg() function after the main() function. When you run the program, you’ll get a compile-time error that the function is not found. To fix this problem, add a declaration for the calculate_mpg() function before the main function.

Add a function that displays the totals

  1. Declare a function named display_file_data() that will display the data in the text file. This function won’t accept any parameters or return any data.
  2. Define the display_file_data() function after the main() function. To do that, you can copy one of the occurrences of the code in the main() function that defines and opens the file and processes the data. Adjust the code as needed so it works within the function.
  3. Modify the code in the main() function so it uses the display_file_data() function.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,