I am having trouble having this code run correctly. I need some assistance as I am now lost. main.cpp

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
icon
Related questions
Question

I am having trouble having this code run correctly. I need some assistance as I am now lost.

main.cpp

#include "ScoreStatistics.cpp"
#include <iostream>
int main() {
int ch=1;
string names[100];
float scores[100];
int numberStudents=0;
while(ch!=4){
cout<<"1. Enter the test scores via a user prompt\n";
cout<<"2. Display grade roster\n";
cout<<"3. Display statistics\n";
cout<<"4. Exit\n";
cout<<"Your choice: ";
cin>>ch;
if(ch==1){
numberStudents=enterTestScoresViaUserPrompt(names,scores);
}else if(ch==2){
displayGradeRoster(scores,names,numberStudents);
}else if(ch==3){
displayClassStatistics(scores,numberStudents);
}else if(ch==4){
 
}else{
cout<<"Wrong menu item.\n\n";
}
}
return 0;
}

 

 

ScoreStatistics.cpp

#include "functions.hpp"
#include <iostream>
 
char getGrade(float score){
if(score>=90 && score<=100){
return 'A';
}
if(score>=80 && score<=89){
return 'B';
}
if(score>=70 && score<=79){
return 'C';
}
if(score>=60 && score<=69){
return 'D';
}
return 'F';
}
float computeMaxScore(float scores[],int numberStudents){
float maximumTestScore=scores[0];
for(int i=0;i<numberStudents;i++){
if(maximumTestScore<scores[i])
maximumTestScore=scores[i];
}
return maximumTestScore;

    float computeMinScore(float scores[],int numberStudents){
    float minimumTestScore=scores[0];
for(int i=0;i<numberStudents;i++){
if(minimumTestScore>scores[i]){
minimumTestScore=scores[i];
}
}
return minimumTestScore;
}
float computeAvgScore(float scores[],int numberStudents){
float totalScore=0;
for(int i=0;i<numberStudents;i++){
totalScore+=scores[i];
}
float classAverageScore=totalScore/(float)numberStudents;
return classAverageScore;
}


int enterTestScoresViaUserPrompt(string names[],float scores[]){
int numberStudents=-1;
while(numberStudents<=0){
cout<<"Enter the number of students: ";
cin>>numberStudents;
if(numberStudents<=0){
cout<<"\nInvalid value, please enter a correct value\n\n";
}
}
for(int i=0;i<numberStudents;i++){
cout<<"Enter the name of the student "<<(i+1)<<": ";
cin>>names[i];
scores[i]=-1;
while(scores[i]<0){
cout<<"Enter the score of the student "<<(i+1)<<": ";
cin>>scores[i];
if(scores[i]<=0){
cout<<"\nInvalid value, please enter a correct value\n\n";
}
}
}
return numberStudents;
}

void displayGradeRoster(float scores[],string names[],int numberStudents){
cout<<"\n";
cout<<fixed<<left<<setw(15)<<"Name"<<setw(15)<<"Test Score"<<"Grade\n";
cout<<left<<setw(15)<<"===="<<setw(15)<<"=========="<<"=====\n";
for(int i=0;i<numberStudents;i++){
cout<<left<<setw(15)<<names[i]<<setprecision(0)<<setw(15)<<scores[i]<<getGrade(scores[i])<<"\n";
}
cout<<"\n";
}

void displayClassStatistics(float scores[],int numberStudents){
cout<<"\n";
for(int i=0;i<15;i++){
cout<<"=";
}
cout<<"Class Statistics";
for(int i=0;i<15;i++){
cout<<"=";
}
float maximumTestScore=computeMaxScore(scores, numberStudents);
float minimumTestScore=computeMinScore(scores, numberStudents);
float classAverageScore=computeAvgScore(scores, numberStudents);;
 
cout<<"\nNumber of students in the class: "<<numberStudents<<"\n";
cout<<"Class Average score: "<<setprecision(4)<<classAverageScore<<"\n";
cout<<"Maximum Test score: "<<setprecision(0)<<maximumTestScore<<"\n";
cout<<"Minimum Test score: "<<minimumTestScore<<"\n\n";
}

function.hpp

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
 
char getGrade(float score);
float computeMaxScore(float scores[],int numberStudents);
float computeMinScore(float scores[],int numberStudents);
float computeAvgScore(float scores[],int numberStudents);
int enterTestScoresViaUserPrompt(string names[],float scores[]);
void displayGradeRoster(float scores[],string names[],int numberStudents);
void displayClassStatistics(float scores[],int numberStudents);

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binary numbers
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
  • SEE MORE 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