Further Programming Concepts in C++
Submitted by
Tharanga Chandrasekara (CB002976)Submitted to
Mr. Udesh AmarasingheModule Code
CE00314-2Intake Code
HF09B1COMAssignment Title
Individual AssignmentDue Date
2nd November 2010Acknowledgements
I would like to extend my gratitude to those who helped me in completing the individual assignment for the module further Programming Concepts in C++.
I would like to express my appreciation and thankfulness to my Further Programming Concepts in C++ module Lecturer Mr. Udesh Amarasinghefor giving me the guidelines towards the successfulness of this project. His expertise on concepts of programming helped me to complete the assignment in the given timeframe.
I’m very grateful for his guidance and the manner he helped me with the encountered problems.
Finally, I would like to thank my institute, Asia Pacific Institute of Information Technology, for providing me the necessary laboratory and library facilities.
Abstract
This project is an individual assignment in the module Further Programming Concepts in C++ for the HF09B1SE.
Main aim if this project is to design a consol system to a clinic center by using C++ and object oriented concepts.
There are four main types of users in this system. They are Administrator, Doctor, Nurse and Patient. Each user has its own access capabilities to the system.
Table of Contents
Acknowledgements ... 1
Abstract ... 3
List of Figure ... 6
List of Table ... 6
1 Description and Justification on Design ... 7
1.1 Class Diagram ... 8
1.2 Class diagram Description ... 9
1.3 Object arrays ... 10
1.4 Menus ... 11
1.4.1 Dynamically changing menus ... 12
1.5 File handler Class ... 13
1.6 Settings Class ... 14
1.7 Validation Class ... 14
2 Description and justification on implementation code in terms of object oriented programming concepts. ... 15
2.1 Object Oriented Concepts used in the program ... 15
2.1.1 Inheritance ... 16
2.1.2 Encapsulation ... 17
2.1.3 Polymorphism ... 19
2.1.4 Constructors ... 20
2.1.5 Static and const variable... 21
2.2 C++ Concepts Used ... 22
2.2.1 Templates ... 22
2.2.2 Pass by Reference ... 23
2.2.3 Argument Passing ... 24
2.2.4 Const Argument Passing ... 25
2.2.5 Inline Functions ... 25 3 Description and Justification of the Validation codes applied into the implementation
3.1 Validate Integer (only take integer as a user input) ... 26
3.2 Date Validation ... 27
3.3 NIC validation ... 28
3.4 Cost Validation ... 29
3.5 File Open Validation ... 30
4 Description and justification on Test Plans and results. ... 31
5 Assumptions and Limitations ... 36
5.1 Limitations ... 36
5.2 Assumptions... 36
6 Conclusion ... 37
List of Figure
Figure 1: Class Diagram ... 8
Figure 2: Illustration of the Object Array ... 10
Figure 3: Code Sample for dynamically changing menus ... 12
Figure 4: Inheritance in the Program (Part of the Class Diagram) ... 16
Figure 5 : Illustration of Login Access... 17
Figure 6: Illustration of Doctor and DoctorControl Classes Access Contro ... 18
Figure 7: View Single Data from File - Method 1 ... 19
Figure 8: View Single Data from File - Method 2 ... 19
Figure 9: Method signature of viewSingleDataFromFile ... 20
Figure 10: Method signature of viewSingleDataFromFile ... 20
Figure 11: Constructor 1 – MedicalBill... 20
Figure 12: Constructor 2 – MedicalBill... 20
Figure 13: Example to Static and const variable ... 21
Figure 14: getLoginDetails method Template ... 22
Figure 15: Calling the mainMenuHandler method ... 23
Figure 16: mainMenuHandler Declaration ... 23
Figure 17: MedicalBill Method in MedicalBill Class ... 24
Figure 18: Parameters of MedicalBill Method ... 24
Figure 19: Const Argument Passing... 25
Figure 20: Inline Function ... 25
Figure 21: validateInteger function ... 26
Figure 22: Error message in validateIneger function ... 26
Figure 23: isValidDate Function ... 27
Figure 24: setNIC function ... 28
Figure 25: File Open Validation Function ... 30
Figure 26 : Error message of File Open validation ... 30
List of Table
Table 1: Test Plan ... 311 Description and Justification on Design
To design the proposed system there are several classes been used, there are
Login User Administrator Doctor Nurse Patient AdministratorControl DoctorControl NurseControl PatientControl Diagnosis DiagnosisControl MedicalBill MedicalBill Control MedicalExpences Menu Validation Settings FileHandler
1.1 Class Diagram
-changePassword() : int -setPassword(in psw : char = "123") +login() +getPassword() : char #UserName : char #Password : char Login +getName() : char +getNIC() : char +getGender() : char +gedDOB() : char +getJoineddate() : char +getNationality() : char +getStatus() : char +setName() : void +setNIC() : void +setGender() : void +setDOB() : void +setJoinedDate() : void +setNationality() : void +setStatus() : void -val : Validation -log : Login -name : char -NIC : char -gender : char -DOB : char -joinedDate : char -nationality : char -status : char User +displaySingleData() : void +displayAllData(in : bool) : void +setData(in : bool) : void +getID() : int +setID() : void +editOneByOne() +Nurse() +~Nurse() -digc : DiagnosisControl -pc : PatientControl -mbc : MedicalBillControl -nsc : NurseControl -IDGenerator : int -ID : int Nurse +displaySingleData() : void +displayAllData(in : bool) : void +setData(in : bool) : void +getSpecialArea() : char +setSpecialArea() : void -dc : DoctorControl -digc : DiagnosisControl -pc : PatientControl -mbc : MedicalBillControl -IDGenerator : int -ID : int -currentDiagnosis : char -SpecialArea : char Doctor+displayAllData(in : bool) : void +displaySingleData() : void +setData(in : bool) : void +getID() : int +setID(in : bool) : void +editOneByOne() : void +Patient() +~Patient() -val : Validation -menuClass : Menu -fh : FileHandler -Alergy : char -IDGenerator : int -ID : int Patient +readInteger() : int +isDateValid(in : char) : bool +invalidInputError() : void
Validation
+title(in * : char) +userLevelMenu() : int +mainMenu(in : int) : int +patientMainMenu() : int +firstCommomSubMenu(in * : char) : int +diagnosisHandlingFirstMenu(in * : char) : int +costHandlingFirstMenu(in * : char) : int +medicalBillMenu(in * : char) : int +SearchOptionMenu(in * : char) : int +doctorMainMenu() : int +nurseMainMenu() : int +exit() : char -setting
Menu
+viewAllDataFromFile(in myDataType) : void +searchANDEditDataFromFile(in myDataType) : void +viewSingleDataFromFile(in myDataType) : void +viewSingleDataFromFile(in myDataType) : void +addNewRecordToFile(in myDataType) : void +IDGenerator(in myDataType) : void +deleteRecordFromFile(in myDataType) : void +modifyRecordsInFile(in myDataType) : void +getLoginDetails(in myDataType) : void -val
-friend class AdministratorControl
FileHandler
+mainMenuHandler(in : int, in : Administrator) : int -friend class Administrator
-menuClass : Menu -val : Validation AdministratorControl +setCost() : void +modifyCost() : void +getCost() : void +resetCost() : void +MedicalExpences() -checkUpCost : int -medicineCost : int -totalCost : int -diagnosisName : char -friend class Doctor
MedicalExpences
+addDiagnosis() : void +displayDiagnosis() : void +viewAllDiagnosiss(in : Diagnosis) : void +deleteDiagnosis() : void +editDiagnosis() : void -menuClass : Menu -fh : FileHandler DiagnosisControl +Diagnosis() +~Diagnosis() +displayAllData(in : bool) : void +displaySingleData() : void +setData(in : bool) : void +getID() : int +setID(in : int) : void +getName() : char +setName(in * : char) : void +getStatus() : char +setStatus(in : char) : void +editOneByOne() : void -name : char +ID : int +IDGenerator : int +status : char -menuClass : Menu -fp : FileHandler Diagnosis
+mainMenuHandler(in : Doctor) : int +addDoctor() : void +searchDoctor(in : Doctor) : int +viewAllDoctor(in : Doctor) : void -friend class Doctor -menuClass : Menu -val : Validation DoctorControl +addAllExpencesToAPatient() : void -menuClass : Menu -fp : FileHandler MedicalBillControl +addNurse() +searchNurse(in : Nurse) : int +viewAllNurse(in : Nurse) : void -friend class Nurse -menuClass : Menu -val : Validation
NurseControl
+MedicalBill()
+MedicalBill(in : int, in : int, in : int) : void +displayAllData() : void
+displaySingleData(in : bool) : void +setData() : void +calculateFinalTotal() : float +setStatus(in : char) : void +setID() : void +getStatus() : char +setStatus(in : int) : void +editOneByOne() : void -ID : int -mm : MedicalExpences -total : float -status : char -val : Validation -fh : FileHandler MedicalBill +addPatient() : void +viewSinglePatient(in : Patient) : void +viewAllPatient(in : Patient) : void +editPatient(in : Patient) : void +searchPatient(in : Patient) : int +deletePatient(in : Patient) : void +viewMedicalBill(in : Patient) : void -menuClass : Menu -fh : FileHandler PatientControl «inherits» «inherits» «inherits» «inherits» -psc 1 -ps 1 -docc 1 -doc 1 -nsc 1 -ns 1 -adminc 1 -admin 1 -dig 1 -docc * -digc 1 -dg 1 -ps 1 -mb 0..1 -me 1 -mb 1..* -dig 1..* -me 1 -mbc 1 -mb 1 +displaySingleData() : void
+displayAllData(in : bool) : void +setData() : void +ac : AdministratorControl +dc : DoctorControl +nsc : NurseControl +pc : PatientControl +mbc : MedicalBillControl +digc : DiagnosisControl +IDGenerator : int +ID : int Administrator -End1 1 -End2 * -End3 1 -End4 * -End5 1 -End6 * -End7 1 -End8 * -End9 1 -End10 * -End11 1 -End12 * -End13 1 -End14 * -End15 1 -End16 * -End17 1 -End18 * -End19 1 -End20 * -End21 1 -End22 * -End23 1 -End24 * -End25 1 -End26 * -End27 1 -End28 * -End29 1 -End30 * -End31 1 -End32 * -End33 1 -End34 * -End35 1 -End36 * -End37 1 -End38 * -End39 1 -End40 * -End41 1 -End42 *
1.2 Class diagram Description
Administrator, Doctor, Nurse, Patient classes are inherits from the User class so that these classes share same attributes such as name, NIC, date of birth, gender, joined date, nationality due to the inheritance from a User class.
Classes like Administrator, Doctor, Nurse, Patient classes have their own add, edit, search, view and delete methods in separate classes. This has been implemented to achieve the user levels in the application and to give the necessary privilege to the relevant users. MedicalBill class also has its own control class to give the necessary privilege to the relevant users.
1.3 Object arrays
Object arrays been used in the Medical Bill Report. MedicalExpences object array of 3 been used to store the medical expenses of the each patient. This each object will hold diagnosis name, check up cost, medicine cost and total cost for each diagnosis. As a result of using this simple object array system can hold 9 different variable values so it makes the program more efficient and easy to program.
Following is the illustration of the used object array.
Checkup Cost Medicine cost Final Total
Checkup Cost Medicine cost Final Total
Checkup Cost Medicine cost Final Total
Diagnosis 1 Diagnosis 3 Diagnosis 2 Medical Bill Patient ID Final Total: Object Array
1.4 Menus
Menu class will handle main functions regarding the menus in the program. By using a separate class to handle the menus, will give a major advantage to the programmer and to the program. As an example many objects in the program will use the same menu class functions to fulfill the functions of their classes so it will reduce the number of code lines and increase the speed of the program due to that.
And also it is easy for a new programmer to understand the program and to make the modifications if it’s necessary in the future, since all the functions are implemented in a one place so it is easy to acquire a wider picture of menu functions rather than looked into several places of the program to find the menu handling in the program.
Each user will have their own separate special menus; this has been done to restrict the functionalities of the restricted users, who are not permitted to execute some special functions in the system such as,
Add a Doctor
Delete Doctor
Add Diagnosis
In some situations common sub menus will be used to every user so it will reduce the programming conflicts when it comes to implementation of the design.
1.4.1 Dynamically changing menus
Dynamically changing menus will also be used in common menus. These menus will change their functions and user interface according to the parameters which is passed to the menu function.
These menu functions will be a good implementation method because it reduces the time to program the separate menus and also helps the programmer to reduce the lines of codes and it will speed up the performance and the speed of the program.
As an example following menu will change its user interface according to the parameters which is passed to the menu function.
int Menu::firstCommomSubMenu(char * type){
int option; title(type);
cout << "\t 1. Add a new " << type << endl; cout << "\t 2. Search " << type << endl; cout << "\t 3. View All " << type << endl; cout << "\t 4. Main Menu" << endl;
cout << endl << "\t Enter option Number :"; cin >> option;
return option;
}
1.5 File handler Class
File handler class will handle all the functions regarding the files in the program. This class is completely responsible of handling the functions regarding the files.
By using a separate class to handle the functions of the used files, will give a major advantage to the programmer and to the program. As an example many objects in the program will use the same file hander class functions to fulfill the functions of their classes so it will reduce the number of code lines and increase the speed of the program due to that.
And also it is easy for a new person to understand the program and to make the modifications if it’s necessary in the future because all the functions are implemented in an one place so it is easy to acquire a wide picture of the file handler function rather than looked into several places in the program to find the file handling functions in the program.
1.6 Settings Class
Settings class will handle all the functions regarding the settings of the program.
1.7 Validation Class
Validation class will handle all the functions regarding the Validation of the program.
By using a separate class to handle the Validation, will give a major advantage to the programmer and to the program. As an example many objects in the program will use the same Validation class functions to fulfill the functions of their classes so it will reduce the number of code lines and increase the speed of the program due to that. And also it is easy for a new person to understand the program and to make the modifications if it’s necessary in the future because all the functions are implemented in an one place so it is easy to acquire a wide picture of the Validation function rather than looked into several places in the program to find the Validation functions in the program.
2 Description and justification on implementation code in
terms of object oriented programming concepts.
Object oriented concepts been used to implement the program; these object oriented concepts provide a very friendly environment to the programmer to program. Class is a blueprint of an object which holds the definition to the each object which has been instantiating.
Addition to these inheritances, Polymorphism and Encapsulation been used to program.
2.1 Object Oriented Concepts used in the program
There are 19 main classes in the program such a s Login,User,Administrater, Doctor,Nurse,Diagnosis,MedicalBill, FileHandler and etc. Each of these classes been used throughout the program by creating an object of them. This creation of the object is called as instantiating.
2.1.1 Inheritance
Figure 4: Inheritance in the Program (Part of the Class Diagram)
Following illustration clearly illustrate the main inheritance concepts used in the program.
Administrator, Doctor, Nurse, Patient classes are inherits from the User class so that these classes share same attributes such as name, NIC, date of birth, gender, joined date, nationality due to the inheritance from a User class. And also this will inherit the method of the User class to the Administrator, Doctor, Nurse, Patient classes.
By using the inheritance in this circumstance will allow the programmer to access the user classes via the Administrator, Doctor, Nurse, Patient classes. So this will reduce
2.1.2 Encapsulation
Encapsulation has been used throughout the program. This has achieved by using access specifies. Main access specifies are
Private
Protected
Public
2.1.2.1 Example 1 – Login Function
Login function is the most important function in this program because it will maintain the user levels for the program where each user will have different privileges to use the system. User Password is saved in the User object of the program using a character array and it is declared as a private variable so it cannot be access by other classes directly. Therefore to give access to the other relevant classes, public method called login () been used. So other classes can use this public method to access the User Password, because of this method users who are using the system will not know the functionality of the password and how it been kept in the system. User will only know that they can access the password by using the login ( ) method.
2.1.2.2 Example 2 – Doctor and DoctorControl Classes
All the controls regarding the doctors been saved is saved in the DoctorControl object of the program so other classes cannot access Doctor Class directly. Therefore to give access to the other relevant classes, public methods been used in the DoctorControl class. So other classes can use this public method in the DoctorControl class to access the Doctor Class, because of this users who are using the system will not know the functionality of the DoctorControl and Doctor Classes.
2.1.3 Polymorphism
Throughout the program Polymorphism concepts been used. There are main two types of polymorphism concepts in computer programming. Those concepts are,
Overloading
Overriding
2.1.3.1 Overloading
In the FileHandlin class there are two methods that have use the same method name, but the parameters pass to the function is different.
void viewSingleDataFromFile(myDataType& myObject,const char *filename){ fstream file;
file.open(filename,ios::in|ios::out|ios::ate|ios::binary); file.seekg(0,ios::beg);
cout<<"Reading from the file\n";
while(file.read((char*)&myObject,sizeof(myObject))) { if(myObject.status!='D'){ myObject.displaySingleData(); } } cin.get(); file.clear(); }
Figure 7: View Single Data from File - Method 1
void viewSingleDataFromFile(myDataType& myObject,const char *filename,int
searchID){
fstream file;
file.open(filename,ios::in|ios::out|ios::ate|ios::binary); file.seekg(0,ios::beg);
cout<<"Reading from the file\n";
while(file.read((char*)&myObject,sizeof(myObject))) { if((myObject.ID == searchID)&&(myObject.status!='D')){ myObject.displaySingleData(); break; } } file.clear(); }
As it shown in the above 2 illustrations, method names are similar to each other but the parameters been passed to the function is different.
First method use parameters as myDataType, const char *
void viewSingleDataFromFile(myDataType& myObject,const char *filename){
Figure 9: Method signature of viewSingleDataFromFile Second method use parameters as myDataType, const char *, int
void viewSingleDataFromFile(myDataType& myObject,const char *filename,int
searchID){
Figure 10: Method signature of viewSingleDataFromFile This kind of operations has been used in the program in many places. 2.1.4 Constructors
In the MedicalBill class; constructor is been overridden by using 2 different constructors.
MedicalBill::MedicalBill(){
for(int i=0;i<NO_OF_DIAGNOSISS;i++){
strcpy(MedicalBillobjectArray[i].diagnosisName,"Diagnosis"); MedicalBillobjectArray[i].checkUpCost = 0; MedicalBillobjectArray[i].medicineCost = 0; MedicalBillobjectArray[i].totalCost=0; } }
Figure 11: Constructor 1 – MedicalBill
MedicalBill::MedicalBill(int patientID,int m1,int m2){
ID = patientID;
for(int i=0;i<NO_OF_DIAGNOSISS;i++){
strcpy(MedicalBillobjectArray[i].diagnosisName,"Diagnosis"); MedicalBillobjectArray[i].checkUpCost = m1; MedicalBillobjectArray[i].medicineCost = m2; MedicalBillobjectArray[i].totalCost=m1+m2; } }
2.1.5 Static and const variable
In Administrator Class, Doctor Class, Nurse Class and Patient Class there is a separate ID Generator. When the program instantiate those class object, a unique ID to each class will be issued to the object. This has been achieved by using static variable called IDGenerator.
static int IDGenerator;
2.2 C++ Concepts Used
2.2.1 Templates
This template is used to get the login details form the files. In this designed system every user should login to the system in order to access the system. As it mention earlier in the documentation there are 4 types of users in the system. They are Admin, Doctor, Nurse and Patient, so each of these users should log to the system by using a function. To do that programmer has to write different functions to each user. But by using the template programmer can achieve all the functions in a one method by passing the relevant object to it.
There are many templates been used in this program, especially in file handler Class, because files have been used by each user and several files been used in the program,
Patient
template <typename myDataType>
void getLoginDetails(myDataType& myObject,const char *filename,int id){ myDataType temp;
fstream file; //stream for input AND output
file.open(filename,ios::in|ios::out|ios::ate|ios::binary); file.seekg(0,ios::beg);
while(file.read((char*)&myObject,sizeof(myObject))) { if((myObject.status!='D')&&(myObject.ID==id)) break; } file.clear(); } }; Doctor Nurse Admin Admin.text Doctor. text Nurse. text Admin.text
2.2.2 Pass by Reference
In the main of the program a Nurse object called “ns” been created if the user selected the user level as nurse. Nurse object (ns) will call the mainMenuuhandler method as shown in the following illustration.
ns.nsc .mainMenuHandler (setting.NURSE ,ns);
Figure 15: Calling the mainMenuHandler method
mainMenuHandler function requires a object of Nurse as shown in the below illustration. So that Nurse (ns) object has been passed to the function as a reference. It reduces the wastage of the memory since it only passes the reference of the object.
int NurseControl::mainMenuHandler(int userType,Nurse& ns){ //code
}
2.2.3 Argument Passing
Argument passing also used in several places in the program, best example to this is method of “calculateFinalTotal” in medical bill control.
MedicalBill::MedicalBill(int patientID,int cost1,int cost2){
ID = patientID;
for(int i=0;i<NO_OF_DIAGNOSISS;i++){
strcpy(MedicalBillobjectArray[i].diagnosisName,"Diagnosis"); MedicalBillobjectArray[i].checkUpCost = cost1; MedicalBillobjectArray[i].medicineCost = cost2; MedicalBillobjectArray[i].totalCost=cost1+cost2; } }
Figure 17: MedicalBill Method in MedicalBill Class
This function has 3 parameters as input parameters.
MedicalBill(int patientID,int cost1,int cost2)
Figure 18: Parameters of MedicalBill Method
In this function it is optional to pass the cost1 and cost2 values since those values been given the value of 0 in the start.
But by using this method programmer can call this method in 3 separate ways. Such as
MedicalBill(patientID);
MedicalBill(patientID,10);
MedicalBill(patientID,10,20);
In the first invoke of the method, both the cost will be assign to 0 since they have given a default vales as 0 in the start. In the seconf invoke of the method checkup cost will get instanciate as 10 and medicine cost will get the value of 0. But in the last invoke method where user pass both the values to the method, checkup cost will get the value of 10 while medicine cost get the 20 as its value.
2.2.4 Const Argument Passing
By using const argument passing user can not modify the variables or the method.
const char* getSpecialArea()const;
Figure 19: Const Argument Passing
2.2.5 Inline Functions
Following is a good example of using inline function, inline functions make program run faster according to the parashift.com(2010)
inline void Menu::title(char *title){
cout << "\n\t******************************************************"<< endl; cout << "\t\t\t\t"<<title << endl ;
cout << "\t******************************************************" << endl<< endl << endl;
}
Figure 20: Inline Function
In each form of the program there is a heading menu. Due to that this menu is called frequently in the program. To make the program faster and to increase the performance this menu is defined as an inline function.
3 Description and Justification of the Validation codes
applied into the implementation of the code.
To perform the validation in the program, especially when taking the inputs form the user separate validation class been created as Validation. This class provides various methods to validate the user inputs throughout the program. Addition to this validation class methods there are some places of the program which use other validation methods.
3.1 Validate Integer (only take integer as a user input)
Following is the code of validateInteger function,
int validateInteger(){ int intval; cin >> intval; while (cin.fail()) { cin.clear(); fflush(stdin);
cout << "\t\tERROR: You can only enter a integer"; cin >> intval;
}
return intval;
}
Figure 21: validateInteger function
By using this validation method programmer can limited the user input data only to integer. If the user input any character it will throw an error message as follow,
ERROR: You can only enter a integer
Figure 22: Error message in validateIneger function
Justification: if the user enters a character value to the cost of the medicine it will make a runtime error in the program. So to avoider the user to input character values to this function been used.
3.2 Date Validation
This method is been used to validate the date. User can only enter a date between the years of 1900-2011. If the user input a wrong date it will prompt the user. Following is the code for the date validation which is in Validation Class.
bool isValidDate(char *date){ // validate the date
char *charPtr;
int count=1;
int isDateValid=0;
int number=0;
charPtr = strtok( date, "-" );
while(charPtr != NULL){
if((count==1)&&(atoi(charPtr)>=1) && (atoi(charPtr)<=31)){ isDateValid++;
}else if((count==2)&&(atoi(charPtr)>=1) && (atoi(charPtr)<=12)){ isDateValid++;
}else if((count==3)&&(atoi(charPtr)>=1900) && (atoi(charPtr)<=2011)){ isDateValid++;
} count++;
charPtr = strtok( NULL, "-" ); }
return ((isDateValid==3)?true:false);
}
Figure 23: isValidDate Function
Justification: if the user enters a wrong format of date to the “date of join” and “date of born” it will make a runtime error in the program and also will not be able to get the correct data from the user. So to avoid the user to input wrong format of date this function been used. Because people normally do lots of errors when they manually input the date to a program.
3.3 NIC validation
This method is been used to validate the NIC number of the user. User can only enter a number which contain 10 digits. If the user input a wrong NIC number which does not contain 10 digits it will prompt the user. Following is the code for the NIC validation which is in USER Class.
void User::setNIC(){
int count=0;
char nic[12];
do{
cout << "\n\tEnter your NIC : "; cin >> nic; if(strlen(nic)==10){ strcpy(NIC,nic); break; }else{ val.invalidInputError(); cin.get(); } count++; }while(count<5); }
Figure 24: setNIC function
Justification: if the user enters a wrong format of NIC to the NIC number it will make a runtime error in the program and also will not be able to get the correct data from the user. And also in the system it provide the search facility by using user NIC number so it is necessary to avoid the user to input wrong format of NIC number to the program this function been used
3.4 Cost Validation
This method is been used to validate the cost. User can only enter a value between the 0-10000. If the user input a wrong value it will prompt the user. Following is
the code for the cost validation which is in Validation Class
Justification: if the user enters a wrong data to the cost it will make a runtime error in the program and also will not be able to get the correct bill for the patient. So to avoid the user to input wrong data to the system this function been used, since people normally do lots of errors when they manually values to the system it is always necessary to check the each and every input of the user.
do{
cout << "\n\tCheckUp Cost): ";
MedicalBillobjectArray[i].checkUpCost = val.validateInteger(); }
while(!((MedicalBillobjectArray[i].checkUpCost>=0) && (MedicalBillobjectArray[i].checkUpCost<=10000))) ;
3.5 File Open Validation
This function been used in the filehandler Class in order to validate the opening of the file. Following is the code for the file open validation which is in filehandler Class,
if ( !file) {
cout << "\a\n\tFile could not be opened." << endl; system("pause");
exit( 1 ); }
Figure 25: File Open Validation Function
By using this validation method programmer can limit the runtime errors in the program and same time can prompt the user. If the file is not available due to any reason program will prompt the user by showing the following message.
File could not be opened
Figure 26 : Error message of File Open validation
Justification: if the requested file is not available in the system, system should prompt the user, because file name been changed by someone manually. So it will make a bad impact on the runtime of the program. So it is necessary to promt the user about the missing or corrupted file.
4 Description and justification on Test Plans and results.
Table 1: Test Plan
Main
Event Test Event Expected Output Actual Output
Login
Enter correct Username and password
Display message “Welcome to the System”
Display message “Welcome ”
Enter incorrect Username and password
Display message “Invalid User Name or Password”
Display message “Invalid User Name or Password”
Enter password more than 5 times
Display message “You cannot log to the system”
Display message “You cannot log to the system”
Add Patient
NIC contain less than 10 digits
Display message “Incorrect Input ”
Display message “Incorrect Input ”
Invalid Character to gender Display message “Incorrect Input ”
Display message “Incorrect Input ”
Invalid date of birth Display message “Invalid Date Format ”
Display message “Incorrect Input ”
Passwords are mismatch Display message “Password mismatch ”
Display message “Password mismatch ”
Nurse try to add a Patient Display message “You do not have permission ”
Display message “You do not have permission ”
Nurse try to add a Doctor Display message “You do not have permission ”
Display message “You do not have permission ”
Invalid date to Join date Display message “Invalid Date Format ” Display message “Invalid Date Format ”
Successfully add a patient Display message “Successfully added ”
Redirect the user to diagnosis menu.
Medical Bill
Examine cost less than 0 and more than 10000
Display message “Incorrect Input ”
Prompt user to enter expense again
Medical cost less than 0 and more than 10000
Display message “Incorrect Input ”
Prompt user to enter expense again
Examine cost input as a character
Display message “Error : Enter an Integer value”
Display message “Error : Enter an Integer value”
character Enter an Integer value” Enter an Integer value”
Menu
Invalid input to a menu
Display message “Invalid option, You don’t have the permission to access ”
Display message “Invalid option, You don’t have the permission to access ”
Invalid input to a menu
Display message “Invalid option, You don’t have the
permission to access ” Return to the main menu. Valid input to a menu Direct to the function. Direct to the function.
Search Patient
Invalid search option Display message “Incorrect Input ”
Display message “Incorrect Option” and direct to the main menu.
Correct search option Direct to the search menu. Direct to the search menu. Invalid ID to search by ID
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Valid ID to search by ID Display the details of patient Display the details of patient Invalid name to search by
name
Display message “No records ” and direct to the search menu
Display message “No records ” and direct to the search menu
Valid name to search by name
Display the main details of patients who have similar names
Display the main details of patients who have similar names
Enter the ID after search Display the details of patient Display the details of patient
Invalid ID to search by NIC
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Valid ID to search by NIC Display the details of patient Display the details of patient
Search Doctor
Invalid search option Display message “Incorrect Input ”
Display message “Incorrect Option” and direct to the main menu.
Correct search option Direct to the search menu. Direct to the search menu. Invalid ID to search by ID
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Valid ID to search by ID Display the details of doctor Display the details of doctor Invalid name to search by
name
Display message “No records ” and direct to the search menu
Display message “No records ” and direct to the search menu
Valid name to search by name
Display the main details of doctors who have similar names
Display the main details of doctors who have similar names
Enter the ID after search Display the details of Doctors
Display the details of Doctors
Invalid ID to search by NIC
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Search Nurse
Invalid search option Display message “Incorrect Input ”
Display message “Incorrect Option” and direct to menu main menu.
Correct search option Direct to the search menu. Direct to the search menu.
Invalid ID to search by ID
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Valid ID to search by ID Display the details of Nurse Display the details of Nurse
Invalid name to search by name
Display message “No records ” and direct to the search menu
Display message “No records ” and direct to the search menu
Valid name to search by name
Display the main details of Nurse who have similar names
Display the main details of Nurse who have similar names
Enter the ID after search Display the details of Nurse Display the details of Nurse
Invalid ID to search by NIC
Display message “Incorrect Input ” and direct to the search menu
Display message “Incorrect Option” and direct to the main menu.
Valid ID to search by NIC Display the details of Nurses
Display the details of Nurses
Edit Doctor Details
Invalid edit option
Display message “Incorrect Input ” and direct to the search menu
Display message Incorrect Input ” and direct to the search menu
Valid edit option Direct to the edit menu Direct to the edit menu
Edit Nurse Details
Invalid edit option
Display message “Incorrect Input ” and direct to the search menu
Display message Incorrect Input ” and direct to the search menu
Valid edit option Direct to the edit menu Direct to the edit menu
Edit Patient Details
Invalid edit option
Display message “Incorrect Input ” and direct to the search menu
Display message Incorrect Input ” and direct to the search menu
Valid edit option Direct to the edit menu Direct to the edit menu
Edit All Details of
doctor
Invalid input Display message “Incorrect Input ” Display message “Incorrect Input ” Valid Input Direct to the all edit page Direct to the all edit page Edit All
Details of Nurse
Invalid input Display message “Incorrect Input ” Display message “Incorrect Input ” Valid Input Direct to the all edit page Direct to the all edit page
Edit All Details of
patient
Invalid input Display message “Incorrect Input ” Display message “Incorrect Input ”
Valid Input Direct to the all edit page Direct to the all edit page
Edit Doctor Details
Enter Invalid data Display message “Invalid Data” Display message “Invalid Data”
Enter Valid data Display message “Invalid Data” Display message “Invalid Data”
Edit Nurse Details
Enter Invalid data Display message “Invalid Data”
Display message “Invalid Data”
Enter Valid data Display message “Invalid Data” Display message “Invalid Data”
Edit Patient Details
Enter Invalid data Display message “Invalid Data” Display message “Invalid Data”
Enter Valid data Display message “Invalid Data” Display message “Invalid Data” Save
Doctor Details
Save Doctor Details
Display message “Data Modified” and direct to main menu
Display message “Data Modified” and direct to main menu
Save Nurse Details
Save Nurse Details
Display message “Data Modified” and direct to main menu
Display message “Data Modified” and direct to main menu
Save Patient Details
Save Patient Details
Display message “Data Modified” and direct to main menu
Display message “Data Modified” and direct to main menu
Delete Doctor Record
Delete Doctor Details
Display message “Data Deleted” and direct to main menu
Display message “Data Deleted” and direct to main menu
Delete Nurse Record
Delete Nurse Details
Display message “Data Deleted” and direct to main menu
Display message “Data Deleted” and direct to main menu
Delete Patient Record
Delete Patient Details
Display message “Data Deleted” and direct to main menu
Display message “Data Deleted” and direct to main menu
View medical
Bill
Invalid patient ID
Display message “Invalid Data” and redirect to the main menu
Display message “Invalid Data” and redirect to the main menu
Valid data ID Display the medial bill of the patient
Display the medial bill of the patient
Add Doctor
NIC contain less than 10 digits
Display message “Incorrect Input ”
Display message “Incorrect Input ”
Invalid date of birth Display message “Invalid Date Format ”
Display message “Incorrect Input ”
Passwords are mismatch Display message “Password mismatch ”
Display message “Password mismatch ” Nurse try to add a doctor No option to add them No option to add them Invalid date to Join date Display message “Invalid
Date Format ”
Display message “Invalid Date Format ”
Successfully add a doctor Display message “Successfully added ” Redirect the user to main menu.
Add Nurse
NIC contain less than 10 digits
Display message “Incorrect Input ”
Display message “Incorrect Input ”
Invalid Character to gender Display message “Incorrect Input ”
Display message “Incorrect Input ”
Invalid date of birth Display message “Invalid Date Format ”
Display message “Incorrect Input ”
Passwords are mismatch Display message “Password mismatch ”
Display message “Password mismatch ”
Nurse try to add a nurse No option to add them No option to add them
Invalid date to Join date Display message “Invalid Date Format ”
Display message “Invalid Date Format ”
Successfully add a doctor Display message “Successfully added ” Redirect the user to main menu. Add Diagnosis Successfully add a diagnosis Display message “Successfully added ”
Redirect the user to diagnosis menu.
Delete Diagnosis
Invalid diagnosis Number Display message “Invalid input ”
Display message “Invalid input ”
Valid diagnosis Number
Display message “Invalid diagnosis deleted ” and delete the diagnosis
Display message “Invalid diagnosis deleted ” and delete the diagnosis
Edit Diagnosis
Invalid diagnosis Number Display message “Invalid input ”
Display message “Invalid input ”
Valid diagnosis Number
Display message “Invalid diagnosis modified ” and modified the diagnosis
Display message “Data modified ” and modified the diagnosis
5 Assumptions and Limitations
There are several assumptions and limitations in the designed system.
5.1 Limitations
Only 3 diagnoses can be assigning to a patient at a one time.
Only one previous recode of a patient can be saved in the system.
Only one admin can added to the system.
Cost of the single medicine cannot be exceeding the limit of Rs.10000.
One doctor can only have one specialized area.
Patient can only have one bill at a time.
Nurse can only view the saved data in the system.
Doctor cannot add any new patient, doctor or nurse to the system.
System will not allow any user to change the logID.
5.2 Assumptions
Maximum of 3 diagnoses can be having to a patient at one given time.
Only one admin control the system.
System is installed in one computer.
Department will have sufficient IT people to handle the system.
Department have enough resource to implement the system.
Doctor will only have one specialized area.
System will not search patient; by allergy they have.
6 Conclusion
Main aim if this project is to design a consol system to a clinic center by using C++ and object oriented concepts.
There are four main types of users in this system. They are Administrator, Doctor, Nurse and Patient. Each user has its own access capabilities to the system. System will hold the data about all the users, addition to that system will hold the data about the diagnosis and the medical bills of the patients.
Text files been used to save the data of the system and data is been saved as an object, due to that it make easy for system to retrieve the data from the file.
By doing this assignment I have gain lot of knowledge regarding the C++ and object oriented concepts. I have used various C++ concepts in the program such as inline functions, templates and polymorphism. This assignment gave me a lot of experience and capability to apply the knowledge which I gain in the class room.
7 Reference
cplusplus.com, 2010, atoi, [Online], Available:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/ , [Accessed 2nd November 2010]
cplusplus.com, 2010, strtok, [Online], Available:
http://www.cplusplus.com/reference/clibrary/cstring/strtok/ , [Accessed 2nd November 2010]
Msdn, 2010, WINDOWS.H and STRICT Type Checking, [Online], Available: http://msdn.microsoft.com/en-us/library/aa271858(VS.60).aspx , [Accessed 2nd November 2010]
northseattle.edu,2010, northseattle.edu ,[Online], Available:
http://facweb.northseattle.edu/voffenba/class/CSC143-Resources/How%20to%20Draw%20a%20Class%20Diagram.pdf , [Accessed 2nd November 2010]