Question: Can you help me finish the code and explain. // Name: get_ranking // PreCondition: just the time array is passed in, and has valid data
Can you help me finish the code and explain.
// Name: get_ranking // PreCondition: just the time array is passed in, and has valid data // PostCondition: after a very inefficient nested loop to determine the placements // and places the ranks in a new array. That new array is returned //--------------------------------------------------------- void get_ranking(const double timeArray[], unsigned int rankArray[]) const double timeArray[] = {} //TODO //------------------------------------------------------- // Name: print_results // PreCondition: all parallel arrays are passed in and have valid data // PostCondition: after a very inefficient nested loop to determine the ranks // it then displays them along with a delta in time from the start //--------------------------------------------------------- void print_results(const double timeArray[], const std::string countryArray[], const std::string lastnameArray[], const unsigned int rankArray[]) { std::cout << "Final results!!"; std::cout << std::setprecision(2) << std::showpoint << std::fixed << std::endl; double best_time = 0.0; // print the results, based on rank, but measure the time difference_type for(unsigned int j = 1; j <= SIZE; j++) { // go thru each array, find who places in "i" spot for(unsigned int i = 0; i < SIZE; i++) { if(rankArray[i] == 1) // has to be a better way, but need the starting time { best_time = timeArray[i]; } if(rankArray[i] == j) // then display this person's data { // this needs precision display std::cout << "[" << j << "] " << timeArray[i] << " " << std::setw(15) << std::left << lastnameArray[i] << "\t" << "(" << countryArray[i] << ") +" << (timeArray[i] - best_time) << std::endl; } } } } std::string trim(std::string ret) { // remove whitespace from the beginning while (!ret.empty() && isspace(ret.at(0))) { ret.erase(0, 1); } // remove whitespace from the end // Note: last index is (.size() - 1) due to 0 based indexing while (!ret.empty() && isspace(ret.at(ret.size()-1))) { ret.erase(ret.size()-1, 1); } return ret; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
