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

//AddafunctionPrintScoresthatprintsthescoressothateachstudent\'slabsappear //ona

ID: 3657691 • Letter: #

Question

//AddafunctionPrintScoresthatprintsthescoressothateachstudent'slabsappear
//onaseparatelineofoutput.Youroutputshouldbelabeledasfollows:
/*Student1:80907010060908578938070988994
Student2:9885100998990720789810065056
Student3:856025....
....*/
//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);
//functionprototypesforPrintScores
voidPrintScores(constintlabScores[][MAX_LABS],intnumStudents,intnumLabs);

intmain()
{
//localdeclarations...
intnumStudents;//howmanystudentsareintheclass
intnumLabs;//howmanyclosedlabs
intlabScores[MAX_STUDENTS][MAX_LABS];//holdslabscores

//readinthedataforallstudentsintheclass
ReadScores(labScores,numStudents,numLabs);

//printthedatainlabScoresreadusingReadScores
//call PrintScores function here

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

//Placethedefinitionofyourfunctiontoprintthescoreshere
// Add a function to print the scores so that each student's labs appear // on a separate line of output. Your output should be labeled as follows: Student 1: 80 90 70 100 60 90 85 78 93 80 70 98 89 94 Student 2: 98 85 100 99 89 90 72 0 78 98 100 65 0 56 Student 3: 85 60 25.... //there should be a nested loop //outer loop controls which student(row) is being read

Explanation / Answer

void PrintScores(const int labScores[][MAX_LABS], int numStudents, int numLabs)
{
int student, lab;

//outer loop controls which student(row) is being printed
for(student=0; student<numStudents; student++)
{
cout << "Student " << (student+1) << ":";
// inner loop controls which lab(column) is being printed
for(lab=0; lab<numLabs; lab++)
{
cout << " " << labScores[student][lab];
}
cout << endl; // new line after each student
}
}