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
|
// Headers
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Global variables
const int NUM_ITEMS = 3;
// Function declaration
string getStudentName();
void getAssignmentName(string assignName[], int size); // Assignment Names
void getAssignmentGrade(int gradeNum[], string assignName[], int size); // Assignment Grades
float getGradeAvg(float gradeAverage, int gradeNum[]); // Grade Average
void displayAvg(string studName, string assignName[], int gradeNum[],
float gradeAverage, int size); // Display Average
int main()
{
// Declare variables
string studentName,
assign[NUM_ITEMS]; // Assignment Names
int grades[NUM_ITEMS]; // Assignment Grades
float average; // Grade Average
// Get Student Name
studentName = getStudentName();
// Get Assignment Names
cout << endl;
getAssignmentName(assign, NUM_ITEMS);
// Get Assignment Grades
cout << endl;
getAssignmentGrade(grades, assign, NUM_ITEMS);
// Get Grade Average
cout << endl;
average = getGradeAvg(average, grades);
// Display Average
cout << endl;
displayAvg(studentName, assign, grades, average, NUM_ITEMS);
return 0;
}
string getStudentName()
{
string studentName;
cout << "Enter student first and last name: ";
getline(cin, studentName);
return studentName;
}
void getAssignmentName(string assignName[], int size)
{
cout << "Enter the name of assignment 1: ";
getline(cin, assignName[0]);
cout << "Enter the name of assignment 2: ";
getline(cin, assignName[1]);
cout << "Enter the name of assignment 3: ";
getline(cin, assignName[2]);
}
void getAssignmentGrade(int gradeNum[], string assignName[], int size)
{
cout << "Enter the grade for " << assignName[0] << ": ";
cin >> gradeNum[0];
cout << "Enter the grade for " << assignName[1] << ": ";
cin >> gradeNum[1];
cout << "Enter the grade for " << assignName[2] << ": ";
cin >> gradeNum[2];
}
float getGradeAvg(float gradeAverage, int gradeNum[])
{
gradeAverage = (gradeNum[0] + gradeNum[1] + gradeNum[2]) / 3.0f;
return gradeAverage;
}
void displayAvg(string studName, string assignName[], int gradeNum[], float gradeAverage, int size)
{
cout << setprecision(1) << fixed << showpoint;
cout << "The average for " << studName << " is " << gradeAverage << endl;
cout << endl;
cout << "Here are your grades: " << endl << endl;
cout << setw(30) << assignName[0] << ": " << setw(3) << gradeNum[0] << endl;
cout << setw(30) << assignName[1] << ": " << setw(3) << gradeNum[1] << endl;
cout << setw(30) << assignName[2] << ": " << setw(3) << gradeNum[2] << endl;
cout << endl;
cout << "Thank you for playing." << endl;
cout << endl;
}
|