Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; // Declaring a new struct to store patient data struct patient { int age; char name[20]; float balance; };

#include  #include  #include  using namespace std; // Declaring a new struct to store patient data struct patient { int age; char name[20]; float balance; }; // TODO: // IMPLEMENT A FUNCTION THAT COMPARES TWO PATIENTS BY AGE // THE FUNCTION RETURNS AN INTEGER AS FOLLOWS: // -1 IF THE AGE OF THE FIRST PATIENT IS LESS // THAN THE SECOND PATIENT'S AGE // 0 IF THE AGES ARE EQUAL // 1 OTHERWISE // TODO: // IMPLEMENT A FUNCTION THAT COMPARES TWO PATIENTS BY BALANCE DUE // THE FUNCTION RETURNS AN INTEGER AS FOLLOWS: // -1 IF THE BALANCE FOR THE FIRST PATIENT IS LESS // THAN THE SECOND PATIENT'S BALANCE // 0 IF THE BALANCES ARE EQUAL // 1 OTHERWISE // TODO: // IMPLEMENT A FUNCTION THAT COMPARES TWO PATIENTS BY NAME // THE FUNCTION RETURNS AN INTEGER AS FOLLOWS: // -1 IF THE NAME OF THE FIRST PATIENT GOES BEFORE // THE SECOND PATIENT'S NAME // 0 IF THE AGES ARE EQUAL // 1 OTHERWISE // // HINT: USE THE strncmp FUNCTION // (SEE http://www.cplusplus.com/reference/cstring/strncmp/) // The main program int main() { int total_patients = 5; // Storing some test data struct patient patient_list[5] = { {25, "Juan Valdez ", 1250}, {15, "James Morris ", 2100}, {32, "Tyra Banks ", 750}, {62, "Mario O'Donell", 375}, {53, "Pablo Picasso ", 615} }; cout << "Patient List: " << endl; // TODO: // IMPLEMENT THE CODE TO DISPLAY THE CONTENTS // OF THE ARRAY BEFORE SORTING cout << endl; cout << "Sorting..." << endl; // TODO: // CALL THE qsort FUNCTION TO SORT THE ARRAY BY PATIENT AGE cout << "Patient List - Sorted by Age: " << endl; // TODO: // DISPLAY THE CONTENTS OF THE ARRAY // AFTER SORTING BY AGE cout << endl; cout << "Sorting..." << endl; // TODO: // CALL THE qsort FUNCTION TO SORT THE ARRAY BY PATIENT BALANCE cout << "Patient List - Sorted by Balance Due: " << endl; // TODO: // DISPLAY THE CONTENTS OF THE ARRAY // AFTER SORTING BY BALANCE cout << endl; cout << "Sorting..." << endl; // TODO: // CALL THE qsort FUNCTION TO SORT THE ARRAY BY PATIENT NAME cout << "Patient List - Sorted by Name: " << endl; // TODO: // DISPLAY THE CONTENTS OF THE ARRAY // AFTER SORTING BY NAME cout << endl; return 0; } student submitted image, transcription available below
e. Add a prompt to ask the user to input their last name (no spaces ; please use underscores if needed), age and a balance of their choice. Create a new entry in the patient_list array with this information [Important note: you can statically modify the code to have the patient_list array hold an extra entry ; no need to do any dynamic memory allocation to accommodate the new entry]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions