Using C++ • Define a structure that holds the following information about each s
ID: 3728016 • Letter: U
Question
Using C++
• Define a structure that holds the following information about each student:
* An int number for ID
* Four int number for Math, English, Science, and Art
* A float number for GPA
• Write a function called Report that receives a student structure as a parameter, prints a message if the student has failed a course, and returns the GPA.
* Notice that if you set the GPA member of structure in the function, it won’t work outside the function.
• In your main function, stay in a loop and ask the user to enter grades for 3 students. For each, calculate the GPA, and at the end identify which student had the highest GPA.
• Define a structure called Fails with four members for four courses. How can you update this with the number of students who have failed in any of the courses? Modify the program (main and/or Report functions) to use the Fails structure and to print the number of failed students in each course.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
struct student
{
char name[30];
int ID;
int Math, English, Science, Art;
float GPA;
};
struct Fails
{
int Math, English, Science, Art;
void start()
{Math=0;
English=0 ;
Science=0;
Art=0;
}
float Report(student S)
{
S.GPA=(S.Math+S.Science+S.English+S.Art)/4;
if(S.Math<2) // Assuming E is fail"
Math=Math+1;
if(S.English<2) // Assuming E is fail"
English++;
if(S.Science<2) // Assuming E is fail"
Science++;
if(S.Art<2) // Assuming E is fail"
Art++;
if (S.GPA<2)
cout<< "student Fail"; // Assuming GPA<2 is fail
else
cout<< "Student Passed";
return S.GPA;
}
};
int convert(char x)
{
switch(x)
{
case 'A' : return 5;
case 'B' : return 4;
case 'C' : return 3;
case 'D' : return 2;
case 'E' : return 1;
}
return 0;
}
void main()
{
clrscr();
int i;
struct student s[3];
struct Fails F;
char grade;
int maxGPA=0,max ;
int g[3];
F.start();
for (i=0;i<3;i++)
{
cout<<" Enter Name";
cin>>s[i].name;
cout<<"Enter Math Grade";
cin>>grade;
s[i].Math=convert(grade);
cout<<"Enter Englush Grade";
cin>>grade;
s[i].English=convert(grade);
cout<<"Enter Science Grade";
cin>>grade;
s[i].Science=convert(grade);
cout<<"Enter Art Grade";
cin>>grade;
s[i].Art=convert(grade);
g[i]=F.Report(s[i]);
if(g[i]>maxGPA)
{
maxGPA=g[i];
max=i;
}
}
cout<<" Student with highest GPA";
cout<<" Name : "<<s[max].name;
cout<<" GPA : "<<s[max].GPA;
cout<<" Subject wise failures report";
cout<<" Maths : "<<F.Math;
cout<<" English : "<<F.English;
cout<<" Science : "<<F.Science;
cout<<" Art : "<<F.Art;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.