In: Computer Science
Write a C++ program that reads a students name followed by 7 numeric grades from a file. Compute the average grade after dropping the lowest grade. Assign letter grades via this scale .Please show steps in the comments .
A 90 – 100
B 80 --89
C 70 –79
D 60 -69
F 0 - 59
Input format:
Sam 100 90 87 23 12 67 95
Mary 30 20 90 90 90 90 88
Mark 80 90 80 80 90 87 100
End of file
REPORT
Name Grade
Sam C
Mary A
Mark B
The student with the highest average is Mary (99.99)
The student with the lowest average is Sam (99.99)
C++ program to find average, total and grade
Steps:
Source code
#include<iostream>
#include<conio.h>
using namespace std;
int main ( )
{
// define struct and decide the number of subjects
struct student
{
int subject1 ;
int subject2 ;
int subject3 ;
int subject4 ;
int subject5 ;
int subject6 ;
int subject7 ;
};
// define number of students markes have to be collected
int i , n, total;
float av ;
struct student st[20];
char name[20];
cout<<" \n Enter the Number of Students marks wish to enter : " ;
cin>> n ;
for (i =0; i<n; i++)
{
// Collecting the basic details
cout<<"Enter the name of Student: ";
cin>>name;
cout<<"\nEnter the Marks of seven Subjects : " ;
total = 0 ;
cin>> st[i].subject1 >>st[i].subject2>>st[i].subject3>>st[i].subject4>>st[i].subject5>>st[i].subject6>>st[i].subject7;
total = st[i].subject1+st[i].subject2+st[i].subject3+st[i].subject4+st[i].subject5+st[i].subject6+st[i].subject7;
av = (float) total /7 ;
cout<<"Total mark is :"<<total;
cout<<"\nAVERAGE Marks of the Student is : "<< av ;
cout<<"\nYour Grade is :: ";
// define the conditions of grade
if(av>89)
{
cout<<"[ A ]\n";
}
else if(av>79 && av<=89)
{
cout<<"[ B ]\n";
}
else if(av>69 && av<=79)
{
cout<<"[ C ]\n";
}
else if(av>59 && av<=69)
{
cout<<"[ D ]\n";
}
else
{
cout<<"[ F ]\n";
}
}
return 0;
}
The output: