Question: Need help writing this code Your task: implement in C++ the algorithm solution shown below. Algorithm solution (in pseudocode): 1. Declare variable inFile to get

Need help writing this code

\Your task: implement in C++ the algorithm solution shown below. Algorithm solution (in pseudocode): 1. Declare variable inFile to get the data from an input file

2. Declare a named constant MAX = 600

3. Declare an array of strings named name that holds up to MAX elements

4. Declare an array of whole numbers named grade that holds up to MAX elements

5. Declare variables quantity, x, avg, and sum (initialized to zero) that hold whole numbers

6. Open file indata3.txt

7. Check if the file was opened (if not opened, show an error message and stop the program)

8. Set x to 0

9. Read a name and a grade from the file and assign them to name[x] and grade[x] respectively

10. While (not-end-of-file)

11. Increment x

12. Read a name and a grade from the file and assign them to name[x] and grade[x] respectively

13. Print "Enter quantity of grades to be processed (0-", x, "): "

14. Read a value from the keyboard and assign it to quantity

15. For (x = 0 to quantity-1)

16. Accumulate grade[x] in sum

17. Assign to avg the value returned by average (sum, quantity)

18. Print "Average grade: ", avg

19. Print "Name", "Grade", " Comment"

20. For (x = 0 to quantity-1)

21. Print name[x], grade[x]

22. If (grade[x] < avg)

23. Print " below average"

24. Else if (grade[x] > avg)

25. Print " above average"

26. Else

27. Print " average"

28. Close the file. Function average( ) receives the values of sum and quantity, calculates the average, and rounds it to the nearest whole number (ones) before returning it. Use appropriate type casting to avoid loss of information when calculating the average.

Note: if the value of quantity is zero, the function returns 0, otherwise it returns the average.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!