// CS2310 Exercise 12 // // Name ____________________ // // Chapter 15: p892 - 5 // // Given the following declaration and code segment, the PtrToMax // function returns a pointer: the value of p1, p2, or p3, whichever // points to the struct with the highest value of score. Implement // the PtrToMax function. // #include using namespace std; struct GradeType { int score; char grade; }; typedef GradeType* PtrType; PtrType PtrToMax( /* in */ PtrType p1, /* in */ PtrType p2, /* in */ PtrType p3 ) // Precondition: // p1, p2, and p3 point to assigned structs // Postcondition: // Function value == p1, p2, or p3, whichever points to the // struct with the greatest score member { PtrType ptrToMax = p1; // Pointer to struct with max. score // Write the omitted code here. return ptrToMax; } int main() { PtrType p1 = new GradeType; PtrType p2 = new GradeType; PtrType p3 = new GradeType; PtrType p4; p1->score = 56; p1->grade = 'F'; p2->score = 67; p2->grade = 'D'; p3->score = 80; p3->grade = 'B'; p4 = PtrToMax(p1, p2, p3); cout << "The highest score is: " << p4->score << endl; p1->score = 56; p1->grade = 'F'; p2->score = 90; p2->grade = 'A'; p3->score = 80; p3->grade = 'B'; p4 = PtrToMax(p1, p2, p3); cout << "The highest score is: " << p4->score << endl; p1->score = 78; p1->grade = 'C'; p2->score = 67; p2->grade = 'D'; p3->score = 75; p3->grade = 'C'; p4 = PtrToMax(p1, p2, p3); cout << "The highest score is: " << p4->score << endl; delete p1; delete p2; delete p3; return 0; }