Add the cpp files for Assignment 4.
This commit is contained in:
parent
94ac292f32
commit
cfcce88ebc
4 changed files with 345 additions and 0 deletions
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
Program Name: Medical Records
|
||||
Process: Design a generalized template class named MedicalRecord - a data
|
||||
structure for managing patient medical information.
|
||||
Function Input/Parameters: ???
|
||||
Function Output/Parameters: ???
|
||||
Function Output/Returned: ???
|
||||
Device Input/Device: ???
|
||||
Device Output/Monitor: ???
|
||||
Dependencies: ???
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// class definitions
|
||||
template <class T>
|
||||
class MedicalRecord
|
||||
{
|
||||
private:
|
||||
T *arr;
|
||||
int arraySize;
|
||||
public:
|
||||
MedicalRecord()
|
||||
{
|
||||
//
|
||||
arr = NULL;
|
||||
arraySize = 0;
|
||||
}
|
||||
MedicalRecord(int size)
|
||||
{
|
||||
//
|
||||
arr = new T[size];
|
||||
arraySize = size;
|
||||
}
|
||||
MedicalRecord(int size, T newArray[])
|
||||
{
|
||||
arraySize = size;
|
||||
arr = new T[size];
|
||||
for(int copyIterator = 0; copyIterator < size; copyIterator++)
|
||||
{
|
||||
arr[copyIterator] = newArray[copyIterator];
|
||||
}
|
||||
}
|
||||
// MedicalRecord(const MedicalRecord &rec)
|
||||
// {
|
||||
// //
|
||||
// MedicalRecord(rec.arraySize, rec.arr);
|
||||
// }
|
||||
~MedicalRecord()
|
||||
{
|
||||
// for(int deleteIterator = 0; deleteIterator < arraySize; deleteIterator++)
|
||||
// {
|
||||
// delete arr[deleteIterator];
|
||||
// }
|
||||
delete arr;
|
||||
arr = NULL;
|
||||
arraySize = 0;
|
||||
}
|
||||
// accessor methods
|
||||
int getNumberPatients()
|
||||
{
|
||||
return arraySize;
|
||||
}
|
||||
T getPatientAt(int pos)
|
||||
{
|
||||
if(pos < arraySize)
|
||||
{
|
||||
if(pos > arraySize)
|
||||
{
|
||||
//
|
||||
return arr[pos];
|
||||
}
|
||||
}
|
||||
}
|
||||
// mutator methods
|
||||
// operator overloads
|
||||
T &operator[](size_t arrSize)
|
||||
{
|
||||
return arr[arrSize];
|
||||
}
|
||||
// const T &operator[](size_t arrSize)
|
||||
// {
|
||||
// return const arr[arrSize];
|
||||
// }
|
||||
};
|
||||
|
||||
// function definitions
|
||||
|
||||
// main function
|
||||
int main()
|
||||
{
|
||||
bool exitValue = false;
|
||||
int numRecords = 0;
|
||||
int currentRecord = 0;
|
||||
int inputRecord = 0;
|
||||
// string details
|
||||
string fullString = "";
|
||||
string patName = "";
|
||||
int patAge = 0;
|
||||
string patDetails = "";
|
||||
// ask user for number of records
|
||||
cout << "Please enter number of records: ";
|
||||
cin >> numRecords;
|
||||
cin.ignore();
|
||||
cout << endl;
|
||||
// create the medical records object
|
||||
MedicalRecord<string> record(numRecords);
|
||||
// create the display medical record object.
|
||||
while (!exitValue || currentRecord != numRecords)
|
||||
{
|
||||
// ask the user for the relevant information.
|
||||
cout << "Please enter patient name: ";
|
||||
cin >> patName;
|
||||
cout << endl;
|
||||
cout << "Please enter patient age: ";
|
||||
cin >> patAge;
|
||||
cout << "Please enter patient details: ";
|
||||
cin >> patDetails;
|
||||
cout << endl;
|
||||
|
||||
// assign fullString to the record[currentRecord].
|
||||
fullString = patName + " " + to_string(patAge) + " " + patDetails;
|
||||
record[currentRecord] = fullString;
|
||||
|
||||
// ask for index to get data out of array using record[inputIndex]
|
||||
cout << "Enter index to access record: ";
|
||||
cin >> inputRecord;
|
||||
|
||||
// copy data from record to display, then access data and output using display[currentRecord]
|
||||
string *tempArray = new string[record.getNumberPatients()];
|
||||
for(int copyString = 0; copyString < record.getNumberPatients(); copyString++)
|
||||
{
|
||||
tempArray[copyString] = record.getPatientAt(copyString);
|
||||
}
|
||||
MedicalRecord<string> display(numRecords, tempArray);
|
||||
|
||||
// erase the patient details after moving into string.
|
||||
fullString = "";
|
||||
patName = "";
|
||||
patAge = 0;
|
||||
patDetails = "";
|
||||
// increment the current record
|
||||
currentRecord = currentRecord + 1;
|
||||
// ask user if they want to continue.
|
||||
// if no, then set the exitValue to true.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue