Question
C++ program
Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to
4. delete_patient_record: This function uses to delete a specific record from the file Patient.txt, i.e. the matched patien
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

I have created the program with just files, please see the output screenshots before executing the program.

Program:

//header files
#include <iostream>
#include<string>
#include <fstream>
#include <cstring>

using namespace std;

//function to display menu
char hospital_menu()
{
cout << "\nArkansas Children Hospital" << endl
<< endl;

cout << "a. Add new patient record" << endl;
cout << "b. search record" << endl;
cout << "c. Deletea record" << endl;
cout << "d. Print all records" << endl;
cout << "e. Exit " << endl;

char ch;
cout << "Enter your choice HERE=> ";
cin >> ch;

return ch;
}

//function to add new paient
void add_new_patient()
{

int id;
string name;
string address;
string dob;
string gender;

cout << "Enter patient details.."<<endl;;
cout << "Enter id: ";
cin >> id;

while ((getchar()) != '\n');

cout << "Enter name: ";
getline(cin, name);

cout << "Enter address: ";
cin >> address;

cout << "Enter date of birth: ";
cin >> dob;

cout << "Enter gender: ";
cin >> gender;

std::fstream fs;
fs.open("Patient.txt", std::fstream::in | std::fstream::out | std::fstream::app);

fs << id << " " << name << " " << address << " " << dob << " " << gender << endl;

fs.close();
}

//function to search for a patient
void search_patient()
{

std::fstream fs;
fs.open("Patient.txt", std::fstream::in | std::fstream::out | std::fstream::app);

string d;
cout << "Enter patient dob: ";
cin >> d;

int id;
string fname;
string lname;
string address;
string dob;
string gender;
string fn, ln;

while (fs >> id >> fname >> lname >> address >> dob >> gender)
{

int result = dob.compare(d);
if (result == 0)
{
cout << "Enter first name: ";
cin >> fn;
cout << "Enter last name: ";
cin >> ln;

string ff = fn + ln;
string ff1 = fname + lname;

result = ff.compare(ff1);
if (result == 0)
{
cout << "Record found..." <<endl;
cout << "Id:" << id << "\nName: " << fname << " " << lname << "\nAddress: " << address << "\nDOB: " << dob << "\nGender: " << gender << endl;
return;
}
}
}

cout << "This is a new patient, please select option \'a\' from the menu." << endl;

fs.close();
}

//function to delete a patient based on id
void delete_patient_record()
{

std::fstream fs;
fs.open("Patient.txt", std::fstream::in | std::fstream::out | std::fstream::app);

int d;
cout << "Enter patient id: ";
cin >> d;

int id;
string fname;
string lname;
string address;
string dob;
string gender;
string fn, ln;

while (fs >> id >> fname >> lname >> address >> dob >> gender)
{

if (d == id)
{
break;
}
else
{
cout << "Patient record with id " << d << " not found!!" << endl;
return;
}
}

std::fstream fs1;
fs1.open("Patient.txt", std::fstream::in | std::fstream::out | std::fstream::app);

ofstream temp;
temp.open("temp.txt");

while (fs >> id >> fname >> lname >> address >> dob >> gender)
{

if (d != id)
{

temp << id << " " << fname << " " << lname << " " << address << " " << dob << " " << gender << endl;
}
}

temp.close();
fs1.close();
remove("Patient.txt");
rename("temp.txt", "Patient.txt");
}

//function to print all patient records
void print_all_record()
{

std::fstream fs;
fs.open("Patient.txt", std::fstream::in | std::fstream::out | std::fstream::app);

int id;
string fname;
string lname;
string address;
string dob;
string gender;
string fn, ln;

cout << "Id "
<< "Name\t"
<< "Address\t\t\t"
<< "DOB\t\t"
<< "Gender" << endl;

while (fs >> id >> fname >> lname >> address >> dob >> gender)
{
cout << id<<" " << fname <<" " << lname<< "\t" << address <<"\t\t" << dob <<"\t"<< gender << endl;
}
}

//main method
int main()
{

while(true){
char ch = hospital_menu();
if(ch != 'a' && ch != 'b' && ch != 'c' && ch != 'd' && ch != 'e')
break;

switch (ch)
{
case 'a':
add_new_patient();
break;
case 'b':
search_patient();
break;
case 'c':
delete_patient_record();
break;

case 'd':
print_all_record();
break;
case 'e':
return 1;
break;
default:
break;
}
}
return 0;

}

magic.cpp C prime. FindPatientRecords.cs pt.cpp X mat.py Cpt.C RunLengthEncoding.java print_all_record() DateTest.cs Date.cs

Output Screenshots:

ramesh@rameshk:-/Music/cpp/patients is a.out Patient.txt pt.cpp ramesh@rameshk:-/Music/cpp/patients cat Patient.txt ramesh@ra

Arkansas Children Hospital a. Add new patient record b. search record c. Deletea record d. Print all records le. Exit Enter y

Arkansas Children Hospital a. Add new patient record b. search record c. Deletea record d. Print all records e. Exit Enter yo

Arkansas Children Hospital a. Add new patient record b. search record c. Deletea record d. Print all records e. Exit Enter yo

Actual file content:

ranesh@rameshk:-/Music/cpp/patients cat Patient.txt 1002 Rumi K #34, Neol, Ave 30-11-1992 F 1003 Abu Sk #54.Mark. Ave 04-06-1

Add a comment
Know the answer?
Add Answer to:
C++ program Write a C++ program to manage a hospital system, the system mainly uses file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • C++ developing involves ut from a file a person's first name, last name, phone number and...

    C++ developing involves ut from a file a person's first name, last name, phone number and birth a menu driven database application. You need to 4) This program accept as input ogram will be menu driven with the following options: 1) Find a person's information 2) Add a person to the database 3) Edit a person's information 4) Display all records to the screen 5) Quit Option 1 allows the user to enter a name after which you will search...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the syste...

    Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check the validity of this user-id and password to verify that this is a legitimate user. Because this validation must be done many times each day, it is necessary to structure this information in...

  • Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sale...

    Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Customer Accounts This program should be designed and written by a team of students. Here are...

    Customer Accounts This program should be designed and written by a team of students. Here are some suggestions: Write a program that uses a structure to store the following information about a customer account: • Name • Address • City, state, and ZIP • Telephone number • Account balance • Date of last payment The structure should be used to store customer account records in a file. The program should have a menu that lets the user perform the following...

  • Phase one implementation: 1-The menu of selections implemented in main function. 2- Each choice should be...

    Phase one implementation: 1-The menu of selections implemented in main function. 2- Each choice should be implemented in the main function. 3- The data is saved permanently in a file. Problem Description: Assume one of the companies in Qatar who is renting flats for people asks you to develop a small system to help them track who paid the rent fees, and who did not for the coming month. The data in this system includes: ID number of the person...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT