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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cmath>
using namespace std;
//place prototypes here
void input (int Count, float Grade_Array[], float Hour_Array[],
float Pts_Array[], int SIZE);
float gpa (float& Total_Gradepts, float Pts_Array[], float& Total_Crdt,
float Hour_Array[], float Gpa);
bool validate(int Grade, int Hours);
void display (string Name, int Count, int SIZE, float Grade_Array[],
float Hour_Array[], float Pts_Array[], float Gpa);
void close();
int main()
{
//local constants
const int QUIT = -1; //Init Quit Value
const string QUIT_NAME = "-1"; //Init String Quit
const int SIZE = 3; //Set Array Size to 6
//local variables
int Count = 0; //Init Count to 0
string Name; //Students Name
float Grade; //Students Grade
int Hours; //Credit Hours
float Pts; //Convert Grade to Pts
float Grade_Array [SIZE]; //Initialize Grade Array
float Hour_Array [SIZE]; //Initialize Hour Array
float Pts_Array [SIZE]; //Initialize Pts Array
float Gpa; //Initialize GPA
float Total_Gradepts; //Total of Grades in Array
float Total_Crdt; //Total of Hrs in Array
/**************************start main program*********************/
// Spaces from top of screen
cout << "\n\n\n\n\n\n";
//Input name or quit value
cout << setw(57) << "Input Students Name Or -1 To Quit" << endl;
cout << "\n\n";
//Input Student Name
cout << setw(48) << "Students Name : ";
cin >> Name;
//WHILE Name does not equal QUIT
while (Name != QUIT_NAME)
{
//Call Function To Input
input (Count, Grade_Array, Hour_Array, Pts_Array, SIZE);
//Clear Screen
system ("cls");
//Call Function to Calculate GPA
Gpa = gpa (Total_Gradepts, Pts_Array, Total_Crdt, Hour_Array, Gpa);
//Call Function to Display the grade report
display (Name, Count, SIZE, Grade_Array, Hour_Array, Pts_Array, Gpa);
//Pause Screen
system ("pause");
//Clear Screen
system ("cls");
// Spaces from top of screen
cout << "\n\n\n\n\n\n";
//Input name or quit value
cout << setw(57) << "Input Students Name Or -1 To Quit" << endl;
cout << "\n\n";
//Input Student Name
cout << setw(48) << "Students Name : ";
cin >> Name;
//END WHILE
}
//Call function to display closing message (optional)
close();
//Pause Screen
system ("pause");
} //END Calc Students GPA
************************Start Input Function*************************/
void input (int Count, float Grade_Array[], float Hour_Array[],
float Pts_Array[], int SIZE)
{
//local constant
//local variables
float Grade; //Students Grade
float Hours; //Credit Hours
float Pts; //Convert Grade to Pts
/*************************************************************/
//FOR (Each Grade Entered)
for (Count = 0; Count < SIZE; Count ++)
{
//Input Grade
cout << "\n" << setw(48) << "Students Grade : ";
cin >> Grade;
//Input Credit Hours
cout << setw(48) << "Credit Hours : ";
cin >> Hours;
//Call Function To Validate Input Data
validate (Grade, Hours);
//Calc Grade Pts
Pts = Grade * Hours;
//ADD Grade, Credit Hours, Grade Pts to Array
Grade_Array [Count] = Grade;
Hour_Array [Count] = Hours;
Pts_Array [Count] = Pts;
//END FOR
}
} //END of Input Function
***********************Start Validate Function***********************/
bool validate (int Grade, int Hours)
{
//local constant
const float GRADE_LOW = 0.0; //Set Grade Low to 0.0
const float GRADE_HIGH = 4.0; //Set Grade High to 4.0
const int HOUR_MIN = 1; //Set Hour Min to 1
const int HOUR_MAX = 4; //Set Hour Max to 4
//local variables
/*************************************************************/
//IF (Grade & Credit Hours are Valid)
if ((Grade >= GRADE_LOW && Grade <= GRADE_HIGH) &&
(Hours >= HOUR_MIN && Hours <= HOUR_MAX))
{
//Return True
cout << endl;
return true;
}
else
{
//Display Error
cout << "\n" << setw(42) << "ERROR" << endl;
cout << setw(42) << "-----" << endl;
return false;
}
//Return False
return false;
} //END of Validate Function
*************************Start GPA Function**************************/
float gpa (float& Total_Gradepts, float Pts_Array[], float& Total_Crdt,
float Hour_Array[], float Gpa)
{
//local constants
//local variables
/*************************************************************/
//Calculate GPA
Total_Gradepts = Pts_Array[0] + Pts_Array[1] + Pts_Array[2];
Total_Crdt = Hour_Array[0] + Hour_Array[1] + Hour_Array[2];
Gpa = Total_Gradepts / Total_Crdt;
return Gpa;
} //END of GPA Function
************************Start Display Function***********************/
void display (string Name, int Count, int SIZE, float Grade_Array[],
float Hour_Array[], float Pts_Array[], float Gpa)
{
//local constants
//local variables
/*************************************************************/
//Clear Screen
system ("cls");
// Spaces from output
cout << "\n\n\n";
//Output Students Name
cout << setw(47) << "Final Grades For " << Name << endl << "\n\n";
//Display Grade, Credit Hour, Grade Pts, Header
cout << setw(60) << "Grades Credit Hours Grade Pts" << endl;
//FOR (Each Grade Entered)
for (Count = 0; Count < SIZE; Count ++)
{
//Set to decimal point output
cout << setiosflags (ios::fixed | ios::showpoint) << setprecision (2);
//Display Grade, Credit Hours, Grade Points
cout << setw(26) << Grade_Array[Count] << setw(15) << Hour_Array[Count];
cout << setw(17) << Pts_Array[Count] << endl;
//END FOR
}
//Output GPA
cout << "\n\n" << setw(40) << "GPA : " << Gpa << endl;
// Spaces from output
cout << "\n\n\n";
//Pause Screen
system ("pause");
//Clear Screen
system ("cls");
} //END of Display Function
|