//Purpose:Thisprogramreadsdataforacomputerscienceclosedlabsection. //(1)Addafunc
ID: 3658122 • Letter: #
Question
//Purpose:Thisprogramreadsdataforacomputerscienceclosedlabsection.
//(1)AddafunctionStudentAvgwhichfindsandprintsthelabaverageforeach
//studentintheclass.Activatethisfunctioninthethemainprogram.
//(2)AddafunctionLabAvg()whichfindsandprintstheaveragescoremadeon
//eachindividuallab.Activatethisfunctioninthethemainprogram.
//Forbothfunctions,followtheformatspecified.
//Input:Thefirsttwoentriesintheinputarethenumberofstudents
//intheclassandthenumberofclosedlabstheclasshasfinished.
//Foreachstudent,theirclosedlabsareinputfromthe
//followinglinesofthefile.
//
//Limitations:Itisassumedthattherewillbenomorethan
//MAX_STUDENTSstudentsintheclassandtherewillbe
//nomorethanMAX_LABSlabs.
//includefiles...
#include<iostream>
usingnamespacestd;
//globalconstants...
constintMAX_STUDENTS=40;//maximumnumberofstudents
constintMAX_LABS=14;//maximumnumberofclosedlabs
//functionprototypes...
//functiontoreadlabsfromthedatafile
voidReadScores(intlabScores[][MAX_LABS],int&numStudents,int&numLabs);
//yourfunctionprototypesshouldgohere!!!
//StudentAvg()findsandprintsthelabaverageforeachstudentintheclass.
voidStudentAvg(constintlabScores[][MAX_LABS],intnumStudents,intnumLabs);
//LabAvg()findsandprintstheaveragescoremadeoneachindividuallab.
voidLabAvg(constintlabScores[][MAX_LABS],intnumStudents,intnumLabs);
intmain()
{
//localdeclarations...
intnumStudents;//howmanystudentsareintheclass
intnumLabs;//howmanyclosedlabs
intlabScores[MAX_STUDENTS][MAX_LABS];//holdslabscores
//readinthedataforallstudentsintheclass
ReadScores(labScores,numStudents,numLabs);
cout<<" Averageofeachstudent'slabscores:"<<endl;
//findeachstudent'slabaverage--usetheStudentAvg()
Activate function StudentAvg here with the labScores array.
cout<<" Averagescoreoneachlab:"<<endl;
//findandprinttheaveragescoremadeoneachindividuallab
//useyourLabAvg()functionhere
Activate function LabAvg here with the labScores array.
//endofmain...
return0;
}
//Function:ReadScores()
//Purpose:Thisfunctionreadsdataforstudentsinaclosedlabclass.
//Dataisreadfromthestandardinput.Thenumberofstudentsinthelab
//andthenumberofclosedlabsfinishedbyeachstudentarereadfirst.
//Next,foreachstudent,theirclosedlabsarereadintothe2Darraylabscores.
//Assumption:MAX_LABSisaglobalconstantwhichhasbeendefined
//previously.
voidReadScores(intlabScores[][MAX_LABS],//OUT:Holdsthelabscores
int&numStudents,//OUT:#ofstudents
int&numLabs)//OUT:NumberofLabs
{
//localdeclarations...
intstudent;//controlswhichstudent'slabsareread
intlab;//controlswhichlabisbeingread
//getthenumberofstudentsintheclass
cin>>numStudents>>numLabs;
//outerloopcontrolswhichstudent(row)isbeingread
for(student=0;student<numStudents;student++)
{
//innerloopcontrolswhichlab(column)isbeingread
for(lab=0;lab<numLabs;lab++)
cin>>labScores[student][lab];
}
return;
}
//PlacethedefinitionoftheStudentAvg()functionhere
//Student1:8.73
//Student2:9.255
//(donotuseanyoutputformattingfornumericvalues)
//Place the definition of the StudentAvg() function here // Student 1: 8.73 // Student 2: 9.255 // (do not use any output formatting for numeric values)
//PlacethedefinitionoftheLabAvg()functionhere
//Lab1:8.73
//Lab2:9.255
//(donotuseanyoutputformattingfornumericvalues)
//Place the definition of the LabAvg() function here // Lab 1: 8.73 // Lab 2: 9.255 // (do not use any output formatting for numeric values)
Here is what i have for the activation staements:
StudentAvg(labScores, numStudents, numLabs);
LabAvg(labScores, numStudents, numLabs);
and heres what i have for the definitions:
void StudentAvg(const int labScores[][MAX_LABS], int numStudents, int numLabs)
{
int student, lab;
for(student = 0; student < numStudents; student++)
{
double total = 0.0;
for(lab = 0; lab < numLabs; lab++)
{
total += labScores[student][lab];
}
double average = total/numLabs;
cout << "Student " << (student+1) << " average: " << average << endl;
}
}
second one:
void LabAvg(const int labScores[][MAX_LABS], int numStudents, int numLabs)
{
int student, lab;
for(lab = 0; lab < numLabs; lab++)
{
double total = 0.0;
for(student = 0; student < numStudents; student++)
{
total += labScores[student][lab];
}
double average = total/numStudents;
cout << "Lab " << (lab+1) << " average: " << average << endl;
}
}
Explanation / Answer
//includefiles... #include using namespace std; //globalconstants... const int MAX_STUDENTS=40;//maximumnumberofstudents const int MAX_LABS=14;//maximumnumberofclosedlabs //functionprototypes... //functiontoreadlabsfromthedatafile void ReadScores(int labScores[][MAX_LABS],int &numStudents,int &numLabs); //yourfunctionprototypesshouldgohere!!! //StudentAvg()findsandprint sthelabaverageforeachstudentint heclass. void StudentAvg(const int labScores[][MAX_LABS],int numStudents,int numLabs); //LabAvg()findsandprint stheaveragescoremadeoneachindividuallab. void LabAvg(const int labScores[][MAX_LABS],int numStudents,int numLabs); int main() { //localdeclarations... int numStudents;//howmanystudentsareint heclass int numLabs;//howmanyclosedlabs int labScores[MAX_STUDENTS][MAX_LABS];//holdslabscores //readint hedataforallstudentsint heclass ReadScores(labScores,numStudents,numLabs); coutnumLabs; //outerloopcontrolswhichstudent(row)isbeingread for(student=0;studentlabScores[student][lab]; } return; } //PlacethedefinitionoftheStudentAvg()functionhere //Student1:8.73 //Student2:9.255 //(donotuseanyoutputformattingfornumericvalues) /// void StudentAvg(const int labScores[][MAX_LABS], int numStudents, int numLabs) { int student, lab; double total; double average; for(student = 0; studentRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.