Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <sstream>
- using namespace std;
- //Start Function Declarations
- //Arrays for GPAs and student names and number of students
- //promps user for name and gpa for that name
- //if invald GPA, will error message and reprompt user
- void obtainNamesAndGPAs (string[], double[], int nstud);
- // Param string - student names
- // param double - student GPA
- // param int - student number
- void sortGPA(string[], double[], int nstud);
- //Sort GPAs with corresponding names in ASCENDING ORDER.
- void displayMinMaxGPA(string[], double[], int nstud);
- //display of lowest and highest GPAs with corresponding names
- int calcAvgGPA(string[], double[], int nstud);
- //calculates the average GPA from the GPAs entered in the array
- //End Function Declarations
- int main () {
- //variable
- int nstud;
- //promps user number of students
- cout << "Enter the number of students: ";
- cin >> nstud;
- //Arrays for GPA and Names
- string* nameList;
- nameList = new string [nstud];
- double* gradeList;
- gradeList = new double [nstud];
- //calling functions
- obtainNamesAndGPAs (nameList, gradeList, nstud);
- sortGPA(nameList, gradeList, nstud);
- displayMinMaxGPA (nameList, gradeList, nstud);
- calcAvgGPA (nameList, gradeList, nstud);
- return 0;
- }
- //Start Function Defenitions
- //promps user for name and gpa for that name
- //Arrays for GPAs and student names and number of students
- //if invald GPA, will error message and reprompt user
- void obtainNamesAndGPAs (string nameList[], double gradeList[], int nstud) {
- //Prompt user for Student name
- for (int i = 0; i < nstud; i++) {
- cout << "Enter student name: ";
- cin >> nameList[i];
- //Prompt user for Students GPA
- cout << "Enter their GPA: ";
- cin >> gradeList[i];
- if (gradeList[i] < 0 || gradeList[i] > 4) {
- cout << "Invalid GPA - re-enter: ";
- cin >> gradeList[i];
- }
- }
- }
- //Sort GPAs with corresponding names in ASCENDING ORDER.
- void sortGPA(string nameList[], double gradeList[], int nstud) {
- //bubblesort
- // for (int i = 0; i<nstud; i++) {
- // for (int j = 0, exchange = 0;j<nstud;j++) {
- // if (*gradeList[j] > *gradeList[j + 1]) {
- // temp1 = *gradeList[j];
- // *gradeList[j] = *gradeList[j + 1];
- // *gradeList[j + 1] = temp1;
- // swap(*nameList[j], *nameList[j + 1]);
- // exchange++;
- // }
- for (int a = 0; a<nstud; a++) {
- cout << nameList[a] << " " << gradeList[a];
- }
- }
- //display of lowest and highest GPAs with corresponding names
- void displayMinMaxGPA (string nameList[], double gradeList[], int nstud) {
- }
- //calculates the average GPA from the GPAs entered in the array
- int calcAvgGPA(string nameList[], double gradeList[], int nstud) {
- double sum=0.0, avg;
- for(int i=0;i<nstud;i++) {
- sum=sum + gradeList[i];
- }
- avg = sum / nstud;
- return avg;
- }
- //End Function Defentitions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement