hat does the extraction and analysis described above except that the tasks shall be made somewhat simpler. The program shall read from a file "inputdata.txt" containing a name and exactly five values of floating point numbers per line in the file. The first line of the file shall contain the name of the person (first and last) that gathered the data i.e. Joe Jones. The second line of the file shall be the first row of data.  Your program will process all the lines in the file as described below. As the program reads each row of data, it shall do two things: it shall keep a running sum of the values read for that row, and shall also write the average of that row to a file "averages.txt". The program will continue reading from the file until it reaches the end of the file. This will entail using a "while" loop and the eof() function that is talked about in Chapter 13 of the text book. The person's name is to be read in at one time using "getline" and stored under a single variable name.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

create a program in C++ that does the extraction and analysis described above except that the tasks shall be made somewhat simpler. The program shall read from a file "inputdata.txt" containing a name and exactly five values of floating point numbers per line in the file. The first line of the file shall contain the name of the person (first and last) that gathered the data i.e. Joe Jones. The second line of the file shall be the first row of data.  Your program will process all the lines in the file as described below.

As the program reads each row of data, it shall do two things: it shall keep a running sum of the values read for that row, and shall also write the average of that row to a file "averages.txt". The program will continue reading from the file until it reaches the end of the file. This will entail using a "while" loop and the eof() function that is talked about in Chapter 13 of the text book. The person's name is to be read in at one time using "getline" and stored under a single variable name.

Note that the program shall have no interaction with a user except for starting the program using an IDE or the command line. This means that the program shall NOT prompt the user for the entry of any data. When the program is done, it shall print to the screen the name of the person that sent the data i.e Joe Jones and the name of the output file i.e. "averages.txt". 

Software Design

The design of the program consists of two function definitions: mainrowAverage.

float rowAverage(float num1, float num2,float num3,float num4,float num5)

Declare five floating point variables to hold the five numbers that are being sent each time from a row in the input file. (Note: These five variables could be declared more appropriately using an array, but we are not covering that data structure until next unit, so do not use it here.) Set up the function to add up all the values sent and save them in a local variable. Then using that variable divide by 5 and save it in another local variable. Return this value back to the "main" function that has called this function. Now it would be much easier to do all this in the "main" but we are setting things up for the topic of the next unit.

Print just the averages the output file (nothing more or nothing less). i.e.

24.63
56.1
48.9
  .
  .
  .

See inputData.txt (attached file) for a sample of what the input file would look like.

Complete each part of the program by translating the software design information (described in the section above) into C++ source code. Remember to place any local variable declarations at the top of the block of the function definition so that they occur before any of the executable statements.

Save the contents of the file

Use your IDE to compile the contents of your source code file

If any syntax errors are detected by the g++ compiler, or any warning messages appear, correct the errors, save the contents of your source code file, and recompile the file. Continue this step until all syntax errors in the program are corrected and no warning messages appear

Link the program. (The g++ compiler automatically performs this link step for you after you compile the program if your program contains no syntax errors)

Test your program using the input-data.txt file. (You can open a command prompt window and run the program there or from within your IDE.) If any logical errors occur (i.e., program does not fulfill the requirements or produces incorrect output), make corrections in your source code file, save the file, compile and link the file, and run the program again. Continue to do this step until the logical errors are corrected.

To test your error detecting statements in the main function, first use a text editor to change the numbers in the first line of the input-data.txt file. Then use that file as your input file to the program.

Joe Jones
17.186 20.667 12.508 14.053 15.123
12.831 14.917 15.045 15.8
19.816
14.96 11.698 19.275 11.391 14.313
10.45 11.926 11.366 13.372
16.638
14.924 13.434 10.045
15.616
10.654
20.954 17.025 19.64 11.983 19.377
11.856 13.166 10.835 19.815
11.1
19.664 20.519 11.358 10.576 14.735
11.052 13.08 16.244 16.982 13.241
16.632 11.061 12.057 12.539 11.021
16.851 11.37 12.421 11.334
11.712
Transcribed Image Text:Joe Jones 17.186 20.667 12.508 14.053 15.123 12.831 14.917 15.045 15.8 19.816 14.96 11.698 19.275 11.391 14.313 10.45 11.926 11.366 13.372 16.638 14.924 13.434 10.045 15.616 10.654 20.954 17.025 19.64 11.983 19.377 11.856 13.166 10.835 19.815 11.1 19.664 20.519 11.358 10.576 14.735 11.052 13.08 16.244 16.982 13.241 16.632 11.061 12.057 12.539 11.021 16.851 11.37 12.421 11.334 11.712
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education