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

Using C/C++ define a struct Student which has three properties: id, score, and g

ID: 3683438 • Letter: U

Question


Using C/C++ define a struct Student which has three properties: id, score, and grade. id is in integer typo, score is in double type and grade is in char type. Using Student to declare an array with 20 elements in main(); assign the ids of the students from 1 to 20; assign the scores of each student with random within [10, 99]; then - define a function and pasS the student array aa parameter(s). In the function, assign the grade of each student according to his scores (e.g; if score is >=90, assign 'A' grade; else if score is >=80, assign 'B'; grade else if score is >=70, assign 'C'; else if score is >=60, assign 'D'; otherwise, assign 'F'; after the function returns, print all students' ids, scores, and grades accordingly.

Explanation / Answer

#include<cmath>
#include<cstdlib>
#include<cstring>
#include <iostream>
using namespace std;
struct student {
   int id;
   double score;
   char grade;

};

void setGrade(student stud[]) {
   int i = 0;
   for (i = 1; i <= 20; i++) {
       if (stud[i - 1].score >= 90) {
           stud[i - 1].grade = 'A';
       } else if (stud[i - 1].score >= 80) {
           stud[i - 1].grade = 'B';
       } else if (stud[i - 1].score >= 70) {
           stud[i - 1].grade = 'C';
       } else if (stud[i - 1].score >= 60) {
           stud[i - 1].grade = 'D';
       } else {
           stud[i - 1].grade = 'F';
       }
   }
}

int main() {
   struct student stud[20];
   int i = 1;
   double score;
   for (i = 1; i <= 20; i++) {
       stud[i - 1].id = i;
       score = 10 + rand() % 89;
       cout << score;
       stud[i-1].score = ((double) score * 1.0);
   }

   setGrade(stud);

   for (i = 0; i < 20; i++) {
       cout << " Id : " << stud[i].id << " Score : " << stud[i].score << " Grade : " << stud[i].grade;
   }

}

Let me know in case of issues.

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