Question: Debug#3 #include #include using namespace std; struct test { string name; double score; }; //void sort(test*, int); void sort(test a[], int number); int main() {

Debug#3

#include #include using namespace std;

struct test { string name; double score; };

//void sort(test*, int); void sort(test a[], int number);

int main() { test* scores = nullptr; int classSize; cout << "How manys students took the test." << endl; cin >> classSize; scores = new test[classSize]; test* p = scores;

while () { cout << "Enter the name of the student" << endl; cin >> scores->name; cout << "Enter " << scores->name << "'s score" << endl; cin >> scores->score; scores++; } while () { cout << scores->name << " " << scores->score << endl; scores++;

} while () { cout << "Boo" << endl; cout << scores->name << " got a " << scores->score << endl; scores++; } delete []scores; scores = nullptr;

system("pause"); }

void sort(test* score, int size) { cout << "hello" << endl; int startScan, minIndex; double minValue;

for (startScan = 0; startScan < (size - 1); startScan++) { minIndex = startScan; minValue = score[startScan].score;

for (int index = startScan + 1; index < size; index++) { if (score[index].score < minValue) { minValue = score[index].score; minIndex = index; } }

score[minIndex].score = score[startScan].score; score[startScan].score = minValue;

} } /*void sort(test a[], int number) { for (int k = number - 1; k >= 1; k--) { // Find maximum of a[0..k] test* maxPointer = a; for (test* p = a + 1; p != a + k + 1; p++) { if (p->score > maxPointer->score) maxPointer = p; } // Swap *maxPointer with a[k] swap(*maxPointer, *(a + k)); } }*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!