I am having a huge problem with writing this program. Every time I ask the teacher for help she is too busy helping someone else. so she just tell me one thing and runs off to the next person without checking if it worked and what other help I might need. It has become very frustrating. I have been able to ask for a classmates help, but that is only when we have free time during class, if he's not too busy writing his own code. I am turning to you for help. I have written and adjusted this program so many times that I am so confused. Please take a look at my code and steer me in the right direction. I greatly appreciate it. Thank you. I also hope that I use these code tags the right way. Sorry if it doesn't work. Oh, and P.S. the teacher said we had to call a function and pass something by reference(what, I'm not sure, but I specifically remember her pointing it out) I'm thinking it's to do the calculations. I've tried to design this program using only function, but I'm not that great with those, so it's been difficult.
//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