#include <iostream> #include <string> using namespace std; struct Student { stri
ID: 663039 • Letter: #
Question
#include <iostream>
#include <string>
using namespace std;
struct Student
{
string studFirstName,studLastName;
int studExam1,studExam2,studExam3; // 0 - 100
double studAvg;
char studGrade; // A-F
};
int main() {
Student stud1;
char Grade;
for (int i = 0; i <3; i++)
{
//Input data
cout<<"Enter student's first and last name: ";
cin >>stud1.studFirstName >>stud1.studLastName;
cout<<"Enter three Exams: ";
cin >>stud1.studExam1 >>stud1.studExam2 >>stud1.studExam3;
//Process data
stud1.studAvg = (stud1.studExam1 + stud1.studExam2 + stud1.studExam3 ) /3;
if (stud1.studAvg >= 90)
Grade = 'A';
else if( stud1.studAvg >=80)
Grade = 'B';
else if (stud1.studAvg>=70)
Grade = 'C';
else if (stud1.studAvg >=60)
Grade = 'D';
else
Grade = 'F';
stud1.studGrade = Grade;
//Add the code to display the Student record for each student.
}
system ("pause");
return 0;
}
jimmy shandeh
100 100 100
Mike Jackson
100 90 93
Mary Johnson
90 75 88
2) Add the code to display the Student record for each student, see comment inside the code. 30 points
3) Run it again with data listed above. 30 points
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
struct Student
{
string studFirstName,studLastName;
int studExam1,studExam2,studExam3; // 0 - 100
double studAvg;
char studGrade; // A-F
};
int main() {
Student stud1;
char Grade;
for (int i = 0; i <3; i++)
{
//Input data
cout<<"Enter student's first and last name: ";
cin >>stud1.studFirstName >>stud1.studLastName;
cout<<"Enter three Exams: ";
cin >>stud1.studExam1 >>stud1.studExam2 >>stud1.studExam3;
//Process data
stud1.studAvg = (stud1.studExam1 + stud1.studExam2 + stud1.studExam3 ) /3;
if (stud1.studAvg >= 90)
Grade = 'A';
else if( stud1.studAvg >=80)
Grade = 'B';
else if (stud1.studAvg>=70)
Grade = 'C';
else if (stud1.studAvg >=60)
Grade = 'D';
else
Grade = 'F';
stud1.studGrade = Grade;
cout<<"Name:"<<stud1.studFirstName<<stud1.studLastName<<" ";
cout<<"Marks in three subjects: "<<stud1.studExam1<<" "<<stud1.studExam2<<" "<<stud1.studExam3<<" ";
cout<<"Average:"<<stud1.studAvg<<" ";
cout<<"Grade:"<<Grade<<" ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.