Write a program to complete the following tasks. Record all results to a data fi
ID: 3759661 • Letter: W
Question
Write a program to complete the following tasks. Record all results to a data file called "GradeSheet.dat".(1) Read the grade sheet from attached data file, "Assignment4.dat". Print the original grade sheet.
(3) Write a module to sort array GRADE[] and print the sorted grade sheet.
(4) Write a module to sort array NAME[] and print the sorted grade sheet.
(5) Write a module to sort array ID[] and print the sorted grade sheet.
(6) Write a module to print the student's id, name, and grade for student with highest grade and with lowest grade, respectively.
(7) Write a module to determine mean of the grades.
(8) Write a module to list students with grade is less than mean.
File for GradeSheet.dat
ID NAME GRADE
5532 Mary 100
7856 Tom 99.56
3345 Cathy 33.78
1229 Jim 89.42
2785 David 67.52
9954 Rob 99.25
2388 Sue 87.29
6523 Michael 60.55
1287 Zach 76.12
2783 Amy 90.55
Explanation / Answer
using namespace std;
struct Student
{
string name;
int id;
float GRADE;
Double mean,col_sum;
};
void printStudents(Student* student, int nStudents)
{
int i;
for (i = 0; i < nStudents; i++)
{
cout << "Name = " << left << setw(30) << student[i].name;
cout.fill('0');
cout << " ID = " << right << setw(7)
<< student[i].id << ", GRADE = "
<< student[i].GRADE << endl;
cout.fill(' ');
}
}
int main()
{
string name;
int id;
float GRADE;
Double mean,col_sum;
// create an empty list
const int MAX_STUDENTS = 100;
int nStudents = 0;
Student student[MAX_STUDENTS];
// read and save the records
while (true)
{
// create a record and read it from file
Student aStudent;
cout << "Student's name: ";
getline(cin, aStudent.name);
int aID;
cout << "Student's ID: ";
cin >> aStudent.id;
cin.ignore(1000, 10);
float GRADE;
cout << "Student's GPA: ";
cin >> aStudent.GRADE;
cin.ignore(1000, 10);
cout << " " << endl;
// add record to list, if it's not full
if (nStudents < MAX_STUDENTS)
student[nStudents++] = aStudent;
}
// sort the students by id
for (int i = 0; i < nStudents; i++)
{
for (int j = i + 1; j < nStudents; j++)
{
if (student[i].id > student[j].id)
{
Student temp = student[i];
student[i] = student[j];
student[j] = temp;
}
}
}
// sort the students by NAME
for (int i = 0; i < nStudents; i++)
{
for (int j = i + 1; j < nStudents; j++)
{
if (student[i].name > student[j].name)
{
Student temp = student[i];
student[i] = student[j];
student[j] = temp;
}
}
}
// sort the students by GRADE
for (int i = 0; i < nStudents; i++)
{
for (int j = i + 1; j < nStudents; j++)
{
if (student[i].GRADE > student[j].GRADE)
{
Student temp = student[i];
student[i] = student[j];
student[j] = temp;
}
}
}
col_sum=0.0;
for (int j=0;jfor (int g=0;g"AVERAGE GRADE: "<"."<:
cout<<"STUDENTS WITH ABOVE-AVEARAGE GRADES: "<for (int j=0;jfor (int k=0;kif (mean"ID "<" Name "<": "<//Students with above-average grades.
cout<//Number of days with higher output:
cout<<"***There are "<" total students with higher than average grades."<"pause");
return 0;
}
printStudents(student, nStudents);
cin.ignore();
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.