//chapter 7 lab p475 ex8 gradebook
//Intructions:
//A teacher has five students who have taken four tests.
//The teacher uses the following grading scale to assign a letter
//grade to a student, based on the average of his or her test scores.
//___________________________________
// Test Score Letter Grade
//-----------------------------------
// 90-100 A
// 80-89 B
// 70-79 C
// 60-69 D
// 0-59 F
//___________________________________
//Write a program that uses a two-dimensional array of charachters
//that hold the five student names, a single-dimensional array of
//five characters to hold the five students' letter grades, and five
//single-dimensional arrays of four doubles to hold each student's
//set of test scores.
//The program should allow the user to enter each student's name and
//his or her scores. It should then calculate and display each
//student's average test score and a letter grade based on that average.
//Imput Validation: Do not accept test scores less than zero or greater
//than 100.
#include <iostream>
using namespace std;
//function prototype
void calcdata(double []);
void display data();
//start of main
int main()
{
const int NUM_NAMES = 5; //how many occurances
const int NAMESIZE = 11; //how long names can be, 10 letters
const int NUM_TESTS = 4; //how many tests
char name[NUM_NAMES][NAMESIZE]; //two-dimensional name array
char grade[NUM_NAMES]; //grade for each student array
double average[NUM_NAMES]; //average for each student array
double student1[NUM_TESTS] //student1 array
double student2[NUM_TESTS] //student2 array
double student3[NUM_TESTS] //student3 array
double student4[NUM_TESTS] //student4 array
double student5[NUM_TESTS] //student5 array
cout << βEnter the studentβs nameβ?
for (int count = 0; count < NUM_NAMES; count++)
{ // beginning of nested for loop
cout << "Student" << (count +1) <<": ";
cin >> name[count];
for (i = 0; i < NUM_NAMES; i++)
cout >> name [i]; //stub statement
} //end of for loop
//Beginning of validation sequence taken from chapter 6 lab assignment
//********Need to change to fit with this lab assignment********
cout << "Please enter test 1, with scores between 0 and 100.\n";
cin >> val1;
while (val1 < 0 || val1 > 100)
{
cout << "You have not entered a number between 0 and 100. Please re-enter test 1.\n";
cin >> val1;
}//end of while loop
cout << "Please enter test 2, with scores between 0 and 100.\n";
cin >> val1;
while (val2 < 0 || val2 > 100)
{
cout << "You have not entered a number between 0 and 100. Please re-enter test 2.\n";
cin >> val2;
}//end of while loop
cout << "Please enter test 3, with scores between 0 and 100.\n";
cin >> val1;
while (val3 < 0 || val3 > 100)
{
cout << "You have not entered a number between 0 and 100. Please re-enter test 3.\n";
cin >> val3;
}//end of while loop
cout << "Please enter test 4, with scores between 0 and 100.\n";
cin >> val4;
while (val4 < 0 || val4> 100)
{
cout << "You have not entered a number between 0 and 100. Please re-enter test 4.\n";
cin >> val4;
}//end of while loop
cout << "Please enter test 5, with scores between 0 and 100.\n";
cin >> val5;
while (val5 < 0 || val5 > 100)
{
cout << "You have not entered a number between 0 and 100. Please re-enter test 5.\n";
cin >> val5;
}//end of while loop
//display output for validation
cout << "Test 1 is: " << val1 << endl;
cout << "Test 2 is: " << val2 << endl;
cout << "Test 3 is: " << val3 << endl;
cout << "Test 4 is: " << val4 << endl;
cout << "Test 5 is: " << val5 << endl;
//call to function calcdata
calcdata();
return 0;
} //end of main
//************************************************
//function definition of calcdata
// this function is going to get the test scores
// array and calculate the averages
// and calculate grade
//i need to pass the student names to correspond
// with the test scores, avgs, and grade
//************************************************
void calcdata()
const int NUM_STUDENTS = 5;
const int NUM_SCORES = 4;
double total, average;
double scores[NUM_STUDENTS][NUM_SCORES];
//get each students average score
for (int row = 0; row < NUM_STUDENTS; row++)
{
//set the accumulator.
total = 0;
//sum a row
for (int col = 0; col < NUM_SCORES; col++
total += scores[row][column];
//get the average
average = total / NUM_SCORES;
//
//**************************************************
// loop used to determine grade for each students average
//for (int index = 0; index < NUM_NAMES; index++)
//nested loop
//for (int count =0; index < NUM_NAMES; count++)
if (average[0] < 60)
grade[0] = βFβ
else if (average [0] < 70)
grade[0] = βDβ
else if (average [0] < 80)
grade[0] = βCβ
else if (average [0] < 90)
grade[0] = βBβ
else (average [0] <= 100)
grade[0] = βAβ
if (average[1] < 60)
grade[1] = βFβ
else if (average [1] < 70)
grade[1] = βDβ
else if (average [1] < 80)
grade[1] = βCβ
else if (average [1] < 90)
grade[1] = βBβ
else (average [1] <= 100)
grade[1] = βAβ
if (average[2] < 60)
grade[2] = βFβ
else if (average [2] < 70)
grade[2] = βDβ
else if (average [2] < 80)
grade[2] = βCβ
else if (average [2] < 90)
grade[2] = βBβ
else (average [2] <= 100)
grade[2] = βAβ
if (average[0] < 60)
grade[3] = βFβ
else if (average [3] < 70)
grade[3] = βDβ
else if (average [3] < 80)
grade[3] = βCβ
else if (average [3] < 90)
grade[3] = βBβ
else (average [3] <= 100)
grade[3] = βAβ
if (average[0] < 60)
grade[4] = βFβ
else if (average [4] < 70)
grade[4] = βDβ
else if (average [4] < 80)
grade[4] = βCβ
else if (average [4] < 90)
grade[4] = βBβ
else (average [4] <= 100)
grade[4] = βAβ
//call to function displaydata
displaydata();
return 0;
}//end of function calc data
//***************************************************
//definition of function displaydata
//this function is designed to display the student's
// average and letter grade
//***************************************************
void displaydata()
for (int i = 0; i < NUM_SIZE; i++)
cout << "Student: " <<name [i]
<<"average: " << average [i]
<<"grade: " << grade [i]
<< endl;
return 0;
} // end of main