C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Question
Book Icon
Chapter 7.5, Problem 8E

a)

Program Plan Intro

Program Plan: 

  1. Include library file for various operations.
  2. Declare file_name and line variables of string type.
  3. Create a data.txt file to store data values.
  4. Use while loop to read data from the file named data.txt.
  5. int main() function is used to perform all the task.
  6. Display the calculated results to the user.
  7. Close the file after displaying the content of the file.

Program Description: The main purpose of the program is to read and display the data from the data.txt file.

b)

Program Plan Intro

Program Plan: 

  1. Include library file for various operations.
  2. Declare uChoice, num, counter, sum,and loop variables of int type.
  3. Create a data.txtand tempfile.txt file to store data values.
  4. Use while loop to read data from the file named data.txt.
  5. int main() function is used to perform all the task.
  6. Display the calculated results to the user.
  7. Close the file after displaying the content of the file.

Program Description: The main purpose of the program is to modify the program given in part (a) such that the program will be able to:

  • Delete the first number of the file.
  • Add a new integer data value at end of the file.
  • Compute and display the average of all numbers given in the file.
  • Overwrite theold file data with the new list of numbers.

Blurred answer
Students have asked these similar questions
Using the code and the function above
Show the output of the following code:
Practice problem we were given in C++ to review for test. Thanks Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements: Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file. Save the output of the program in a file. Write a function called getNumber which reads a number from the input file, outputs the number to the output file and the monitor and sends the input number to the function main. Make sure, both input and out file are being opened in the main program. Write a function called classifyNumber which counts number of even, odd, and zero (occurrences of zero) available in the input file. Have the program find the sum and average of the numbers and print only 10 numbers per line. Write a function called printResult so that it outputs (in output file and monitor) even number of…

Chapter 7 Solutions

C++ for Engineers and Scientists

Ch. 7.2 - (Practice) Write array declarations, including...Ch. 7.2 - (Data processing) Write an array declaration...Ch. 7.2 - (Data processing) Write a program that uses an...Ch. 7.2 - (Electrical eng.) Write a program that stores the...Ch. 7.2 - (Practice) a. Write a declaration to store the...Ch. 7.3 - (Practice) Write specification statements for the...Ch. 7.3 - (Desk check) Determine the output produced by the...Ch. 7.3 - (Practice) a. Write a C++ program that adds the...Ch. 7.3 - (Practice) Write a C++ program that adds...Ch. 7.3 - Prob. 5ECh. 7.3 - (Electrical eng.) a. An engineer has constructed a...Ch. 7.4 - Prob. 1ECh. 7.4 - Prob. 2ECh. 7.4 - Prob. 3ECh. 7.4 - Prob. 4ECh. 7.4 - Prob. 5ECh. 7.4 - (Electrical eng.) Write a program that declares...Ch. 7.4 - (Statistics) Write a program that includes two...Ch. 7.5 - Prob. 1ECh. 7.5 - (Practice) Run Program 7.10 to determine the...Ch. 7.5 - Prob. 3ECh. 7.5 - (List maintenance) a. Write a complete C++ program...Ch. 7.5 - Prob. 5ECh. 7.5 - (List maintenance) The following letters are...Ch. 7.5 - (File creation) Write a C++ program that creates...Ch. 7.5 - Prob. 8ECh. 7.5 - Prob. 9ECh. 7.5 - Prob. 10ECh. 7.5 - Prob. 11ECh. 7.5 - Prob. 12ECh. 7.5 - Prob. 13ECh. 7.5 - Prob. 14ECh. 7.5 - Prob. 15ECh. 7.6 - Prob. 1ECh. 7.6 - Prob. 2ECh. 7.6 - Prob. 3ECh. 7.6 - Prob. 4ECh. 7.6 - Prob. 5ECh. 7.6 - Prob. 6ECh. 7.6 - Prob. 7ECh. 7.6 - Prob. 8ECh. 7.6 - (Practice) Use the max_element and min_element...Ch. 7 - (Statistics) a. Write a C++ program that reads a...Ch. 7 - (Practice) Define an array named peopleTypes that...Ch. 7 - (Numerical) Given a one-dimensional array of...Ch. 7 - (Numerical) Write and test a function that returns...Ch. 7 - (Sorting) Read a set of numerical grades from the...Ch. 7 - (Numerical) a. Define an array with a maximum of...Ch. 7 - (Numerical) Using the srand() and rand() C++...Ch. 7 - (Statistical) In many statistical analysis...Ch. 7 - (Data processing) Your professor has asked you to...Ch. 7 - (Modify) Modify the program written for Exercise 9...Ch. 7 - Prob. 11PPCh. 7 - (Data processing) The answers to a true-false test...Ch. 7 - Prob. 13PPCh. 7 - (Data processing) Construct a three-dimensional...Ch. 7 - (Computation) A magic square is a square of...Ch. 7 - (Computation) Among other applications, Pascal’s...
Knowledge Booster
Background pattern image
Similar 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