Use your solution for Lab 1 and add a menu option to fill the array with values from a file. The first entry in the file will be the number of values that follow (ie the size of the array). Be sure to handle every possible error condition. Test your code through the Lab 2 test plan below and the Lab 2 Sample Files (although not all error conditions are in the sample files so you may need to make more files use Notepad).
Lab 2 Test Plan:
Menu Testing
Condition | Input | Result |
Menu input of 6 first | 6, then Prompt for name of file | File should be processed per testing below |
Menu input of 2 | 2 (then enter 3 for size of new array) | Input accepted, back to menu |
Menu input of 4 | 4 | Values should print 0.0 0.0 0.0 |
Menu input of 3 | 3 (then values -1 -2 -3) | User should be prompted to enter 3 numbers |
Menu input of 5 | 5 | Average of -2.0 should be displayed |
Menu input of 6 | 6, then Prompt for name of file | File should be processed per testing below |
Menu input of 7 | 7 | Program ends |
File Testing
Condition | Input | Result |
Bad file name | lab2 | Error Message file does not exist. (Back to menu) |
Good file | lab2.txt contains4 1 2 3 4 | Input accepted, data read, back to menu |
Menu input of 4 | Values 1 2 3 4 should display | |
Menu input of 5 | Average 2.5 should display | |
Bad file wrong number of entries | Lab2bad1.txt contains4 1 2 3 | Error Message missing values in file did not process file (Back to menu) |
Bad file invalid value for number of entries | Lab2bad2.txt containsA 1 2 3 | Error Message Invalid data in file did not process |
Bad file invalid value for an entry | Lab2bad3.txt contains 4 1 2 a 3 | Error Message Invalid data in file did not process |
Bad file contains more values than number of entries | Program processes number of entries and ignore rest of file |
Reviews
There are no reviews yet.