//Addacodetoprintthescoressothateachstudent\'slabsappear //onaseparatelineofoutp
ID: 3657692 • Letter: #
Question
//Addacodetoprintthescoressothateachstudent'slabsappear
//onaseparatelineofoutput.Youroutputshouldbelabeledasfollows:
/*
Student1:80907010060908578938070988994
Student2:9885100998990720789810065056
Student3:856025....
.
.
*/
//Input:Thefirsttwoentriesintheinputarethenumberofstudents
//intheclassandthenumberofclosedlabstheclasshasfinished.
//Foreachstudent,theirclosedlabsareinputfromthe
//followinglinesofthefile.
//
//Limitations:ItisassumedthattherewillbenomorethanMAX_STUDENTSstudents
//intheclassandtherewillbenomorethanMAX_LABSlabs.
//includefiles...
#include<iostream>
usingnamespacestd;
//globalconstants...
constintMAX_STUDENTS=40;//maximumnumberofstudents
constintMAX_LABS=14;//maximumnumberofclosedlabs
intmain()
{
//localdeclarations...
intnumStudents;//howmanystudentsareintheclass
intnumLabs;//howmanyclosedlabs
intlabScores[MAX_STUDENTS][MAX_LABS];//holdslabscores
intstudent;//controlswhichstudent'slabsareread
intlab;//controlswhichlabisbeingread
//readinthedataforallstudentsintheclass
//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];
}
//printthedataforallstudentsintheclass
// Add a code 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 Note: do NOT put a space before the end of line. It will grade as wrong.
//endofmain...
return0;
}
Explanation / Answer
//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
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.