1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <iostream>
using namespace std;
struct Class
{
char title[100];
int units;
char grade;
};
struct Student
{
char name[100];
double GPA;
Class classes[100];
};
void initialize(Student[], int);
void read(Student[], int);
void GPAs(Student[], int);
void display(Student[], int);
//void sort_name(Student[], int); For the sort function see #2
int main()
{
Student profile[50];
int size = 50;
initialize(profile, size);
read(profile, size);
GPAs(profile, size);
display(profile, size);
//sort_name(profile, size); for the sort function...see #2
system("pause");
return 0;
}
void initialize(Student profile[], int size)//I was asked to set GPAs to 0.0
{
for(int i = 0; i < size; i++)
{
profile[i].GPA = 0.0;
}
}
void read(Student profile[], int size)//Where user inputs info
{
for(int i = 0; i < size; i++)
{
cout<<"Enter student's name: ";
cin.getline(profile[i].name, 100, '\n');
for(int j = 0; j < 100; j++)
{
if(profile[i].name[j] == ' ')
{
if(isupper(profile[i].name[j+1]) == false)
toupper(profile[i].name[j+1]);
}
}
if(profile[i].name[0] == '\0')//I'm having issues here
{ //See #1 at the bottom
break; //for more info
}
for(int c = 0; c < 100; c++)
{
cout<<"\nEnter class name: ";
cin.getline(profile[i].classes[c].title, 100, '\n');
if(profile[i].classes[c].title == '\0')//Again,
{ //same thing
break; //see #1
}
cout<<"Enter number of units: ";
cin>>profile[i].classes[c].units;
cout<<"Enter letter grade: ";
cin>>profile[i].classes[c].grade;
if(islower(profile[i].classes[c].grade))
toupper(profile[i].classes[c].grade);
cin.ignore();
}
}
}
void GPAs(Student profile[], int size)// Calculates GPAs of the students
{
int totalunits, worth, sum;
for(int i = 0; i < size; i++)
{
totalunits = 0;
sum = 0;
for(int c = 0; c < 100; c++)
{
totalunits += profile[i].classes[c].units;
if(profile[i].classes[c].grade == 'A')
worth = 4;
else if(profile[i].classes[c].grade == 'B')
worth = 3;
else if(profile[i].classes[c].grade == 'C')
worth = 2;
else if(profile[i].classes[c].grade == 'D')
worth = 1;
else
worth = 0;
sum += (worth * profile[i].classes[c].units);
}
profile[i].GPA = sum/totalunits;
}
}
void display(Student profile[], int size) //supposed to display the array
{ //not sure if it works because
for(int i = 0; i < 50; i++) //I can't get past inputting
{ //because I cant stop the program
cout<< "Student name: " //from asking info so, see #1
<< profile[i].name;
for(int j = 1; j <= 100; j++)
{
cout<<"\n\tName of Class #"<<j<<": "
<<profile[i].classes[j].title
<<"\n\tAmount of units: "
<<profile[i].classes[j].units
<<"\n\tLetter grade: "
<<profile[i].classes[j].grade;
}
cout<<profile[i].GPA<<"\n\n";
}
}
|