Implement the void function \"WriteFile\" that will have two parameters: an outp
ID: 3795471 • Letter: I
Question
Implement the void function "WriteFile" that will have two parameters: an output file stream called "out", and a patient medical record called "patient record". The function will write the room number (integer), age (integer), and hospital wing (string: north south, east or west), from the patient record to the data file. Assume that the output file stream is already open. Consider the following patient record declaration when answering this question: class patient_record {public: int room_number, age; string hospital_wing;};Explanation / Answer
#include <fstream>
#include <iostream>
using namespace std;
class Patient {
String Hospital_wing; //{North,South,East,West};
int room_num,age;
// open a file in write mode.
ofstream outfile;
outfile.open("patient.dat");
cout << "Writing to the file" << endl;
cout << "Enter patient name: ";
cin.getline(data, 100);
// write inputted data into the file.
outfile << data << endl;
cout << "Enter your age: ";
cin >> data;
cin.ignore();
// again write inputted data into the file.
outfile << data << endl;
cout << "Enter hospital wing: ";
cin.getline(data, 10);
// close the opened file.
outfile.close();
// open a file in read mode.
ifstream infile;
infile.open("afile.dat");
cout << "Reading from the file" << endl;
infile >> data;
// write the data at the screen.
cout << data << endl;
// again read the data from the file and display it.
infile >> data;
cout << data << endl;
// close the opened file.
infile.close();
return 0;
}