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

CS 46 - C Programming Write a program to manipulate an array that contains a max

ID: 3621827 • Letter: C

Question

CS 46 - C Programming

Write a program to manipulate an array that contains a maximum of 100 grade scores. Each grade is stored as type double. Global variables are not allowed, and all references to the grades array (outside of main() ) must use pointer notation. You must write 6 functions described below:

main()
defines the array
calls the other 5 functions listed below within a do while loop

menu() - displays 5 choices (1=get grades, 2=show grades, 3=change, 4-find, 5=quit).

getgrades() - this function enters grades into the array
received the array as an argument
within a loop:
prompts for a grade, or 0 to quit
gets a grade until 0 is entered
returns the count of how many grades were entered

showgrades() - this function displays all the grades and positions
receives the array and count
displays all the grades entered with position 0 shown as position 1.
Position Grade
1 96
2 88
3 74
4 91
etc.

changegrade() - this function allows changes to any grade
receives the array and count
prompts for element position of grade or 0 if no changes
(use position 1 as element 0).
prompts for new grade and updates array

findgrades() - this function displays a list of the grades within a range of grade values (low to high, e.g. if you wanted all students that received a B, enter 80 for low and 89 for high). Note: it is not necessary to sort the array of grades to do this.
receives the array and count
prompts for the lowest grade to locate
prompts for the highest grade to locate
displays all grades within (inclusive) the range low to high

Explanation / Answer

#include int menu(); int getgrades(double *); void showgrades(double *, int); void changegrade(double *, int); void findgrades(double *, int); int main() { double grades[100]; int ch, count; do{ ch=menu(); switch(ch) { case 1: count=getgrades(grades); break; case 2: showgrades(grades,count); break; case 3: changegrade(grades, count); break; case 4: findgrades(grades, count); break; case 5: break; } }while(ch!=5); return 0; } int menu() { int ch; printf(" 1. Get grades"); printf(" 2. Show grades"); printf(" 3. Change"); printf(" 4. Find"); printf(" 5. Quit"); printf(" Your Choice: "); scanf("%d",&ch); return ch; } int getgrades(double *ptr) { int count =0; while(1) { printf(" Enter grade score(0 to exit): "); scanf("%lf",ptr); if(*ptr == 0) break; ptr++; count++; } return count; } void showgrades(double *ptr, int count) { int i; printf(" Position Grade "); for(i=0; i