Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help writing this code \\Your task: implement in C++ the algorithm solution

ID: 3714380 • Letter: N

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 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.

Explanation / Answer

1.

2.int const MAX = 600;

3.string name[MAX];

4.int grade[MAX];

5.

int x, avg, sum=0;

inFile("indata3.txt");

6.if (!inFile)

cout << "file not found"<<endl;

else

{

cout << getData << endl;

}

7.inFile.open("indata3.txt");

8.x=0;

9.inFile >> name[x] >> grade[x];

10.while (x < quantity && x < 600)   

!inFile.eof();

11.x = x++;

12.inFile >> name[x] >> grade[x];

13.cout << "Enter the quantity of grades to be processed: ";

14.q = quantity;

15.for (x=0; x < q; x++)

16.sum = sum + grade[x];

17.avg = sum / q;

18.cout << "Average grade: " << avg <<endl;

19.cout << "Name: " <<"Grade: " << "Comment: " << endl;

20.for (int x = 0; x < q; x++)

21.cout << name[x] << grade[x];

22.if (grade[x] < avg)

23.cout << "Below average";

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

25.cout <<"Above average";

26. else

27.cout <<"Average";

28.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote