Lab Lesson 7 Part 2

profileminerlover1972

 

Part of lab lesson 7

There are two parts to lab lesson 7. The entire lab will be worth 100 points.

Bonus points for lab lesson 7

There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 10 (Gaddis Chapter 5). These have to be completed by the due date for lab lesson 7. For example, if you complete 89% of the activities you will get 8 points (there is no rounding).

Lab lesson 7 part 2 is worth 50 points

For part 2 you will have 40 points if you enter the program and successfully run the program tests. An additional 10 points will be based on the style and formatting of your C++ code.

Style points

The 10 points for coding style will be based on the following guidelines:

  • Comments at the start of your programming with a brief description of the purpose of the program.
  • Comments throughout your program
  • Proper formatting of your code (follow the guidelines in the Gaddis text book, or those used by your CS 1336 professor)
  • If you have any variables they must have meaningful names.

Development in your IDE

For lab lesson 7 (both parts) you will be developing your solutions using an Integrated Development Environment (IDE) such as Visual Studio, Code::Blocks or Eclipse. You should use whatever IDE you are using for your CS 1336 class. Once you have created and tested your solutions you will be uploading the files to zyBooks/zyLabs. Your uploaded file must match the name specified in the directions for the lab lesson. You will be using an IDE and uploading the appropriate files for this and all future lab lessons.

For this and all future labs the name of the source files must be:

lessonXpartY.cpp

Where X is the lab lesson number (7 for lab lesson 7) and Y is the part number (1 for part 1, 2 for part 2).

You will need to develop and test the program in your IDE. Once you are satisfied that it is correct you will need to upload the source file to zyBooks/zyLabs, and submit it for the Submit mode tests. If your program does not pass all of the tests you need to go back to the IDE, and update your program to fix the problems you have with the tests. You must then upload the program from the IDE to zyBooks/zylabs again. You can then run the tests again in Submit mode.

When running your program in Submit mode it is very important that you look at the output from all of the tests. You should then try and fix all of the problems in your IDE and then upload the updated code to zyBooks/zyLabs.

C++ requirements

  • The numbers need to be read in as type double. The calculations need to be done using type double as well.
  • You must properly handle end of file conditions.
  • You must properly open and close any files.

Failure to follow the C++ requirements could reduce the points received from passing the tests.

General overview

In this program you will be reading numbers from a file. You will validate the numbers and calculate the average of all of the valid numbers.

Your program will read in a file with numbers. The numbers will be of type double.

The numbers should be in the range from 0 to 105 (inclusive). You need to count all of the numbers between 0 and 105. You also need to calculate the average of these numbers. The average will be written out with four digits to the right of the decimal point.

If a number is not valid (that is, it is less than 0 or greater than 105) you need to count it (as a count of invalid values) and you need to write out the number to a file called "invalid-values.txt". Values written to file invalid-values.txt should be in fixed format with five digits to the right of the decimal point.

As you did in lab lesson 7 part 1 you need to read in the input file name using cin. The prompt for the input file name is:

Enter input file name

You need to properly handle end of file conditions. See lab lesson 7 part 1 for details on reading files. Also see Demo of file input and output of data in this unit.

The output from your program will be written to cout. The output must contain the file being processed, the total number of values read in from the file, the number of invalid values read in, the number of valid values read in.

The last thing you need to output is either the average of the valid values or an error message. The average must have four digits of precision to the right of the decimal point and must be in fixed format. If there is not valid average you should output the message:

An average cannot be calculated

In what case would you display this message?

If the input file cannot be opened, you will need to output a message. Assume the input file name is badinput.txt and it cannot be opened. You will display the following error message to cout

File "badinput.txt" could not be opened 

Here is an example of a working program:

Assume the file name read in from cin is:

input.txt

and that input.txt contains:

-12
0
98.5
100
105.5
93.5
88
75
-3
111
89
-12

Your program would output the following:

Enter input file name
Reading from file "numbers.txt"
Total values: 12
Invalid values: 5
Valid values: 7
Average of valid values: 77.7143

The contents written out to file invalid-values.txt are:

-12.00000
105.50000
-3.00000
111.00000
-12.00000

You are reading from an input file and you are writing to an output file. Make sure you close both files after you are finished using them. You must do this in your program, you cannot just let the operating system close the files for you.

For tests where there is output written to an output file the contents of the output file will determine if you passed that test or not. For cases where you have written out to cout the tests will check the output sent to cout. In some cases output will be written to a file and to cout. When this is the case the test will be run twice with the same input. Once to test cout and once to test the contents of the output file. An example of this would be tests 2 and 3. Both use the same input file. Test 2 check the output written to cout and test 3 checks the output written to the file invalid-values.txt.

Failure to follow the requirements for lab lessons can result in deductions to your points, even if you pass the validation tests. Logic errors, where you are not actually implementing the correct behavior, can result in reductions even if the test cases happen to return valid answers. This will be true for this and all future lab lessons.

Expected output

There are eight tests. Some tests are parts 1 and 2 of one test. Test 1 uses an input file that contains only valid values. Test 2 tests an input file that does not exist. Test 3 and 4 each have two parts. The first part tests the output to cout and the second part tests the contents of the output file invalid-values.txt. The final two tests have just one part.

You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course "How to use zyBooks" - especially section "1.4 zyLab basics".

Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.

Note: that the system("pause"); command runs the pause command on the computer where the program is running. The pause command is a Windows command. Your program will be run on a server in the cloud. The cloud server may be running a different operating system (such as Linux).

    • 2 years ago
    • 5
    Answer(0)