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

objective In this assignment you will implement nested loops in a program to ass

ID: 3864860 • Letter: O

Question

objective In this assignment you will implement nested loops in a program to assign grades to students in a class at the end of a semester Description: The program should first input the number of scores that will be a fixed number for all students. Then using a while loop, the program should input a student's ID. The while loop ends when the users enters a character other than Y' for the student ID. For each student, the score must be entered using a loop (for loop that iterates from 1 till number of scores). This loop will be nested inside the outer while loop that inputs the IDs. Calculate the average of scores made by each student and assign one of the three possible grades: A, B, C, D, F, and I. When entering the scores, if a student had an excused absence for a score it will be entered as -1. If a student has 2 or more excused absences, give the student a grade of I. If the student has less than 2 excused absences then compute the average and determine the grade. Of course for a student with 1 excused absence the average should not count the -1 score. For example, if the input scores for a student were 53, -1, 49 and 50, your program would ignore the -1, since this is the student's only absence. For this student average will be (53+49+50)/3.0. Grades A, B, C, D, and F are assigned based on the average score as: A: avg, score 90 B: 80 avg. score 90 C: 70 avg, score 80 D: 60 avg, score

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;


int main(int argc, char const *argv[])
{
   cout<<"Enter number of scores for this semester ";
   int scores;
   cin>>scores;
   int stA=0,stB=0,stC=0,stD=0,stF=0,stI=0;//keep count number of students getting grades
char id;
int student=1;
cout<<"Enter student ID ";
cin>>id;
   while(id=='Y')//stop loop when user enters other than Y
   {
       cout<<"For student No: "<<student;
       student++;
       int sum=0;//store sum of scores
       int score;
       int c=0;//to keep count for how many students where absents
       int subjects=0;
       for (int i = 1; i <=scores; ++i)
       {
           cout<<"Enter score "<<i<<endl;
           cin>>score;//score for each subject
           if(score==-1)
           {
               c++;//increment absent count
           }
           else
           {
               sum+=score;
               subjects++;
           }
       }

       if(c>1)
       {
           cout<<"Grade is I"<<endl;//for absent more than 1 subject
           stI++;
       }
       else
       {
           int avg=sum/subjects;//find avearge of subjects

           if(avg>=90)
           {
           cout<<"Grade is A"<<endl;
           stA++;
           }else if(avg>=80&&avg>90)
           {
               cout<<"Grade is B"<<endl;
               stB++;
           }else if(avg>=70&&avg<80)
           {
               cout<<"Grade is C"<<endl;
               stC++;
           }else if(avg>=60&&avg>70)
           {
               cout<<"Grade is D   "<<endl;
               stD++;
           }else
           {
               cout<<"Grade is F"<<endl;
               stF++;

           }
       }
       cout<<"Enter student ID ";
       cin>>id;
   }
   //print summary
   cout<<"Number of students who got Grade A is "<<stA<<endl;
       cout<<"Number of students who got Grade B is "<<stB<<endl;
   cout<<"Number of students who got Grade C is "<<stC<<endl;
   cout<<"Number of students who got Grade D is "<<stD<<endl;
   cout<<"Number of students who got Grade F is "<<stF<<endl;
       cout<<"Number of students who got Grade I is "<<stI<<endl;


   return 0;
}

============================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ grade.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter number of scores for this semester
3
Enter student ID
Y
For student No: 1Enter score 1
60
Enter score 2
-1
Enter score 3
-1
Grade is I
Enter student ID
Y
For student No: 2Enter score 1
98
Enter score 2
95
Enter score 3
92
Grade is A
Enter student ID
C
Number of students who got Grade A is 1
Number of students who got Grade B is 0
Number of students who got Grade C is 0
Number of students who got Grade D is 0
Number of students who got Grade F is 0
Number of students who got Grade I is 1