Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//(1)AddafunctionStudentAvgwhichfindsandprintsthelabaverageforeach //studentinth

ID: 3657688 • Letter: #

Question

//(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)

Explanation / Answer

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;
}
}

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;
}
}