Question
Programming Assignment #4 Intro to CS Prepare a Lab Report Problem: Your friend the biology lab assistant needs to calculate the average time it takes
Programming Assignment #4
Intro to CS
Prepare a Lab Report
Problem: Your friend the biology lab assistant needs to calculate the average time it takes each of her rats to run through a given maze. For three days she runs each rat through the maze once, and records the amount of time it takes. Write a C++ program that will, after the test runs are all complete, calculate the average time it took for each of his rats to run the maze, and print a report to a file.
Input: The user should be prompted to input the name and 3 maze times for each rat. The name may have spaces in it. The three maze times will be positive integers. After the user has input the data for each rat, your program should ask the user if they have data for another rat. If they type Y or y, your program should allow them to input data for another rat.
Processing: Compute the average maze time for each of the rats by computing the mean of their 3 maze times.
Output: The program should output a lab report to a file named lab_report.txt. The first row of the report should be a list of column headers that label the data to be output. This should be followed by a row for each rat that lists their name, each of the three maze times, and the average. This should be followed by the word Superior if the average is less than than 25. Otherwise, if it is less than 35, it should be followed by the word Normal. If the average is 35 or over, the program should output Slow. The final average should be formatted to 1 decimal place. The numerical data in each column should line up under its column header.
Name Time 1 Time 2 Time 3 Avg Rating
Black Fred 28 40 29 32.3 Normal
Lima Bean 35 40 36 37.0 Slow
Master Splinter 25 27 39 30.3 Normal
Nicodemus 24 25 25 24.7 Superior
See the file output4.txt on the class website for the console output from running the program to create this output file.
output4.txt
Enter the name of the next rat:
Black Fred
Please enter the maze times for the rat.
28 40 29
Enter Y to add another rat, N to quit: Y
Enter the name of the next rat:
Lima Bean
Please enter the maze times for the rat.
35 40 36
Enter Y to add another rat, N to quit: Y
Enter the name of the next rat:
Master Splinter
Please enter the maze times for the rat.
25 27 39
Enter Y to add another rat, N to quit: Y
Enter the name of the next rat:
Nicodemus
Please enter the maze times for the rat.
24 25 25
Enter Y to add another rat, N to quit: N
The lab report is stored in the file lab_report.txt
Additional Requirements:
For full credit, you must use appropriate loop constructs, and your program should work for any number of rats (not always four).
For full credit, your program should allow spaces in the rat names. You will receive a small point deduction if your program works only for rats without spaces in their names. Hint: use cin >> ws; immediately before getline.
Hint: set up your output file and output the column headers BEFORE the loop that processes the rat names and times.
Hint: output the data to the file immediately after it is input from the user or computed by your program. Re-use one variable for the time to run the maze.
All of the output data can be LEFT justified for this assignment.
The name should be displayed in a width of 20 characters, the numerical data should be displayed in a width of 7 characters each.
Note that the column headers may be output as one long string with spaces embedded in the proper places.
Use proper data types (only use float and double when necessary).
Your program must compile and run, otherwise you will receive a 0.
See the Style Guidelines document on the course website. The grader will deduct points if your program violates the style guidelines.
STYLE GUIDELINES
Variable names:
--must be meaningful
--loop index names can be simple (i, j, k, etc)
--The initial letter should be lowercase, following words should be capitalized, no other caps or punctuation (ie: weightInPounds). This is called "camel case".
Named constants:
--use for most numeric literals, including array sizes
--all capitals with underscores (ie: TX_STATE_SALES_TAX)
--should occur near the top of the program
DO NOT USE GLOBAL VARIABLES!! (all variables should be defined INSIDE of a function)
Line length of source code should be no longer than 80 characters (no wrapping of lines).
Indentation:
--Use 2-4 spaces (but be consistent throughout your program).
--Indent blocks, within blocks, etc.
--Use blank lines to separate sections.
Comments for variables and functions:
All variable declarations should be commented as follows:
int rank; // numeric value for a card, A=1, J=11, Q=12, K=13
Function definitions should be commented to describe what it does, what the parameters are, and what the function returns (when appropriate). See the template and the example below. If the function body contains more than about five statements, there should be comments to describe the various sections of code in the function body.
Template:
//***********************************************************
// function name: short description of what the function does.
//
// param-1 description of first parameter (if any)
// param-2 description of second parameter (if any)
// (remaining params, if any) // returns: description of what function returns (if not void) //***********************************************************
Example:
//***********************************************************
// getBestPlayer: determines which player scored the most points
// p the array of player information
// size the number of players in the array
// returns the name of player who scored the most points //***********************************************************
string getBestPlayer(Player p[], int size) {
// function body goes here
}
In-code comments: DO NOT comment every line of code! In general, try to avoid using comments that describe WHAT the code is doing. These are redundant (we can just read the code). Comments that explain WHY the code is doing what it is doing are more helpful. Try to minimize in-code comments, and write readable code instead.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started