Question

Student average array program

Having a bit of trouble in my c++ class, was wondering if anyone can help.
Write a program to calculate students' average test scores and their grades. You may assume the following input data:


Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 68 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63

Use three arrays: a one-dimensional array to store the students names, a (parallel) two-dimensional array to store the test scores, and a parallel one-dimensional arayto store grades. Your program must contain at least the following functions: a function to read and store data into two arrays, a function to calculate the averagetest score and grade, and a function to output the results. Have your program also output the class average.

Thanks for any help.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

    

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>


using namespace std;


void getData(ifstream& inf, string n[], double tstData[][6], int count);

void calculateAverage(double tstData[][6], int count);

void calculateGrade(double tstData[][6], char gr[], int count);

void print(string n[], double tstData[][6], char gr[], int count);

  

int main()

{

string names[10];

    double testData[10][6];

    char grade[10];


    ifstream inFile;


    inFile.open("ch8_Ex13Data.txt");


    if (!inFile)

    {

        cout << "Cannot open the input file: ch8_Ex13Data.txt." << endl;

        cout << "Program terminates!" << endl;

        return 1;

    }


    cout << fixed << showpoint << setprecision(2);


    getData(inFile, names, testData, 10);

    calculateAverage(testData, 10);

    calculateGrade(testData, grade, 10);

    print(names, testData, grade, 10);


    inFile.close();


return 0;

}


void getData(ifstream& inf, string n[], double tstData[][6], int count)

{

    for (int i = 0; i < count; i++)

    {

        inf >> n[i];

        

        for (int j = 0; j < 5; j++)

            inf >> tstData[i][j];


        tstData[i][5] = 0.0;

    }

}


void calculateAverage(double tstData[][6], int count)

    double sum;


    for (int i = 0; i < count; i++)

    {

        sum = 0.0;

        for (int j = 0; j < 5; j++)

            sum = sum + tstData[i][j];

        tstData[i][5] = sum / 5;

    }

}


void calculateGrade(double tstData[][6], char gr[], int count)

{

    for (int i = 0; i < count; i++)

        if (tstData[i][5] >= 90)

            gr[i] = 'A';

        else if (tstData[i][5] >= 80)

            gr[i] = 'B';

        else if (tstData[i][5] >= 70)

            gr[i] = 'C';

        else if (tstData[i][5] >= 60)

            gr[i] = 'D';

        else 

            gr[i] = 'F';

}


void print(string n[], double tstData[][6], char gr[], int count)

{

    double sum = 0.0;


    cout << left << setw(10) << "Name"

         << right << setw(8) << "Test 1"

         << setw(8) << "Test 2"

         << setw(8) << "Test 3"

         << setw(8) << "Test 4"

         << setw(8) << "Test 5"

         << setw(10) << "Average"

         << setw(8) << "Grade" << endl;


    for (int i = 0; i < count; i++)

    {

        cout << left << setw(10) << n[i];

        cout << right;


        for (int j = 0; j < 5; j++)

            cout << setw(8) << tstData[i][j];


        cout << setw(10) << tstData[i][5]

             << setw(6) << gr[i] << endl;

        sum = sum + tstData[i][5];

    }


    cout << endl << endl;

    cout << "Class average: " << sum / count << endl;

}


answered by: Rachel
Add a comment
Know the answer?
Add Answer to:
Student average array program
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • this is a java course class. Please, I need full an accurate answer. Labeled steps of...

    this is a java course class. Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with: (Create another file to test the class and output to the screen, not an output file) please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer. Thanks in advance. Write the definition of the class Tests such...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • Could someone show how to do this in C#? I keep getting errors for mine and...

    Could someone show how to do this in C#? I keep getting errors for mine and the other answers on here that are similar doesn't work. And please make sure it accepts user input. Write the class "Tests". Ensure that it stores a student's first name, last name, all five test scores, the average of those 5 tests' scores and their final letter grade. (Use an array to store test scores.) Add constructors and methods to manipulate the data stored...

  • SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes...

    SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array....

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT