int CountUntilSum(int numDice) { Vector a(numDice,0); Dice d(6); int j,k; int count = 0; int first; bool allSame = false; while (! allSame) { count++; for(k=0; k < numDice; k++) // store all rolls { a[k] = d.Roll(); } first = a[0]; // compare against this allSame = true; for(j=1; j < numDice; j++) { if (a[j] != first) { allSame = false; break; } } } return count; } int CountUntilSum(int numDice) { Dice d(6); bool allSame = false; int count = 0; int k; while (! allSame) { allSame = true; int firstRoll = d.Roll(); // store first roll for(k=1; k < numDice; k++) { if (d.Roll() != firstRoll) // check other rolls { allSame = false; break; } } } } int MaxRowIndex(const Vector & v, int size) // precondition: # elements in v = size // postcondition: returns index of largest (absolute value) element in v { int k; int max = 0; for(k=1; k < size; k++) { if (v[k] > v[max]) { max = k; } } return max; } void Dominators(const Matrix & m) { int rows = m.Rows(); int cols = m.Cols(); int j,k; for(k=0; k < rows; k++) { int maxCol = MaxRowIndex(m[k],cols); int maxRow = MaxColIndex(m,maxCol); if (k == maxRow) { cout << k << ", " << rm << " = " << m[k][rm] << endl; } } } // inefficient version void Dominators(const Matrix & m) { int rows = m.Rows(); int cols = m.Cols(); int j,k; for(k=0; k < rows; k++) { for(j=0; j < cols; j++) { if (MaxRowIndex(m[k],cols) == j && MaxColIndex(m,j) == k) { cout << k << ", " << rm << " = " << m[k][rm] << endl; } } } Rollodex::Rollodex() : myList(100), myCount(0) { // done in initializer list } void Rollodex::SearchZip(const string & zip, Rollodex & match) // precondition: match is an empty rollodex // postcondition: all entries with zipcode matching value of zip // are copied into match { int k; for(k=0; k < myCount; k++) { if (myList[k].address.zip == zip) { match.Add(myList[k]); } } }