In C Problem Statement A teacher has five students who have

In C++

Problem Statement: 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/her four test scores:

90-100 -> \"A\", 80-89 -> \"B\", 70-79 -> \"C\", 60-69 -> \"D\", 0-59 -> \"F\"

Write a program that uses a vector of string objects to hold the 5 student names, a vector of characters to hold the 5 students’ letter grades, and 4 vectors of doubles to hold each student’s set of test scores.

The program should allow the user to enter each student’s name and his/her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average.

Input Validation: Do not accept scores less than 0 or greater than 100.

Solution

#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.\ \";

cin >> val1;

while (val1 < 0 || val1 > 100)

{

cout << \"You have not entered a number between 0 and 100. Please re-enter test 1.\ \";

cin >> val1;

}//end of while loop

cout << \"Please enter test 2, with scores between 0 and 100.\ \";

cin >> val1;

while (val2 < 0 || val2 > 100)

{

cout << \"You have not entered a number between 0 and 100. Please re-enter test 2.\ \";

cin >> val2;

}//end of while loop

cout << \"Please enter test 3, with scores between 0 and 100.\ \";

cin >> val1;

while (val3 < 0 || val3 > 100)

{

cout << \"You have not entered a number between 0 and 100. Please re-enter test 3.\ \";

cin >> val3;

}//end of while loop

cout << \"Please enter test 4, with scores between 0 and 100.\ \";

cin >> val4;

while (val4 < 0 || val4> 100)

{

cout << \"You have not entered a number between 0 and 100. Please re-enter test 4.\ \";

cin >> val4;

}//end of while loop

cout << \"Please enter test 5, with scores between 0 and 100.\ \";

cin >> val5;

while (val5 < 0 || val5 > 100)

{

cout << \"You have not entered a number between 0 and 100. Please re-enter test 5.\ \";

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

//please rate my answer

In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud
In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud
In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud
In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud
In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud
In C++ Problem Statement: A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a stud

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site