Concept explainers
a.
Top-down design for calculating the average of ten test scores:
From the problem 54,
- Assign value to the given variables.
- Perform loop iteration for 10 times.
- Get the input from user.
- Compute the sum of 10 test scores.
- Increment the value of counter.
- Finally, find the average of 10 scores.
Example:
The example code for calculating average of ten scores is given below:
//Initialize count to 0
Set count to 0
//Initialize total to 0
Set total to 0
//Performs iteration for 10 times
WHILE (count < 10)
//Read the scores
Get mark
//Compute sum of test score
Set total to total + mark
//Performs increment for count
Set count to count + 1
//Print the result of average
Set average to total/10
Explanation:
The above code is used for calculating the average of ten scores using “WHILE” loop. In “WHILE” loop, the addition will perform until the score become greater than “10”.
b.
Top-down design for calculating the average of an unknown number of test scores:
- Assign value to the given variables.
- Performs iteration for n times.
- Get the input.
- Compute the sum of test scores for n scores.
- Increment the value of counter.
- Finally, determine the average of test scores.
Example:
The example code for calculating average of unknown number of scores is given below:
//Initialize count to 0
Set count to 0
//Initialize total to 0
Set total to 0
//Performs iteration for n times
WHILE (number of scores)
//Read the scores
Get mark
//Compute sum of test score
Set total to total + mark
//Performs increment for count
Set count to count + 1
//Print the result of average
Set average to total / count
Explanation:
The above code is used to compute the sum of score for “n” values using “WHILE” loop. In “WHILE” loop, the addition will perform until the score becomes greater than “n”.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Computer Science Illuminated
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education