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);
![Run
O Debug
1 Stop
C Share
A Save
{} Beautify
Language C++
main.cpp
ScoreStatistics.cpp : functions.hpp !
1 #include "ScoreStatistics.cpp"
2 #include <iostream>
3- int main() {
4 int ch=1;
5 string names[100];
6 float scores[100];
7 int numberStudents=0;
8 - while(ch!=4){_
input
stderr
Compilation failed due to following error(s).
ScoreStatistics.cpp:(.text+0x0): multiple definition of `getGrade(float)'; /tmp/cc73vNAV.o:main.cpp:( .text+0x0): first defined here
/usr/bin/ld: /tmp/CCU590AV.o: in function `computeMaxScore(float*, int)':
ScoreStatistics.cpp:(.text+0xa0): multiple definition of `computeMaxScore(float*, int)'; /tmp/cc73vNAV.o:main.cpp:(.text+0xa0): first defined here
/usr/bin/ld: /tmp/CCU590AV.o: in function `computeMinScore(float*, int)':
ScoreStatistics.cpp:(.text+0x113): multiple definition of `computeMinScore(float*, int)'; /tmp/cc73vNAV.o:main.cpp:(.text+0x113): first defined here
/usr/bin/ld: /tmp/CCU590AV.o: in function `computeAvgScore(float*, int)':
ScoreStatistics.cpp:(.text+0x18a): multiple definition of `computeAvgScore(float*, int)'; / tmp/cc73vNAV.o:main.cpp:(.text+0x18a): first defined here
/usr/bin/ld: /tmp/CCU590AV.o: in function `enterTestScoresViaUserPrompt(std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, float*)':
ScoreStatistics.cpp:(.text+0x1f7): multiple definition of `enterTestScoresViaUserPrompt(std::_cxx11::basic_string, std::allocator >*, float*)'; /tmp/CC73VNAV.o:main.
/usr/bin/ld: /tmp/CCU590AV.o: in function `displayGradeRoster(float*, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)':
ScoreStatistics.cpp:(.text+0x3cc): multiple definition of `displayGradeRoster (float*, std: :_cxx11::basic_string, std::allocator >*, int)'; /tmp/cc73vNAV.o: main.cpp:(
/usr/bin/ld: /tmp/CCU590AV.o: in function `displayClassStatistics (float*, int)':
ScoreStatistics.cpp:(.text+0x5f5): multiple definition of `displayClassStatistics(float*, int)'; /tmp/CC73VNAV.o:main.cpp:(.text+0x5f5): first defined here
collect2: error: ld returned 1 exit status](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F86bfc21f-7304-4d6a-8ae3-de059a5180e7%2F61e09533-9acc-4f6d-9975-6663db926984%2Fsdg378_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









