// roster_05.cpp // CS302 // James S. Plank // EECS Department, University of Tennessee // August, 2009 // #include "roster_05.h" Roster::Roster(int starting_number) { start = starting_number; } void Roster::Add_name(string name) { names.push_back(name); } void Roster::Print(int columns, int print_names) { int i, c, j, tmp; vector randomize; randomize.resize(names.size()); for (i = 0; i < randomize.size(); i++) randomize[i] = i; for (j = randomize.size(); j > 0; j--) { i = lrand48()%j; tmp = randomize[j-1]; randomize[j-1] = randomize[i]; randomize[i] = tmp; } c = 0; cout << "\n"; for (i = 0; i < names.size(); i++) { if (c == 0) cout << "\n"; // Start a new row when c = 0. cout << "" << endl; c++; if (c == columns) { // End the row when c == columns cout << "\n"; c = 0; } } if (c != 0) cout << "\n"; // If the last row is incomplete, end it. cout << "
"; printf("", randomize[i]+start); if (print_names) cout << "
" << names[randomize[i]]; cout << "
\n"; }