can anyone show me how to do this program by the nested loop? I\'m taking cs1 cl
ID: 3864888 • Letter: C
Question
can anyone show me how to do this program by the nested loop? I'm taking cs1 class 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, scoreExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int number;
char ch;
int id,i;
float sum=0;
float average=0;
cout << "Enter the number of score for this semester :" ;
cin >>number;
int score[number];
char grade;
do{
cout<<"=================================================="<<endl;
cout<<"Add a Student(Y for continue and any other character to end) : ";
cin>>ch;
if(ch=='Y')
{
cout<<"Enter the Student ID :";
cin>>id;
for(i=0;i<number;i++)
{
cout<<"Enter a Score : ";
cin>>score[i];
}
int exec=0;
for(i=0;i<number;i++)
{
if(score[i]==-1)
{
exec=exec+1;
}
else
{
sum=sum+ (float)score[i];
}
}
if(exec>=2)
{
cout<<"ID = "<<id<<" Excused = "<<exec<<" Grade is = I"<<endl;
}
else
{
average= (float)(sum+exec)/(number-exec);
if(average>=90)
{
grade='A';
}
if(average>=80 && average< 90)
{
grade='B';
}
if(average>=70 && average< 80)
{
grade='C';
}
if(average>=60 && average< 70)
{
grade='D';
}
if(average>=0 && average< 60)
{
grade='E';
}
cout<<"ID = "<<id<<" Average = "<<average<<" Grade is ="<<grade<<endl;
}
}
}while(ch=='Y');
return 0;
}
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.