a. Assume that you have the two-dimensional array program which was explained in
ID: 3533149 • Letter: A
Question
a. Assume that you have the two-dimensional array program which was explained in the class (the code
of the program is posted on Blackboard). Create a new C++ project and add the source code of the
program to it.
b. Add a new function called modify_grades that takes the 2-dimensional array, grades[i][j], and two
indices in order to modify the grade of quiz_j for student_i.
c. Add a function called highest_score_in_quiz which takes the 2-dimensional array, grades[i][j], and
the quiz number and returns the index of the student who got the highest score in that quiz. You need
to test this function in your main program, for example, by outputting both the index of the student
who got the highest score and the score she/he got.
d. Add a new function called highest_score_for_student that takes the 2-dimensional array, grades[i]
[j], and the student number and returns the index of the quiz which she/he got the highest score in
among all the quizzes she/he took. You need to test this function in your main program, for example,
by outputting the student number and the quiz number she/he got the highest score in and the score
itself.
Explanation / Answer
#include int main() { // an array of double to store student's score double studentscore[50]; // a 2D array of string to store student's name char studentname[50][50]; double studentavg = 0.0, sumscore = 0.0, averagescore = 0.0, highestscore =0.0; // index and terminal variables int i = 0, stop = 0, k = 0; // read and store student name and score do { printf("Enter student name: "); // null terminated string, scanf_s() only accept 1 string // can try gets()/gets_s() scanf_s("%s", &studentname[i], sizeof(studentname[i])); printf("Enter student score: "); scanf_s("%lf", &studentscore[i]); // increment the array index i++; // continue for next data? printf("More data? -1 to stop, others to continue: "); scanf_s("%d", &stop); } while(stop != -1); // some cosmetic... printf(" =================REPORT==================== "); printf("Student Name Score "); printf("------------ ----- "); // set initial value of the highest score to the 1st array element // and then compare 1 by 1 in the for loop... highestscore = studentscore[0]; // the i index less 1, coz we increment after storing it // in the do-while loop... for(k=0;kRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.