/*
Using the program you developed for Homework 1, define a structure which supports the following types of information:
- student name
- student ID number
- current exam grade
- prior exam grade
- overall GPA
The user will once again identify the number of students being represented and will then provide the 5 pieces of information for each student.
The user can sort based on any one of the 5 criteria, by specifying a value of 1-5.
After sorting, print the result.
*/
#include <iostream>
#include <cmath>
#include <algorithm> //contains sort
#include <string>
#include <iomanip>
usingnamespace std;
//define a structure which supports the following types of information
//- student name
//- student ID number
//- current exam grade
//- prior exam grade
//- overall GPA
struct student;
{
string student_name;
int student_ID,current_grade,prior_grade;
double overall_GPA;
}
//global variables
int grade[30],size1;
//get grades, and then sort them
//should probably separate these functions
void accept_sort_grade(student data[])
{
int i;
for(i=0;i<size1;i++)
{
//provide the 5 pieces of information for each student
//- student name
cout<<"Enter the student's name for student #"<<i<<endl;
cin>> data[i].student_name;
//- student ID number
cout<<"Enter the student's ID number#"<<i<<endl;
cin>> data[i].student_ID;
//- current exam grade
cout<<"Enter the current grade #"<<i<<":"<<endl;
cin>> data[i].current_grade;
//- prior exam grade
cout<<"Enter the prior grade #"<<i<<":"<<endl;
cin>>data[i].prior_grade;
//- overall GPA
cout<<"Enter the ovrall GPA #"<<i<<":"<<endl;
cin>>data[i].overall_GPA;
}
//The user can sort based on any one of the 5 criteria, by specifying a value of 1-5.
//get user input
sort(&grade[0],&grade[size1]); //use array sort
return;
}
int main ()
{
int sum1=0; //store grade total
double av1; //store grade average
//identify the number of students being represented
do
{
cout<<"Enter the number of grades."<<endl;
cin>>size1;
}
while((size1>30) || (size1<=0)); //get a number 1-30
accept_sort_grade();
//After sorting, print the result.
cout<<"The sorted grades are: ";
for(int i=0;i<size1;i++)
{
cout<<grade[i]<<" ";
sum1+=grade[i];
}
av1=(double)sum1/(double)size1; //double = int/int;
cout<<fixed<<setprecision(2); //sets the output to show decimal
cout<<endl<<"The grade average is:"<<av1<<endl;
system ("pause");
return 0;
}