I am having trouble having this c++ code run correctly. I need some assistance as I am now lost. Below I have inserted a snip of the results when I complie everything in GDN online. ( https://www.onlinegdb.com/edit/BlpBk7fqx ) main.cpp #include "ScoreStatistics.cpp" #include 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 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;iscores[i]){ minimumTestScore=scores[i]; } } return minimumTestScore; } float computeAvgScore(float scores[],int numberStudents){ float totalScore=0; for(int i=0;i>numberStudents; if(numberStudents<=0){ cout<<"\nInvalid value, please enter a correct value\n\n"; } } for(int i=0;i>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< #include #include #include 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);
I am having trouble having this c++ code run correctly. I need some assistance as I am now lost. Below I have inserted a snip of the results when I complie everything in GDN online.
( https://www.onlinegdb.com/edit/BlpBk7fqx )
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);
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images