Answer to Question #216760 in C++ for Mamsy

Question #216760
Baby Life is a newly founded public clinic. They receive at least 40 maternity patients each day.

Create a C++ program that displays a menu to the user. The menu should have three options, namely (1) save patients details, (2) display patient details and (3) for exiting the program. The program should make use of two functions, addPatient () to add patient details. Use an array to store patient details. Then the second function is display patient () which should display the patient details. Ensure that both functions give an option to either add or display the number of patients to be added or displayed. Also, ensure that the program repeatedly shows the list of options until the point option 3 is selected, which terminates the program.
1
Expert's answer
2021-07-14T00:49:03-0400
#include <iostream>
#include <queue>

using namespace std;

struct patient {
  string name;
  int age;
  bool is_male;
};

patient make_p() {
  // todo impl...
  return patient();
}

void menu() {
  cout << "   Menu" << endl;
  cout << "1) Add patient" << endl;
  cout << "2) Show" << endl;
}

queue<patient> list;

void addPatient(patient p) {
  list.push(p);
}

void show() {
  for (auto p : list) {
    cout << "===" << endl;
    cout << "nmae: " << p.name << endl;
    cout << "age: " << p.age << endl;
    cout << "is mail: " << p.is_male << endl;
  }
}

int main() 
{
  bool running = true;
  while (running) {
    menu();
    int choice; cin >> choice;
    switch (choice) {
      case 1:
        addPatient(make_p());
        cout << "Successfully added a new patent" << endl;
      case 2:
        show();
      case 3:
        running = false;
        cout << "Terminated!" << endl;
        break;
      default:
        cout << "Invalid choice!" << endl;
        break;
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS