Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- New Skills Practiced (Learning Goals)
- Problem solving and debugging.
- Use of selection structures (making decisions).
- Use of repetition structures (looping).
- Formatting output to meet specifications.
- The data files for this assignment will contain several data sets. Each data set will consist of several positive and/or negative integers terminated by the sentinel value, 0. Each value in the file will be separated by whitespace. Here is a sample data file with 2 data sets:
- 4 12 -32 0
- 715 45
- 47 -3 21
- 19 0
- Design and implement a C++ program that will do the following.
- Display your name, lecture section #, and assignment #.
- Read the data from a file (as described above) using Linux redirection and
- generate a table that displays
- a data set #, the number of values in the data set, the sum of the values in the data set, the average of the values in the data set, the largest value in the data set and (if the largest value is greater than 0) the number of factors it has
- When all data has been read and the table is complete, display the total number of non-zero values read, their sum, and average with appropriate labels.
- NOTES:
- Assumptions about input: (you do not have to test for these conditions)
- the data file will exist, will not be empty, and all input values will be integers
- each data set will be terminated by a 0
- a data set can be empty (no values preceding the 0)
- each input value will be separated by whitespace (blanks and/or linefeeds)
- the last line in the data file will be terminated with a linefeed ('\n')
- Program must be designed to run in batch mode (no prompts) via Linux redirection.
- Display averages as floating point numbers with 3 digits to the right of the decimal.
- If there are no values in a data set, leave the average column blank.
- Display data set #, counts, and sums as integers.
- Right justify all numbers displayed in table. The maximum number of columns needed to display a number (including negative sign and decimal) is 11. Make sure numbers do not run together in the table.
- Display final count and sum as integers with labels.
- Display final average with 3 digits to the right of the decimal and a label.
- Documentation (12 pts)
- When the program compiles and runs correctly, add the following documentation (comments) to your source file (.cpp file).
- Place a comment with your name, lecture section#, and assignment # at the beginning of the file.
- List the expected input to the program. If the input will be read from a file, list (describe) the file's content.
- List the expected output of the program. (If the input values are supposed to be displayed, include them in the output list.)
- Provide a meaningful description of what each constant and major variable represents in the program. Place these comments with the constant/variable declarations.
- Programming Style (8 pts)
- Make sure that your program is formatted to promote readability. (indent, 1 statement per line, blank lines, etc)
- Make sure all constants and variables have meaningful names.
- Try to use a naming convention that makes it easy to distinguish between constants and variables.
- Make sure all constants are declared before the start of the main function and that all variables are declared at the beginning of the main function.
- Sample terminal session:
- [lee@bobby keys]$ more data4three
- 4 12 -32 0
- 715 45
- 47 -3 21
- 19 0
- 0
- 5 33 172 222 14
- -15 123 0
- [lee@bobby keys]$ g++ assign03.cpp
- [lee@bobby keys]$ ./a.out < data4three
- Lee Misch LecSec#10__ Assignment #3
- Data Largest #
- Set# Count Sum Average Largest # Factors
- ================================================================
- 1 3 -16 -5.333 12 6
- 2 6 844 140.667 715 8
- 3 0 0 0
- 4 7 554 79.143 222 8
- ================================================================
- Count of all non-zero #s: 16
- Sum of all non-zero #s: 1382
- Average of all non-zero #s: 86.375
- Submitting your program
- Test your program with enough data to verify that it works properly. The sample data file shown above does not test all requirements.
- Make sure you have included the required documentation.
- Make sure it compiles and runs on bobby.cs.unlv.edu AFTER adding the documentation.
- Follow the steps described in the submit handout.
- Return to assignments list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement