C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.5, Problem 8E
a)
Program Plan Intro
- Include library file for various operations.
- Declare file_name and line variables of string type.
- Create a data.txt file to store data values.
- Use while loop to read data from the file named data.txt.
- int main() function is used to perform all the task.
- Display the calculated results to the user.
- 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:
- Include library file for various operations.
- Declare uChoice, num, counter, sum,and loop variables of int type.
- Create a data.txtand tempfile.txt file to store data values.
- Use while loop to read data from the file named data.txt.
- int main() function is used to perform all the task.
- Display the calculated results to the user.
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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.1 - (Practice) Write array declarations for the...Ch. 7.1 - (Practice) Write correct notation for the first,...Ch. 7.1 - Prob. 3ECh. 7.1 - (Practice) a. Write output statements using cout...Ch. 7.1 - (Desk check) List the elements displayed by the...Ch. 7.1 - (Practice) a. Write a program to input the...Ch. 7.1 - (Practice) Write a program to input eight integer...Ch. 7.1 - (Data processing) a. Write a program to input 10...Ch. 7.1 - Prob. 9ECh. 7.1 - (Electrical eng.) Write a program that specifies...
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
Similar questions
- (Practice) Run Program 7.10 to determine the average and standard deviation of the following list of 15 grades: 68, 72, 78, 69, 85, 98, 95, 75, 77, 82, 84, 91, 89, 65, and 74.arrow_forwarduse code to develop a C program that gets a source file name from a user. If the file does not exist, it will generate a proper error and exits. If the file exists, it also gets the name of two files from the user, say destination1 and destination2. These files don't need to exist as they are files that need to be written to. The program then reads the source file line by line. If the line starts with an uppercase and ends with a lower case, it copies that line to dest1 (first destination file) If the line starts with a lowercase and ends with a dot ('.'), it copies that line to dest2 (second destination file) If neither of the above hold, the program discards that line (doesn't copy it anywhere) The program then displays a report mentioning how many lines were copied into each destination file. Don't forget to close all the files. Example: Assume that the source file is (<NL> = new line, <EOF> end of file): Souce: "myfile.txt" This is my first line<NL>…arrow_forward- in this exercise, please do not include and use string class. The function is using only array notation and manipulation.- string functions such as strlen is not allowed.- it should not have multiple return statements in the same function- there should be no global variable.- the function should not traverse the arrays more than once (e.g. looping through the array once only) A C++ PROGRAM named "changeCase" that takes an array of characters terminating by NULL character (C-string) and a boolean flag of toUpper. If the toUpper flag is true, it will go through the array and convert all lowercase characters to uppercase. Otherwise, it will convert all uppercase to lowercase. For example, if the array is {'H', 'e', 'l', 'l', 'o', '\0'} and the flag is true, then the array will become{'H', 'E', 'L', 'L', 'O', '\0'}. And if the flag is false, the array will become{'h', 'e', 'l', 'l', 'o', '\0'}arrow_forward
- -Convert SES variable to a factor and assign the value labels “low”, ”middle” and “high” to the 3 levels of thevariable. Then -Define the variables complic, comorb, depressi, diabetes as factors. For all these factors, a zero means “no” and a 1 means “yes”. Assign these value labels through the function factor() and check the change using str()arrow_forward-Suppose you have a C program whose main function is in main.c and has other functions in the files input.c and output.c: -How would you modify the above commands to link a library called process1 stored in the standard system library directory? -How would you modify the above commands to link a library called process2 stored in your home directory? -Some header files need to be read and have been found to be located in a header subdirectory of your home directory and also in the current working directory. - -How would you modify the compiler commands to account for this?arrow_forwardHow should I answer the following regarding the first main function?arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning