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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int size = 20;//change here to change array size
struct Student//declares struct type Student
//default public members
{
string Firstname, Middlename, Lastname;
float GPA;//each student has 1 GPA
char Lettergrade;
//int Examgrade1, Examgrade2, Examgrade3;
int Examgrade[3];
//int Labgrade1, Labgrade2, Labgrade3, Labgrade4;
int Labgrade[4];
};//<----YES I PUT SEMICOLON
//to "access" any student's ID number: Student.IDnumber
//to "access" a student's 1st exam grade: Student.Examgrade[0]
struct Student Compstud[size];
//initializes an array within type Student to hold 'size' Compsci students
//function declarations
void Initialize(Student s[]);
//function initializes all the elements to 0
void Read_Data(ifstream& In_Data, Student s[]);
//function read values from a file, these values will be used for calculations
//postcondition: replaces 0 initialization with those values
float Calc_GPA(int Examgrade[], int Labgrade[], Student s[]);
//function calculates the GPA of each of the students
//Postcondition: Able to use the return values of this function to assign letter grade
char LetterGrade(float GPA, Student s[]);
//Precondition: Student has a GPA calculated
//function outputs a letter grade according to the student's calculated GPA
//Grading scale: 100-90: A , 90-80: B, 80-70: C, 70-0: D: Failure
float calc_ClassAverage(int Examgrade[], int Labgrade[], Student s[]);
//Precondition: Each student has a GPA calculated
//function uses all student's GPA to calculates average grade of the class
//use pointer to point to each student's GPA and sum them up
void Display_File(ofstream Out_Data, Student s[]);
//Postconditions:
//Outputs each of the 20 students' full name, 3 exam grades,
//each of the 4 lab grades, and final grade to an output file
//Outputs the average GPA of whole class
void Display_Screen(Student s[]);
//Postconditions:
//Outputs each of the 20 students' full name, 3 exam grades,
//each of the 4 lab grades, and final grade to the screen
//Outputs the average GPA of whole class
ifstream In_Data;
ofstream Out_Data;
float ClassAverage;
int main()
{
CompStud *ptr;//declare pointer to student's GPA (s[i].GPA)
//function calls begin
Initialize(CompStud);
Read_Data(In_Data, CompStud);
Calc_GPA(Examgrade, Labgrade, CompStud);
LetterGrade(GPA, CompStud);
calc_ClassAverage(Examgrade, Labgrade, CompStud);
Display_File(Out_Data, CompStud);
Display_Screen(CompStud);
}
|