Sei sulla pagina 1di 38

Further Programming Concepts in C++

Submitted by

Tharanga Chandrasekara (CB002976)

Submitted to

Mr. Udesh Amarasinghe

Module Code

CE00314-2

Intake Code

HF09B1COM

Assignment Title

Individual Assignment

Due Date

2nd November 2010


Acknowledgements

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
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

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 ......................................................................................................... 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»

Doctor Administrator Patient Nurse


-dc : DoctorControl +ac : AdministratorControl -val : Validation -digc : DiagnosisControl
-digc : DiagnosisControl +dc : DoctorControl -menuClass : Menu * -pc : PatientControl
-pc : PatientControl +nsc : NurseControl -fh : FileHandler -mbc : MedicalBillControl
-mbc : MedicalBillControl +pc : PatientControl -Alergy : char -nsc : NurseControl
-IDGenerator : int +mbc : MedicalBillControl -IDGenerator : int -End36 -IDGenerator : int
-ID : int +digc : DiagnosisControl -ID : int -ID : int
-currentDiagnosis : char +IDGenerator : int +displayAllData(in : bool) : void +displaySingleData() : void
-SpecialArea : char +ID : int +displaySingleData() : void +displayAllData(in : bool) : void
+displaySingleData() : void +displaySingleData() : void -End14 +setData(in : bool) : void +setData(in : bool) : void
+displayAllData(in : bool) : void +displayAllData(in : bool) : void +getID() : int +getID() : int
+setData(in : bool) : void +setData() : void +setID(in : bool) : void +setID() : void
+getSpecialArea() : char * +editOneByOne() : void +editOneByOne()
+setSpecialArea() : void +Patient() +Nurse()
1 -adminc
+~Patient() +~Nurse()
1 -docc
1 -psc 1 -nsc
-End40 1 -ps

* 1 -doc 1 -admin 1 -ps 1 -ns


* -End42
DoctorControl AdministratorControl PatientControl NurseControl *
-friend class Doctor -friend class Administrator -menuClass : Menu -friend class Nurse *
-menuClass : Menu -menuClass : Menu -fh : FileHandler -menuClass : Menu -End34
-val : Validation -val : Validation +addPatient() : void -val : Validation
-End26 +mainMenuHandler(in : Doctor) : int +mainMenuHandler(in : int, in : Administrator) : int +viewSinglePatient(in : Patient) : void +addNurse() -End30
+addDoctor() : void +viewAllPatient(in : Patient) : void +searchNurse(in : Nurse) : int
-End12
+searchDoctor(in : Doctor) : int +editPatient(in : Patient) : void +viewAllNurse(in : Nurse) : void
* +viewAllDoctor(in : Doctor) : void +searchPatient(in : Patient) : int
-End22 *-End38 * +deletePatient(in : Patient) : void
* +viewMedicalBill(in : Patient) : void
1 -dig

-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

Figure 1: Class Diagram

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.

Following is the illustration of the used object array.

Patient ID Medical Bill

Diagnosis 1 Checkup Cost Medicine cost Final Total

Diagnosis 2 Checkup Cost Medicine cost Final Total


Object Array

Diagnosis 3 Checkup Cost Medicine cost Final Total

Final Total:

Figure 2: Illustration of the 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;
}

Figure 3: Code Sample for dynamically changing menus


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
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

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.

Figure 5 : Illustration of Login Access


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.

Figure 6: Illustration of Doctor and DoctorControl Classes Access Contro


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();
}
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.

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;
}
}
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.

static int IDGenerator;

Figure 13: Example to Static and const variable


2.2 C++ Concepts Used

2.2.1 Templates
Admin.text
Doctor. text
Doctor
Admin Nurse. text
Patient
Nurse Admin.text

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();
}
};

Figure 14: getLoginDetails method Template

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.

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

}
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

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.

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.

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

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.

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
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 ”

Display message “Invalid Display message “Invalid


Invalid date to Join date
Date Format ” Date Format ”
Display message Redirect the user to
Successfully add a patient
“Successfully added ” diagnosis menu.
Prompt user to enter
Examine cost less than 0 Display message “Incorrect
expense again
and more than 10000 Input ”
Prompt user to enter
Medical cost less than 0 Display message “Incorrect
Medical expense again
and more than 10000 Input ”
Bill
Display message “Error :
Examine cost input as a Display message “Error :
Enter an Integer value”
character Enter an Integer value”
Medical cost input as a Display message “Error : Display message “Error :
character Enter an Integer value” Enter an Integer value”
Display message “Invalid Display message “Invalid
Invalid input to a menu option, You don’t have the option, You don’t have the
permission to access ” permission to access ”
Display message “Invalid
Menu
Invalid input to a menu option, You don’t have the Return to the main menu.
permission to access ”
Direct to the function.
Valid input to a menu Direct to the function.
Display message “Incorrect
Display message “Incorrect
Invalid search option Option” and direct to the
Input ”
main menu.
Correct search option Direct to the search menu. Direct to the search menu.
Display message “Incorrect Display message “Incorrect
Invalid ID to search by ID Input ” and direct to the Option” and direct to the
search menu main menu.
Valid ID to search by ID Display the details of patient Display the details of patient
Display message “No Display message “No
Invalid name to search by
Search records ” and direct to the records ” and direct to the
Patient name
search menu search menu
Display the main details of Display the main details of
Valid name to search by
patients who have similar patients who have similar
name
names names
Enter the ID after search Display the details of patient Display the details of patient
Display message “Incorrect Display message “Incorrect
Invalid ID to search by NIC Input ” and direct to the Option” and direct to the
search menu main menu.
Valid ID to search by NIC Display the details of patient Display the details of patient
Display message “Incorrect
Display message “Incorrect
Invalid search option Option” and direct to the
Input ”
main menu.
Correct search option Direct to the search menu. Direct to the search menu.
Display message “Incorrect Display message “Incorrect
Invalid ID to search by ID Input ” and direct to the Option” and direct to the
search menu main menu.
Valid ID to search by ID Display the details of doctor Display the details of doctor
Display message “No Display message “No
Invalid name to search by
records ” and direct to the records ” and direct to the
Search name
search menu search menu
Doctor
Display the main details of Display the main details of
Valid name to search by
doctors who have similar doctors who have similar
name
names names
Display the details of Display the details of
Enter the ID after search
Doctors Doctors
Display message “Incorrect Display message “Incorrect
Invalid ID to search by NIC Input ” and direct to the Option” and direct to the
search menu main menu.
Display the details of Display the details of
Valid ID to search by NIC
Doctors Doctors
Display message “Incorrect
Display message “Incorrect
Invalid search option Option” and direct to menu
Input ”
main menu.

Correct search option Direct to the search menu. Direct to the search menu.

Display message “Incorrect Display message “Incorrect


Invalid ID to search by ID Input ” and direct to the Option” and direct to the
search menu main menu.
Valid ID to search by ID Display the details of Nurse Display the details of Nurse

Search Display message “No Display message “No


Invalid name to search by
Nurse records ” and direct to the records ” and direct to the
name
search menu search menu
Display the main details of Display the main details of
Valid name to search by
Nurse who have similar Nurse who have similar
name
names names
Enter the ID after search Display the details of Nurse Display the details of Nurse
Display message “Incorrect Display message “Incorrect
Invalid ID to search by NIC Input ” and direct to the Option” and direct to the
search menu main menu.
Display the details of Display the details of
Valid ID to search by NIC
Nurses Nurses
Display message “Incorrect Display message Incorrect
Edit Invalid edit option Input ” and direct to the Input ” and direct to the
Doctor search menu search menu
Details
Valid edit option Direct to the edit menu Direct to the edit menu
Display message “Incorrect Display message Incorrect
Edit Invalid edit option Input ” and direct to the Input ” and direct to the
Nurse search menu search menu
Details
Valid edit option Direct to the edit menu Direct to the edit menu

Display message “Incorrect Display message Incorrect


Edit Invalid edit option Input ” and direct to the Input ” and direct to the
Patient search menu search menu
Details
Valid edit option Direct to the edit menu Direct to the edit menu

Edit All Display message “Incorrect Display message “Incorrect


Invalid input
Details of Input ” Input ”
doctor Valid Input Direct to the all edit page Direct to the all edit page

Edit All Display message “Incorrect Display message “Incorrect


Invalid input
Details of Input ” Input ”
Nurse Valid Input Direct to the all edit page Direct to the all edit page
Display message “Incorrect Display message “Incorrect
Edit All Invalid input
Input ” Input ”
Details of
patient Valid Input Direct to the all edit page Direct to the all edit page

Display message “Invalid Display message “Invalid


Enter Invalid data
Edit Data” Data”
Doctor
Details Display message “Invalid Display message “Invalid
Enter Valid data
Data” Data”
Display message “Invalid Display message “Invalid
Enter Invalid data
Edit Data” Data”
Nurse
Details Display message “Invalid Display message “Invalid
Enter Valid data
Data” Data”
Display message “Invalid Display message “Invalid
Edit Enter Invalid data
Data” Data”
Patient
Details Display message “Invalid Display message “Invalid
Enter Valid data
Data” Data”
Save Display message “Data Display message “Data
Doctor Save Doctor Details Modified” and direct to main Modified” and direct to main
Details menu menu
Save Display message “Data Display message “Data
Nurse Save Nurse Details Modified” and direct to main Modified” and direct to main
Details menu menu
Save Display message “Data Display message “Data
Patient Save Patient Details Modified” and direct to main Modified” and direct to main
Details menu menu
Delete Display message “Data Display message “Data
Doctor Delete Doctor Details Deleted” and direct to main Deleted” and direct to main
Record menu menu
Delete Display message “Data Display message “Data
Nurse Delete Nurse Details Deleted” and direct to main Deleted” and direct to main
Record menu menu
Delete Display message “Data Display message “Data
Patient Delete Patient Details Deleted” and direct to main Deleted” and direct to main
Record menu menu
Display message “Invalid Display message “Invalid
View Invalid patient ID Data” and redirect to the Data” and redirect to the
medical main menu main menu
Bill Display the medial bill of the Display the medial bill of the
Valid data ID
patient patient
Display message “Incorrect
NIC contain less than 10 Display message “Incorrect
Input ”
digits Input ”
Add
Doctor 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 ” “Password mismatch ”
Nurse try to add a doctor No option to add them No option to add them
Display message “Invalid Display message “Invalid
Invalid date to Join date
Date Format ” Date Format ”
Display message Redirect the user to main
Successfully add a doctor
“Successfully added ” menu.
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 ”
Add Display message
Nurse Display message
Passwords are mismatch “Password mismatch ”
“Password mismatch ”

Nurse try to add a nurse No option to add them No option to add them

Display message “Invalid Display message “Invalid


Invalid date to Join date
Date Format ” Date Format ”
Display message Redirect the user to main
Successfully add a doctor
“Successfully added ” menu.

Add Successfully add a Display message Redirect the user to


Diagnosis diagnosis “Successfully added ” diagnosis menu.

Display message “Invalid Display message “Invalid


Invalid diagnosis Number
input ” input ”
Delete
Diagnosis Display message “Invalid Display message “Invalid
Valid diagnosis Number diagnosis deleted ” and diagnosis deleted ” and
delete the diagnosis delete the diagnosis
Display message “Invalid Display message “Invalid
Invalid diagnosis Number
input ” input ”
Edit
Diagnosis Display message “Invalid Display message “Data
Valid diagnosis Number diagnosis modified ” and modified ” and modified the
modified the diagnosis 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.
 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

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]

Potrebbero piacerti anche