Report Oop 1
Report Oop 1
CONTENT PAGES
1.0 INTRODUCTION 2
3.0 APPLICATION
1
1.0 INTRODUCTION
2
2.0 CLASS EXPLANATION
‘Patient’ Class :
‘VaccinationProcess’ Class:
Other Functions:
3
3.0 EXPLANATION OF APPLICATION
3.0.1 FLOWCHART
START
Menu Display
Case 1
Case 2
Loop (Return to
Menu)
Case 3
User Chooses 6
(Exit Program)
Case 4
END
Case 6
4
3.0.2 CLASS DIAGRAM
Patient VaccinationProcess
+saveRegisteredData() : void
+loadRegisteredData() : void
5
3.0.3 SOURCE ARRANGEMENT
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
class Patient {
protected:
string name;
int age;
string vaccineType;
string phoneNumber;
string icNumber;
string homeAddress;
string gender;
public:
Patient(const string& n, int a, const string& v, const string& phone, const string& ic,
const string& address, const string& g)
: name(n), age(a), vaccineType(v), phoneNumber(phone), icNumber(ic),
homeAddress(address), gender(g) {
cout << "\nPatient registered.\n";
}
~Patient() {
cout << "\nPatient removed from the system.\n";
}
6
string getGender() const {
return gender;
}
class VaccinationProcess {
private:
int totalVialsPfizer;
int totalVialsSinovac;
int totalVialsAstraZeneca;
vector<Patient*> preRegisteredPatients;
vector<Patient*> newRegistrations;
public:
VaccinationProcess()
: totalVialsPfizer(0), totalVialsSinovac(0), totalVialsAstraZeneca(0) {
loadRegisteredData();
}
~VaccinationProcess() {
saveRegisteredData();
7
cout << " " << patientName << " is not pre-registered patient.\n";
return false;
}
void verifyDocuments() {
cout << "\nVerifying documents for pre-registered patients...\n";
string patientName;
cout << "\nEnter patient name for verification: \n";
cin.ignore();
getline(cin, patientName);
if (verifyPreRegisteredPatient(patientName)) {
cout << "Verification SUCCESSFULL for patient " << patientName << ".\n";
// Add patient to new registrations
for (const Patient* p : preRegisteredPatients) {
if (p->getName() == patientName) {
newRegistrations.push_back(new Patient(*p));
break;
}
}
} else {
cout << "Verification FAILED for patient " << patientName << ". Patient not
found.\n";
}
}
void performVaccination() {
verifyDocuments();
displayVaccinatedPatients();
cout << "Total Pfizer vials consumed: " << totalVialsPfizer << "\n";
cout << "Total Sinovac vials consumed: " << totalVialsSinovac << "\n";
cout << "Total AstraZeneca vials consumed: " << totalVialsAstraZeneca << "\n";
}
8
const string& phoneNumber, const string& icNumber,
const string& homeAddress, const string& gender) {
Patient* preRegisteredPatient = new Patient(name, age, vaccineType,
phoneNumber, icNumber, homeAddress, gender);
preRegisteredPatients.push_back(preRegisteredPatient);
}
9
void loadRegisteredData() {
ifstream inFile("vaccination_data.txt");
if (inFile.is_open()) {
string name, age, vaccineType, phoneNumber, icNumber, homeAddress, gender;
while (getline(inFile, name, ',')) {
getline(inFile, age, ',');
getline(inFile, vaccineType, ',');
getline(inFile, phoneNumber, ',');
getline(inFile, icNumber, ',');
getline(inFile, homeAddress, ',');
getline(inFile, gender, '\n');
} else {
cout << "\nNo existing data file found.\n";
}
}
};
10
cin >> icNumber;
11
void viewStatistics(const VaccinationProcess& vaccinationProcess) {
displayStatistics(vaccinationProcess);
}
void displayMenu() {
cout << "\n===== VACCINE REGISTRATION SYSTEM =====\n";
cout << "\n1. Register Pre-Registered Patient\n";
cout << "\n2. Register New Patient\n";
cout << "\n3. Perform Vaccination\n";
cout << "\n4. View Total Number of Patients\n";
cout << "\n5. View Real-time Statistics\n";
cout << "\n6. Exit\n";
cout << "=======================================\n";
}
int getMenuChoice() {
int choice;
cout << "\nEnter your choice (1-6): ";
cin >> choice;
return choice;
}
int main() {
VaccinationProcess vaccinationProcess;
do {
displayMenu();
int choice = getMenuChoice();
processMenuChoice(choice, vaccinationProcess);
12
// Break out of the loop if the user chose option 6
if (choice == 6) {
break;
}
} while (true);
return 0;
}
• Dynamic memory allocation is employed for patient objects using new in the
‘VaccinationProcess’ class, and memory is properly deallocated in the destructor.
Inheritance and Polymorphism:
• The use of inheritance is not explicitly present in the current code, but there is
potential for extending classes and leveraging polymorphism.
File I/O:
• File I/O operations are implemented for saving and loading patient data,
demonstrating persistence and data management.
Encapsulation:
• Data members in the Patient class are encapsulated with private access modifiers,
ensuring controlled access to class properties.
User Input Handling:
• User input is appropriately handled using cin and ‘getline’, considering potential
issues with input buffer.
13
Error Handling:
• Some basic error handling is present, such as checking if the file is open during data
loading and providing feedback for invalid user choices.
Code Reusability:
• Functions are used to perform specific tasks, promoting code reusability and
maintainability.
Real-time Statistics Display:
• The menu-driven user interface is clear and user-friendly, making it easy for users to
interact with the program.
Resource Management:
• Patient data is saved to a file, allowing for the persistence of information between
program executions.
Flexibility:
• The code structure allows for easy addition of new features or modifications to
existing functionality.
4.0.2 UNIQUENNESS:
Patient Class:
• The code employs dynamic memory allocation for patient objects using new to create
instances dynamically. It also ensures proper memory deallocation using delete in
the destructor to prevent memory leaks.
14
VaccinationProcess Class:
Persistence of Data:
• The code demonstrates the persistence of patient data by saving and loading
information from a file (vaccination_data.txt). This ensures that patient records are
retained across program executions.
• The system includes a patient verification process, allowing the identification of pre-
registered patients and their subsequent registration for vaccination. It also supports
the registration of entirely new patients.
Real-Time Statistics:
• The system provides real-time statistics, displaying the total number of patients and
the consumption of Pfizer, Sinovac, and AstraZeneca vials.
Input Handling:
• The code incorporates proper input handling, utilizing ‘getline’ to handle string inputs
and ‘cin.ignore()’ to clear the input buffer when needed.
• The menu and choice processing functions are well-structured, offering a clear and
organized way for users to interact with the system.
• Although not explicitly highlighted, the code structure supports potential future
extensions with polymorphism and inheritance, as the Patient class can be further
extended to accommodate different types of patients or additional functionalities.
OUTPUT
15
16
17
18