CPS 6 Test 2 Solutions Prof. Rodger Fall 2000 Problem 1 Mystery(3) 1 3 2 Something(-12) -12 -7 -2 1 Problem 2 - Part A int NumSolved(const tmatrix & teams, int row) // pre: all entries in teams are 0 or 1, 1 indicates the problem was solved // post: returns the number of problems solved by the team in row { int k; int count = 0; for (k=0; k 0) count ++; } return count; } Problem 2 - Part B int MaxNumSolved(const tmatrix & teams) // post: Returns the maximum number of problems solved by a team { int j, cnt, maxcnt; maxcnt = 0;; for (j=0; j maxcnt) { maxcnt = cnt; } } return maxcnt; } Problem 3 - Part A Poll::Poll() : myStudents(0), myNumStudents(0) { } Problem 3 - Part B void Poll::ReadIn() // post: reads in data into myStudents. For each student puts in // the candidates name (one word) and the first and last name only // of the student. Updates myNumStudents. { Person temp; string line; while (getline(cin, line)) { istrstream input(line.c_str()); input >> temp.cand; input >> temp.first; while (input >> temp.last) { // empty } myStudents.push_back(temp); } myNumStudents = myStudents.size(); } Problem 3 - Part C int Poll::Count(const string & name) // post: returns the number of votes for name { int num = 0; int k; for (k=0; k & allnames, const string & name) // post: returns true if name appears in allnames, otherwise returns false { int k; for (k=0; k Poll::Candidates() // post: returns an array of candidate names, one entry per candidate, // the array contains size() entries { int k; tvector temp; for (k = 0; k