Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Purpose Practice creating C++ from creating a program plan (algorithm) to entering the program instructions, declaring variables, if statements, getting input from the user

Lab Purpose Practice creating C++ from creating a program plan (algorithm) to entering the program instructions, declaring variables, if statements, getting input from the user input file and displaying output in the console window, writing it to an output file, using loops.

Mandatory Instructions:

Write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the console window (and output file) as pictured below. You will need to use a while loop to read all the values!

1. Write the algorithm the list of steps needed to solve the problem. No C++ statements please! Use words like Get/Read, Sum, Average, Repeat, and Display. Think about what instructions you would need to read and process one value, then by putting this set of instructions in the loop you are able to process many values.

2. Write the C++ statements for the constant and variable declarations, choosing a name and data type for each one. Then write the C++ statements for the steps listed in step 1. Think about what C++ statement can be used for each step and carefully check the format and punctuation for each one.

3. Type the program Create a new C++ project folder in Visual Studio using your last name and first initial (e.g., MortonL_Lab3). Add a source file to the project. Put your name, class time and today's date in comments at the very beginning of the code. Add inline comments and the code in the main function.

4. Debug program Correct any errors found in your code.

5. Test program What values are you expecting to see? Are you seeing these values? Verify by computing the expected value yourself Excel may be useful to do this rather than entering all the values by hand into a calculator. In bonus part what should happen if the user enters a negative value or something larger than 100?

6. Run your program with input of 100 and screen capture the results which you should paste into the grade sheet. Once complete continue to the additional instructions below.

image text in transcribed

Additional Instructions:

Modify the code to ask the user for the number of values to read out of the data file and a new file name (use myowninput.txt). Create the myowninput.txt data file with at least 25 numerical values (one per line) and place it in the project folder where your .cpp file is stored. Make sure there are no blank lines at the end of the file.

Read the given number of values out of the file. This number has to be less than or equal to 25 and greater than 5 so validate it. If any other value is requested by the user, the program should terminate with an error message and not process any values. Verify the computed results.

image text in transcribed

Program Documentation & Style:

1. Declare all variables and constants that your program uses at the beginning of your program.

2. Your program should include two types of comments:

a. Program banner:

image text in transcribed

b. In-line comments:

There should be an in-line comment for each main step in your program. In general, this means a comment with each group of C++ statements that handles the input, the processing, and the output steps of your program.

3. Use meaningful identifier names

4. Include clear prompts for the user about entering the data.

5. Include clear descriptions of the results when you display them.

SAMPLE OUTPUT Data file: Largest value: lab3 input.txt Smallest value: Average of values: Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago