Hi, i have a problem with this code, which is it only takes the last scores entered by the user when i want to take all the scores of each student and do the avrage calculation and display them like the output ill post with the question.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Question

Hi, i have a problem with this code, which is it only takes the last scores entered by the user when i want to take all the scores of each student and do the avrage calculation and display them like the output ill post with the question.

The code:

#include <iostream>
#include <string>
using namespace std;

void readStudentInfo (string [],int,double[]);

void calcAvg (double[],int);

char getGrade (char[],int, double);

void printResults(string[],double[],double[],int);

 

void line()
{
    cout << "--------------------------------";
}

 

const int N=2; // Number of students
const int S=5; // Number of tests

int main()
{
    string StName[N];
    double StScore[S];
    
    printResults(StName,StScore,StScore,N);
    
}


void readStudentInfo(string names[],int students,double Average[],double Score[])
{
        
    for (int i=0; i<students;i++)
    {
        cout << "Please enter student name (" << i+1 << "): ";
        getline(cin, names[i]);
        cout << "\n";
    }
    
    
    for (int j=0; j<students;j++)
    {
        cout << "Enter all " << S << " scores for " << names[j] << " : " << "\n";
        
        for (int x=0; x<S; x++)
        {
        cin >> Score[x];
        Average[x]+=Score[x];
        }
        
    }    

}


void calcAvg (string names[], double Average[],int students,double Score[])
{
    double     StSum=0;
    for (int i=0; i<students;i++)
    {
        StSum=0;  
        for (int j=0; j<S*N; j++)
        {
        StSum+=Score[j];
        }
        cout <<" StSum: " << StSum << endl;
    
    Average[i] = StSum/S;        
    cout << "AVERAGE IS: " << Average[i] << endl;
    
    }

    
}

 

void printResults(string names[],double Score[],double Average[],int students)
{
    
    readStudentInfo(names,students,Average, Score);
    
    double classAvg=0,scoreSum=0;
    char grade[N],tempGrade[1],ClassGrade;
    double tempAvg=0;

    
    
    calcAvg(names,Score,students, Score);
    
    
    for (int x=0;x<students;x++)
    {
        tempAvg = Average[x];
        grade[x] = getGrade(grade,students,tempAvg);
        
        classAvg+= Average[x];
    }
        classAvg= classAvg/N;

        ClassGrade = getGrade(tempGrade,students,classAvg);        
        
        cout << "\n";
        
        
        line ();    
        cout << "\n";
        cout << "Class Average: " << classAvg    << endl;
        cout << "Class Grade  : " << ClassGrade  << endl;
        line ();

        
        cout << "\n";
                
    for (int i=0; i<students; i++)
    { 

        cout << "    Name: "    << names[i]   << endl;
        cout << " Average: "    << Average[i] << endl;
        cout << "   Grade: "    << grade[i]   << endl;
        line ();
        cout << "\n";

    }
    
}


char getGrade (char grade[],int students, double Avg)
{
        if (Avg>=90)
        return 'A';
        if (Avg>=80)
        return 'B';
        if (Avg>=70)
        return 'C';
        if (Avg>=60)
        return 'D';        
        if (Avg<60)
        return 'F';
}

 

Please enter student name (1): zack
Please enter student name (2): jack
Enter all 5 scores for zack :
100 100 90 90 90
Enter all 5 scores for jack :
90 90 90 90 90
StSum: 900
AVERAGE IS: 180
StSum: 900
AVERAGE IS: 180
Class Average: 180
Class Grade : A
Name: zack
Average: 180
Grade: A
Name: jack
Average: 180
Grade: A
Transcribed Image Text:Please enter student name (1): zack Please enter student name (2): jack Enter all 5 scores for zack : 100 100 90 90 90 Enter all 5 scores for jack : 90 90 90 90 90 StSum: 900 AVERAGE IS: 180 StSum: 900 AVERAGE IS: 180 Class Average: 180 Class Grade : A Name: zack Average: 180 Grade: A Name: jack Average: 180 Grade: A
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Print statement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education