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
|
//this program is used to enter student data and average the test scores giving an overall grade
#include <iomanip>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
//This struct will define the name for the student
struct FullName
{
string fName;
char mInitial;
string lName;
};
//This struct will define the students name using the previous struct and use an array for grades, a float for the average grade, and a char for the letter grade
struct Student
{
FullName name;
float tests[3];
float average;
char grade;
};
//this function is used to determine the average of the array of 3 floats in the student struct
float DetermineAverage(float[3]);
//this function is used to determine the letter grade the student will receive by comparing the average to the grading scale
char DetermineGrade(float);
//this function will populate the two structs with user inputed data
Student GetData(Student [], int);
//this function will print the data on the screen, showing full name, the 3 tests, the average, and the final letter grade
void PrintStudent(Student [], int);
int main()
{
//declaring roster as an array of the Student Struct
const int NUM_STUDENTS = 2;
Student roster[NUM_STUDENTS];
GetData(roster, NUM_STUDENTS);
PrintStudent (roster, NUM_STUDENTS);
return 0;
}
//this function is used to determine the average of the array of 3 floats in the student struct
float DetermineAverage(float t[3])
{
cout << "DetermineAverage Function has been called" << endl;
//determine the average of the tests
return (t[0] + t[1] + t[2]) / 3;
}
//this function is used to determine the letter grade the student will receive by comparing the average to the grading scale
char DetermineGrade(float a)
{
char letterGrade;
cout << "DetermineGrade Function has been called!" << endl;
if (a >= 90)
letterGrade = 'A';
if (a < 90 && a >= 80)
letterGrade = 'B';
if (a < 80 && a >= 70)
letterGrade = 'C';
if (a < 70 && a >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
return letterGrade;
}
//this function will populate the two structs with user inputed data
Student GetData(Student roster[], int s)
{
int r;
char grade;
char letter;
string name;
float average;
for (r = 0; r < s; r++)
{
//enter the students name
cout << "What is the students first name? ";
cin >> name;
roster[r].name.fName = name;
cin.ignore();
cout << "What is the students middle initial? ";
cin >> letter;
roster[r].name.mInitial = letter;
cin.ignore();
cout << "What is the students last name? ";
cin >> name;
roster[r].name.lName = name;
cin.ignore();
//enter the students tests
cout << "Enter the students test scores: ";
cin >> roster[r].tests[0];
cin >> roster[r].tests[1];
cin >> roster[r].tests[2];
cin.ignore();
//call the DetermineAverage function to average the three tests
average = DetermineAverage(roster[r].tests);
roster[r].average = average;
//call to the DetermineGrade function to determine letter grade
grade = DetermineGrade(average);
roster[r].grade = grade;
}
return;
}
//this function will print the data on the screen, showing full name, the 3 tests, the average, and the final letter grade
void PrintStudent(Student roster[], int s)
{
int r;
cout << "PrintStudent function has been called: ";
for (r = 0; r < s; r++)
{
cout << "Student Name: " << roster[r].name.fName << roster[r].name.mInitial << "." << roster[r].name.lName << endl;
cout << "Test 1: " << roster[r].tests[1] << endl;
cout << "Test 2: " << roster[r].tests[2] << endl;
cout << "Test 3: " << roster[r].tests[3] << endl;
cout << "Average: " << roster[r].average << endl;
cout << "Final Grade: " << roster[r].grade << endl;
}
}
|