Ask Question
17 December, 05:05

Using 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 array to store grades. Your program must contain at least the following functions: a function called GetData to read and store data into two arrays, a function called Average that is used to calculate the average test score and grade, and a function called PrintResults to output the results. The student names should be to the left with a width of 10 columns. The test scores should be to the right with a width of 5 columns. Have your program also output the class average on a line after the output.

3 serperate arrays should be used

and it should read from a file

ive used some void functions two dimensional arrays to read numbers from a text file but im getting a lot of errors i know setw needs to be used also

+5
Answers (1)
  1. 17 December, 08:17
    0
    This C+ + program considers scores as follows

    A>=90

    B>=80

    C>=70

    D>=60

    F<60

    You must have a text file for input data

    Here is the program as per the question

    #include

    #include

    #include

    #include

    using namespace std;

    //Definition

    class student

    {

    private:

    string names[80];

    int testscores[80][50];

    char grades[80];

    int count;

    public:

    void GetData ();

    void Average ();

    void PrintResult ();

    };

    void student::GetData ()

    {

    ifstream in;

    in. open ("student1. txt", ios::in);

    if (in. fail ()) / /test if the file exist

    {

    cout<<"Unable to open the file";

    exit (0);

    }

    count=0;

    while (! in. eof ())

    {

    in>>names[count]; / /read name

    for (int i=0; i<5; i++) / / assume 5there are 5 test scores

    {

    in>>testscores[count][i]; / /read scores.

    }

    count++;

    }

    count--;

    }

    void student::Average ()

    {

    float sum, avg;

    for (int i=0; i
    {

    sum=0.00;

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

    {

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

    }

    avg=sum/5;

    if (avg>=90.00)

    grades[i]='A';

    else if (avg>=80)

    grades[i]='B';

    else if (avg>=70)

    grades[i]='C';

    else if (avg>=60)

    grades[i]='D';

    else

    grades[i]='F';

    }

    }

    void student::PrintResult ()

    {

    for (int i=0; i
    {

    cout. setf (ios::left, ios::adjustfield);

    cout. width (10);

    cout<
    cout. setf (ios::right, ios::adjustfield);

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

    {

    cout. width (5);

    cout<
    }

    cout. width (5);

    cout<
    }

    }

    int main ()

    {

    student obj;

    obj. GetData ();

    obj. Average ();

    obj. PrintResult ();

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Using three arrays: a one-dimensional array to store the students' names, a (parallel) two-dimensional array to store the test scores, and ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers