C++ Assignment Document (APIIT)
C++ Assignment Document (APIIT)
C++ Assignment Document (APIIT)
Submitted by
Submitted to
Module Code
CE00314-2
Intake Code
HF09B1COM
Assignment Title
Individual Assignment
Due Date
I’m very grateful for his guidance and the manner he helped me with the encountered
problems.
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
of the code. ................................................................................................................... 26
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
7 Reference .............................................................................................................. 38
List of Figure
List of Table
Table 1: Test Plan ......................................................................................................... 31
1 Description and Justification on Design
To design the proposed system there are several classes been used, there are
Login Diagnosis
User DiagnosisControl
Administrator MedicalBill
Doctor MedicalBill Control
Nurse MedicalExpences
Patient Menu
AdministratorControl Validation
DoctorControl Settings
NurseControl FileHandler
PatientControl
1.1 Class Diagram
Login
#UserName : char
#Password : char
-changePassword() : int
-setPassword(in psw : char = "123")
+login()
+getPassword() : char
User
-val : Validation
-log : Login
-name : char
-NIC : char
-gender : char
-DOB : char
-joinedDate : char
-nationality : char
-status : char
+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
«inherits»
«inherits»
«inherits» «inherits»
-End41 -End35
1 1
0..1 -mb
-End20 * -End33 1
* -docc -End28 *
MedicalExpences
Diagnosis -checkUpCost : int MedicalBill Validation
-name : char -medicineCost : int -ID : int 1
+ID : int -totalCost : int 1 -mm : MedicalExpences * 1
1 1..* 1..* +readInteger() : int
+IDGenerator : int -diagnosisName : char -total : float
+status : char -friend class Doctor -End37 +isDateValid(in : char) : bool
-status : char
-menuClass : Menu +invalidInputError() : void
-me -dig
-End6 +setCost() : void -mb -me -val : Validation -End32 -End31
-fp : FileHandler +modifyCost() : void -fh : FileHandler
+Diagnosis() 1 1 DiagnosisControl +getCost() : void +MedicalBill()
+~Diagnosis() * +resetCost() : void +MedicalBill(in : int, in : int, in : int) : void
-menuClass : Menu
+displayAllData(in : bool) : void +MedicalExpences() +displayAllData() : void
-fh : FileHandler
+displaySingleData() : void -dg -digc +displaySingleData(in : bool) : void
+setData(in : bool) : void +addDiagnosis() : void
MedicalBillControl +setData() : void
+getID() : int +displayDiagnosis() : void 1 1
-End24 +calculateFinalTotal() : float
+setID(in : int) : void +viewAllDiagnosiss(in : Diagnosis) : void -menuClass : Menu +setStatus(in : char) : void
+getName() : char +deleteDiagnosis() : void -fp : FileHandler
-mbc +setID() : void 1 -End39
+setName(in * : char) : void +editDiagnosis() : void +addAllExpencesToAPatient() : void -mb
* +getStatus() : char
+getStatus() : char +setStatus(in : int) : void
+setStatus(in : char) : void +editOneByOne() : void
-End4 *
-End18 *
+editOneByOne() : void -End16 *
-End8 *
-End2 *
-End10 *
-End11 1 -End13 1
-End3 1
-End1 1
FileHandler
-val -End5
-friend class AdministratorControl
+viewAllDataFromFile(in myDataType) : void 1
+searchANDEditDataFromFile(in myDataType) : void -End7
+viewSingleDataFromFile(in myDataType) : void
+viewSingleDataFromFile(in myDataType) : void
+addNewRecordToFile(in myDataType) : void 1 -End9
+IDGenerator(in myDataType) : void
+deleteRecordFromFile(in myDataType) : void
+modifyRecordsInFile(in myDataType) : void 1
-End19 1
+getLoginDetails(in myDataType) : void -End17 1 -End15 1
Menu
-End27
1 -setting
+title(in * : char)
+userLevelMenu() : int 1
-End21 +mainMenu(in : int) : int
1 +patientMainMenu() : int -End29
+firstCommomSubMenu(in * : char) : int
+diagnosisHandlingFirstMenu(in * : char) : int
-End23 1
1 +costHandlingFirstMenu(in * : char) : int
+medicalBillMenu(in * : char) : int
+SearchOptionMenu(in * : char) : int
-End25 +doctorMainMenu() : int
+nurseMainMenu() : int
+exit() : char
PDF file and a JPEG image is been provided separately for class diagram.
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.
Final Total:
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 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;
return option;
}
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.
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.
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
the line of codes and reduce the necessary memory allocation of the program.
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
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.
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.
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.
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
myObject.displaySingleData();
break;
}
}
file.clear();
}
Figure 8: View Single Data from File - Method 2
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.
This kind of operations has been used in the program in many places.
2.1.4 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;
}
}
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;
}
}
Figure 12: Constructor 2 – MedicalBill
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.
2.2.1 Templates
Admin.text
Doctor. text
Doctor
Admin Nurse. text
Patient
Nurse Admin.text
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();
}
};
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,
by using the templates it increase the reusability of the code.
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.
//code
}
Figure 16: mainMenuHandler Declaration
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
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.
This provides the many option to the user by using same code and same function
definition.
2.2.4 Const Argument Passing
By using const argument passing user can not modify the variables or the
method.
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.
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,
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.
char *charPtr;
int count=1;
int isDateValid=0;
int number=0;
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);
}
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
do{
cout << "\n\tCheckUp Cost): ";
MedicalBillobjectArray[i].checkUpCost = val.validateInteger();
}
while(!((MedicalBillobjectArray[i].checkUpCost>=0) &&
(MedicalBillobjectArray[i].checkUpCost<=10000))) ;
}
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.
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.
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.
Main
Test Event Expected Output Actual Output
Event
Display message “Welcome
Enter correct Username Display message “Welcome
”
and password to the System”
Display message “Invalid
Enter incorrect Username Display message “Invalid
Login User Name or Password”
and password User Name or Password”
Display message “You
Enter password more than Display message “You
cannot log to the system”
5 times cannot log to the system”
Display message “Incorrect
NIC contain less than 10 Display message “Incorrect
Input ”
digits Input ”
Display message “Incorrect
Display message “Incorrect
Invalid Character to gender Input ”
Input ”
Display message “Incorrect
Display message “Invalid
Invalid date of birth Input ”
Date Format ”
Display message
Display message
Passwords are mismatch “Password mismatch ”
Add “Password mismatch ”
Patient Display message “You do
Display message “You do
Nurse try to add a Patient not have permission ”
not have permission ”
Display message “You do
Display message “You do
Nurse try to add a Doctor not have permission ”
not have permission ”
Correct search option Direct to the search menu. Direct to the search menu.
Nurse try to add a nurse No option to add them No option to add them
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.
Patient pays the bill before they left the department.
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