x.Hme: This program reads data for a computer science closed lab section. // Add
ID: 3618017 • Letter: X
Question
x.Hme: This program reads data for a computer science closed lab section.// Add a function PrintScores that prints 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....
.... */
//Input: The first two entries in the input are the number of students
// in the class and the number of closed labs the class has finished.
// For each student, their closed labs are input from the
// following lines of the file.
//
//Limitations: It is assumed that there will be no more than
// MAX_STUDENTS students in the class and there will be
// no more than MAX_LABS labs.
//include files...
#include <iostream>
using namespace std;
//global constants...
const int MAX_STUDENTS=40; //maximum number of students
const int MAX_LABS=14; //maximum number of closed labs
//function prototypes...
//function to read labs from the data file
void ReadScores(int labScores[][MAX_LABS], int& numStudents, int& numLabs);
//function prototypes for PrintScores
void PrintScores(const int labScores[][MAX_LABS], int numStudents, int numLabs);
int main()
{
//local declarations...
int numStudents; //how many students are in the class
int numLabs; //how many closed labs
int labScores[MAX_STUDENTS][MAX_LABS]; //holds lab scores
//read in the data for all students in the class
ReadScores(labScores, numStudents, numLabs);
//print the data in labScores read using ReadScores
//call PrintScores function here
//end of main...
return 0;
}
//Function: ReadScores()
//Purpose: This function reads data for students in a closed lab class.
// Data is read from the standard input. The number of students in the lab
// and the number of closed labs finished by each student are read first.
// Next, for each student, their closed labs are read into the 2D array labscores.
//Assumption: MAX_LABS is a global constant which has been defined
// previously.
void ReadScores(int labScores[][MAX_LABS], //OUT: Holds the lab scores
int& numStudents, //OUT: # of students
int& numLabs) //OUT: Number of Labs
{
//local declarations...
int student; //controls which student's labs are read
int lab; //controls which lab is being read
//get the number of students in the class
cin >> numStudents >> numLabs;
//outer loop controls which student(row) is being read
for (student = 0; student < numStudents; student++)
{
//inner loop controls which lab(column) is being read
for (lab = 0; lab < numLabs; lab++)
cin >> labScores[student][lab];
}
Explanation / Answer
please rate - thanks //Purpose: This program reads data for acomputer science closed lab section. // Add a function PrintScores that prints the scores so thateach student's labs appear // on a separate line of output. Your output should belabeled 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 98100 65 0 56 Student 3: 85 60 25.... .... */ //Input: The first two entriesin the input are the number of students // in the class and the number of closed labs the class hasfinished. // For each student, their closed labs are input from the // following lines of the file. // //Limitations: It is assumed that there will be no more than // MAX_STUDENTS students in the class and there will be // no more than MAX_LABS labs. //include files... #include using namespace std; //global constants... const intMAX_STUDENTS=40; //maximum number of students const intMAX_LABS=14; //maximum number of closed labs //function prototypes... //function to read labs from the data file void ReadScores(int labScores[][MAX_LABS], int& numStudents,int& numLabs); //function prototypes for PrintScores void PrintScores(const int labScores[][MAX_LABS], int numStudents,int numLabs); int main() { //local declarations... intnumStudents; //how many students are in the class intnumLabs; //how many closed labs intlabScores[MAX_STUDENTS][MAX_LABS]; //holds labscores //read in the data for all students in the class ReadScores(labScores, numStudents, numLabs); //print the data in labScores read usingReadScores //call PrintScores function herePrintScores(labScores,numStudents,numLabs); //end of main... return 0; } //Function: ReadScores() //Purpose: This function reads data forstudents in a closed lab class. // Data is read from the standard input. Thenumber of students in the lab // and the number of closed labs finished by eachstudent are read first. // Next, for each student, theirclosed labs are read into the 2D array labscores. //Assumption: MAX_LABS is a global constant which has beendefined // previously. void ReadScores(int labScores[][MAX_LABS], //OUT: Holds thelab scores int&numStudents, //OUT: # of students int&numLabs) //OUT: Number of Labs { //local declarations... intstudent; //controls which student's labs are read intlab; //controls which lab is being read //get the number of students in the class cin >> numStudents >> numLabs; //outer loop controls which student(row) is beingread for (student = 0; student labScores[student][lab]; } return; } //Place the definition of your function to print the scoreshere void PrintScores(const int labScores[][MAX_LABS],int numStudents, int numLabs) {int student,lab; for(student=0;student
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.