Mks 1083: Data Structures and Algorithm SEMESTER 1 SESI 2020/2021 Group Project

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 47

MKS 1083: DATA STRUCTURES AND

ALGORITHM

SEMESTER 1 SESI 2020/2021

GROUP PROJECT
NAME: 1) LEE ZHEE NAN (E20191025081)
2) SAMMI TEH SIM YEE
(E20191025091)
3) TAN YAN JUN (E20191025043)
PROGRAM: DIPLOMA IN COMPUTER SCIENCE
GROUP: B
PROGRAM: CLINIC PATIENTS MANAGEMENT
SYSTEM
LECTURER PUAN HASNATUL NAZUHA BINTI
: HASSAN
Table Of Content
NO. INDEX PAGE

1. 1.0 Problem analysis


3-4

2. 2.0 Flowchart
5

3. 3.0 Coding C++


6 - 21

4. 4.0 Output
-1. Import or create file
-2. Adding new patient record
-3. Updating an existing patient record
-4. Search a patient record 22- 47
-5. View patients record
-6. Remove a patient record
-7. Save
-0. Exit

1.0 Problem analysis

Nowadays, doctor and nurse worry about the available system is because it is not quite
popular and it required some specific skills in order to install or operate it. The functionality
of the system can actually replace using the traditional way which is the paperwork in their

2
mind. The current clinic patient management system that available in the market is just
replace the paperwork by using computer and store the data into the database. The normal
functionalities include the patient record management module. There is not much new
functionality that available in the system. In this project, we intend to solve the problem that
the doctor and nurse worry about in the available system and add in new innovations that help
the patient and staff of clinic in our developed system.

Compare with the available system, there are a lot of modules inside. We will focus the
problems in these modules which are registration, updating, searching, viewing and deleting
information modules.

Modules Problems
Registration module When a patient first time visits the clinic,
he/she need to register into the system.
Nurse needs to type the details of patient
into the system which may slow down the

3
process of registration and typo will be
occurred sometimes.
Information update module If a patient wants to update his/her
information for address and phone number.
New information that is added may not
properly stored or old information may still
be the same data.
Search information module If doctors or staff nurses want to view for a
particular patient’s record. It requires a lot
of time to search for it. It may occur
duplication of data or data error.
View information module When a doctor or nurse wants to view all
the patients’ information, it may occur lost
in data information or data error. Some of
the data information may also not be shown
if there is a crash or jammed of information
lists.
Delete information module If doctor or nurse wants to delete a patient’s
record, they might accidentally delete the
wrong data due to duplication of
information.

Table 1: Problem analysis for different types of modules.

2.0 Flowchart

4
3.0 Coding C++

5
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

using namespace std;

typedef struct {

int id;

char name[50];

int age;

char gender[8];

int contact;

char address[200];

}patient;

typedef struct LNode {

patient data;

struct LNode* next;

}LNode,* LinkList;

LinkList L = NULL;

FILE* fp;

6
char filename[10];

void menu();

void CreateList();

void OpenFile();

void PrintAll();

void SearchMenu();

void SearchID();

void AddData();

void DeleteMenu();

void DeleteID();

void ModifyData();

void SaveData();

void menu() {

cout << endl << endl;

cout << "\t----------------------------------------------------\n";

cout << "\t| MKS1083 GROUP PROJECT |\n";

cout << "\t----------------------------------------------------\n";

cout << "\t| Welcome to Premium Clinic Management System. |\n";

cout << "\t----------------------------------------------------\n";

cout << "\t| 1. Create or Import Patients Records File |\n";

cout << "\t| 2. Adding New Patients Record |\n";

7
cout << "\t| 3. Updating An Existing Patient Record |\n";

cout << "\t| 4. Search A Patient Record |\n";

cout << "\t| 5. View Patients Record |\n";

cout << "\t| 6. Remove A Patient Record |\n";

cout << "\t| 7. Save Patients Record |\n";

cout << "\t| 0. Exit |\n";

cout << "\t----------------------------------------------------\n";

void CreateList() {

L = (LNode*)malloc(sizeof(LNode));

L->next = NULL;

void OpenFile() {

CreateList();

LNode * p, *q;

q = L;

while (true) {

cout << "\n\n\tPlease enter file name:";

cin >> filename;

if ((fp = fopen(filename, "r")) == NULL) {

cout << "\tFile didn't existed. Do you want to create a new file?(y/n):";

char ch; cin >> ch;

8
if (ch == 'Y' || ch == 'y') {

if ((fp = fopen(filename, "a+")) == NULL) {

cout << "\tFailed to created file!" << endl;

else break;

else continue;

else break;

while (true) {

p = (LNode*)malloc(sizeof(LNode));

if (fscanf(fp, "%d\t%s\t%d\t%s\t%d\t%s\n", &p->data.id, &p->data.name, &p-


>data.age, &p->data.gender, &p->data.contact, &p->data.address) == EOF){

free(p);

cout << "\n\tSuccess Import Patients Record file!" << "\n";

cout << "\t";

system("pause");

break;

p->next = NULL;

q->next = p;

q = q->next;

fclose(fp);

9
}

void PrintAll() {

system("cls");

cout << "\n\n\t-------------------------------------Patiens


Record-------------------------------------\n";

LinkList p;

p = L->next;

cout << "\tID\tName\t\t\tAge\tGender\tPhone no.\tAddress\n";

if (p == NULL) {

cout << "\tNo data!" << "\n";

cout << "\t";

system("pause");

return;

while (p!=NULL) {

printf("\t%d\t%s\t%d\t%s\t%d\t%s\n", p->data.id, p->data.name, p->data.age, p-


>data.gender, p->data.contact, p->data.address);

p = p->next;

cout << "\t----------------------------------------------------------------------------------------\n";

cout << "\t";

system("pause");

void SearchMenu() {

10
int choise = -1;

while (choise != 2) {

system("cls");

cout << endl << endl;

cout << "\t----------------------------------------------------\n";

cout << "\t| Search Patient Record |\n";

cout << "\t----------------------------------------------------\n";

cout << "\t| 1.Search by ID |\n";

cout << "\t| 2.Back to Menu |\n";

cout << "\t----------------------------------------------------\n";

cout << "\tYour choice:";

cin >> choise;

switch (choise)

case 1:

SearchID();

break;

default:

break;

11
void SearchID() {

system("cls");

cout << endl << endl;

cout << "\t--------------------------------Searching Patient


Record--------------------------------\n";

cout << "\tPlease enter patient ID:";

int id; cin >> id;

LinkList q = L->next;

while (q != NULL) {

if (q->data.id == id) {

cout << "\tID\tName\t\t\tAge\tGender\tPhone no.\tAddress" << endl;

printf("\t%d\t%s\t%d\t%s\t%d\t%s\n", q->data.id, q->data.name, q->data.age, q-


>data.gender, q->data.contact, q->data.address);

cout << "\t------------------------------------------------------------------------------------\n";

cout << "\t";

system("pause");

return;

q = q->next;

cout << "\t------------------------------------------------------------------------------------\n";

cout << "\tID not exist." << "\n";

cout << "\t";

system("pause");

12
void DeleteMenu() {

int choise = -1;

while (choise != 2) {

system("cls");

cout << endl << endl;

cout << "\t----------------------------------------------------\n";

cout << "\t| Remove A Patient Record |\n";

cout << "\t----------------------------------------------------\n";

cout << "\t| 1.Remove by ID |\n";

cout << "\t| 2.Back to Menu |\n";

cout << "\t----------------------------------------------------\n";

cout << "\tYour choice:";

cin >> choise;

switch (choise)

case 1:

DeleteID();

break;

default:

break;

13
void DeleteID() {

cout << endl << endl;

cout << "\tPlease enter patient ID:";

int id; cin >> id;

LinkList q = L;

while (q != NULL) {

if (q->next->data.id == id) {

LinkList p = q->next;

q->next = p->next;

free(p);

cout << "\t----------------------------------------------------\n";

cout << "\tPatient record remove successfully!" << "\n";

cout << "\t";

system("pause");

return;

q = q->next;

cout << "\tID not exist." << "\n";

cout << "\t";

system("pause");

void AddData() {

14
system("cls");

cout << endl << endl;

cout << "\t----------------Adding Patient Record---------------\n";

cout << "\tPlease enter number of patient you want to add:";

int n; cin >> n;

LinkList p, q;

for (int i = 0; i < n; i++) {

p = (LNode*)malloc(sizeof(LNode));

printf("\tAdding Number%d's patient record':\n", i + 1);

cout << "\tPlease enter patient ID:";

cin >> p->data.id;

q = L->next;

while (q != NULL) {

if (q->data.id == p->data.id) {

cout << "\tDuplicate ID,please enter again:";

cin >> p->data.id;

q = L->next;

continue;

else q=q->next;

fflush(stdin);

cout << "\tPlease enter patient name:";

cin.getline(p->data.name,50);

15
fflush(stdin);

cout << "\tPlease enter patient age:";

cin >> p->data.age;

fflush(stdin);

cout << "\tPlease enter patient gender:";

cin.getline(p->data.gender,10);

fflush(stdin);

cout << "\tPlease enter patient phone no.:";

cin >> p->data.contact;

fflush(stdin);

cout << "\tPlease enter patient address:";

cin.getline(p->data.address,200);

cout << "\n";

if (L->next == NULL) {

p->next = NULL;

L->next = p;

else {

q = L->next;

while (q != NULL) {

if (q->next != NULL) {

if (p->data.id > q->data.id && p->data.id < q->next->data.id) {

p->next = q->next;

16
q->next = p;

break;

else {

p->next = NULL;

q->next = p;

break;

q = q->next;

cout << "\t----------------------------------------------------\n";

cout << "\t";

system("pause");

void ModifyData() {

system("cls");

cout << endl << endl;

cout << "\t-----------Updating An Existing Patient Record----------\n";

cout << "\tPlease enter patient ID:";

int id,n=0 ; cin >> id;

17
LinkList q = L ;

while (q != NULL) {

q = q->next;

if (q->data.id == id) {

break;

if (q->next == NULL) {

cout << "\tID not existed,please try again:";

cin >> id;

q = L->next;

continue;

LinkList pnew = (LNode*)malloc(sizeof(LNode));

pnew->next = NULL;

cout << "\tPlease enter new age:";

cin >> pnew->data.age;

cout << "\tPlease enter new phone no.:";

cin >> pnew->data.contact;

fflush(stdin);

cout << "\tPlease enter new address.:";

cin.getline(pnew->data.address,200);

18
q->data.age = pnew->data.age;

q->data.contact = pnew->data.contact;

strcpy(q->data.address,pnew->data.address);

free(pnew);

cout << "\t--------------------------------------------------------\n";

cout << "\tPatient record update successfully!" << "\n";

cout << "\t";

system("pause");

void SaveData() {

LinkList q = L->next;

if ( (fp = fopen(filename, "w")) == NULL) {

cout << "\tFailed to open file, ";

system("pause");

return;

else {

while (q != NULL) {

fprintf(fp, "%d\t%s\t%d\t%s\t%d\t%s\n", q->data.id, q->data.name, q->data.age, q-


>data.gender, q->data.contact, q->data.address);

q = q->next;

19
fclose(fp);

cout << "\tSaved Successfully!" << "\n";

cout << "\t";

system("pause");

int main() {

int choise = -1;

while(choise){

system("cls");

menu();

cout << "\tYour choice:";

cin >> choise;

switch(choise){

case 1:

OpenFile();

break;

case 2:

AddData();

break;

case 3:

ModifyData();

20
break;

case 4:

SearchMenu();

break;

case 5:

PrintAll();

break;

case 6:

DeleteMenu();

break;

case 7:

SaveData();

break;

default:

break;

return 0;

4.0 Output

21
Output: Main menu

22
1.0 Main menu enter ‘1’ to import or create a file name: premium_clinic

1.1 File premium_clinic doesn’t exist

23
1.2 File doesn’t exist, enter ‘n’ to try enter file name again.

1.3 File doesn’t exist, enter ‘y’ to create new file. File created.

24
2.0 Main menu enter ‘2’ to add new patients record.

2.1 After enter ‘2’, enter numbers of patient we want to add. Try enter ‘5’.

25
2.2 After enter numbers of patient, we can start enter patient details (ID, Name, Age, Gender,
Phone no. , Address)

2.3 Finished enter details of first patient, continue to enter details of second patient and so on
until fifth patient.

26
2.4 We try adding patient with ID: 103 at second (for later to test is it ‘sorting by ID’ function
working or not). When adding details of no.5 patient, we try enter ID which already existed
to test ‘unique’ of ID function or not. It is functioning properly, so display message to ask
user to enter the ID again.

27
2.5 Done adding all patients details.

28
2.6 Back to main menu. Enter ‘5’ to view and check all records we added just now.

2.7 All patients record we added just now is show properly. All records also sorted follow by
ID

29
2.8 Back to main menu. Enter ‘7’ to save patients record we added just now into
premium_clinic file we created just now.

2.9 Records saved.

30
2.9.1 Open premium_clinic file to check record save successful or not. All records save
successfully.

3.0 Main menu enter ‘3’ to update an existing patient record.

31
3.1 After enter ‘3’, we can enter patient’s ID which we want to update.

3.2 After enter patient’s ID, we can enter the new age, phone number and address to update.

Stay ID, Name and Gender unchanged.

32
3.3 Update patient with ID 102. Age ‘22’ become ‘25’, phone number ‘0127839821’ become
‘0173491293’ and address ‘C134, Taman Cahaya, Tanjong Malim’ become ‘C54, Taman
Ceriah, Tanjong Malim’. Update successfully.

3.4 Back to main menu. Enter ‘5’ to view and check record after updated.

33
3.5 Confirm record we updated just now was successful.

3.6 Back to main menu. Enter ‘7’ to save update we make just now.
34
3.7 Records saved.

3.7.1 Open premium_clinic file to check updated record save successful or not. All records
save successfully.

35
4.0 Main menu enter ‘4’ to search a patient record.

4.1 After enter ‘4’, we go to ‘Search Patient Record’ menu.

36
4.2 Enter ‘1’ to search patient record by ID.

4.3 After enter ‘1’, we can enter patient’s ID which we want to search.

37
4.4 try enter ID that didn’t exist. Display message “ID not exits”.

4.5 Enter patient ID 103, we success found that patient record.

38
4.6 Back to ‘Search Patient Record’ menu. Enter ‘2’ back to main menu.

4.7 Back to main menu.

39
5.0 To view all patients record.

5.1 View all patients record.

40
6.0 Back to main menu. Enter ‘6’ to remove a patient record.

6.1 After enter ‘6’, we go to ‘Remove A Patient Record’ menu.

41
6.2 Enter ‘1’ to remove a patient record by ID.

6.3 Enter ID 103 to remove patient with number ID 103. Remove successfully.

42
6.4 Back to ‘Remove A Patient Record’ menu. Enter 2 back to main menu.

6.5 Back to main menu.

43
6.6 Enter ‘5’ to view and check record after removed.

6.7 Confirm the record we removed just now was successful.

44
6.8 Back to main menu. Enter ‘7’ to save remove we make just now.

6.9 Records save.

45
6.9.1 Open premium_clinic file to check record after removed save successful or not. All
records save successfully.

7.0 Back to main menu. Enter’0’ to close program.

46
7.1 After enter ‘0’, program end.

47

You might also like