Skip to main content

C++ program for a hospital

Here's a simple C++ program for a hospital:


#include <iostream>
#include <string>
using namespace std;

class Patient {
private:
    string name;
    int age;
    string disease;
    string doctor;

public:
    void inputDetails() {
        cout << "Enter patient name: ";
        cin.ignore();
        getline(cin, name);
        cout << "Enter patient age: ";
        cin >> age;
        cout << "Enter patient disease: ";
        cin.ignore();
        getline(cin, disease);
        cout << "Enter doctor's name: ";
        getline(cin, doctor);
    }

    void displayDetails() {
        cout << "\nPatient Details\n";
        cout << "Name: " << name << endl;
        cout << "Age: " << age << endl;
        cout << "Disease: " << disease << endl;
        cout << "Doctor: " << doctor << endl;
    }
};

class Hospital {
private:
    string hospitalName;
    string address;
    Patient patients[10];
    int numberOfPatients;

public:
    void inputHospitalDetails() {
        cout << "Enter hospital name: ";
        cin.ignore();
        getline(cin, hospitalName);
        cout << "Enter hospital address: ";
        getline(cin, address);
    }

    void addPatient() {
        patients[numberOfPatients].inputDetails();
        numberOfPatients++;
    }

    void displayPatientDetails() {
        for (int i = 0; i < numberOfPatients; i++) {
            patients[i].displayDetails();
        }
    }

    void displayHospitalDetails() {
        cout << "\nHospital Details\n";
        cout << "Name: " << hospitalName << endl;
        cout << "Address: " << address << endl;
    }
};

int main() {
    Hospital hospital;
    int choice;
    hospital.numberOfPatients = 0;
    hospital.inputHospitalDetails();
    while (true) {
        cout << "\nHospital Management System\n";
        cout << "1. Add patient\n";
        cout << "2. Display patient details\n";
        cout << "3. Display hospital details\n";
        cout << "4. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;
        switch (choice) {
            case 1:
                hospital.addPatient();
                break;
            case 2:
                hospital.displayPatientDetails();
                break;
            case 3:
                hospital.displayHospitalDetails();
                break;
            case 4:
                return 0;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    }
    return 0;
}


*Example Output:*

Enter hospital name: Apollo Hospital
Enter hospital address: 123 Main St

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 1

Enter patient name: John Doe
Enter patient age: 30
Enter patient disease: Flu
Enter doctor's name: Dr. Smith

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 2

Patient Details
Name: John Doe
Age: 30
Disease: Flu
Doctor: Dr. Smith

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 3

Hospital Details
Name: Apollo Hospital
Address: 123 Main St


This program defines two classes: `Patient` and `Hospital`. The `Patient` class has private member variables for patient details and public methods for inputting and displaying patient details. The `Hospital` class has private member variables for hospital details and patient data, as well as public methods for inputting hospital details, adding patients, displaying patient details, and displaying hospital details.

In the `main()` function, a `Hospital` object is created, and the user is presented with a menu to add patients, display patient details, display hospital details, or exit the program.

Comments

Popular posts from this blog

Solve

Directions: In each Q1 to Q3 of the following questions, there are five letter groups or words in each question. Four of these letter groups or words are alike in some way, while one is different. Find the one which is different. Q.1.    (1) black    (2) red    (3) green    (4) paint    (5) yellow Answer:- (4) paint Q.2.    (1) BC    (2) MN    (3) PQ    (4) XZ    (5) ST Answer :-(4)XZ Q.3.    (1) Mango    (2)Apple    (3) Orange    (4) Guava    (5) Rose Answer :- (5) Rose Directions : In each of the following questions, there is a question mark in which only one of the five alternatives given under the question satisfies the same relationship as is found between the two terms to the left of the sign :: given in the question. Find the correct answer ...

Solved practical slips of 12th Computer Science journal

Program 1:- Write a function in C++ that exchanges data (passing by references )using swap function to interchange the given two numbers.*/ # include<iostream.h> # include<conio.h> void swap(float &x ,float &y) { float t=x; x=y; y=t; } void main() { void swap(float &,float &); float a,b; cin>>a>>b; cout<<” a := ” << a <<” b := ”<< b<< endl; swap(a,b); cout<< ”a:= ”<< a<< ” b := ”<< b<< endl; } Output : 2 4 a := 2 b:= 4 a:= 4 b: =2   Program 2:- Write a program in C++ with a ratio class using member functions like assign () function to initialize its member data integer numerator and denominator ,convert() function to convert the ratio into double, invert() to get the inverse of the ratio and print() function to print the ratio and its reciprocal.*/ ...

SOLVE QUESTION ANSWERS ON OPERATING SYSTEM .

1.One can interface with operating system by means of ------- A) Operating system call in a program B) Operating system commands C) Operating system process D) Both by operating system call and operating system commands Answer :-  D) Both by operating system call and operating system commands 2. Which of the following is not type of processing ? A) Serial B) Network C) Batch D) Multiprogramming Answer :- B) Network 3. Kernel is _____ A) A part of operating system B) An operating system C) A hardware D) A register Answer :-  A) A part of operating system 4. UNIX operating system is based on ______ A) Language structure B) Kernel approach C) Virtual machine D) Time sharing Answer :-   B) Kernel approach 5. A transition between two memory resident process in a memory resident process in amultiprograming system is called ______ A) Process switch B) Mode switch C) Transition switch D) None of these Answer :-    A) Process ...