PSPD Assignment

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

INDIVIDUAL ASSIGNMENT

TECHNOLOGY PARK MALAYSIA


AAPP005-4-4-PSPD
PROGRAM SOLVING AND PROBLEM USING C
UCDF1505ICT(SE)

NAME: LEONG WENG FON


TP NO. :TP038881
LECTURER NAME: TANVEER KHALEEL SHAIKH
SUCMISSION DATE: JUNE, 3, 2016

1
Contents (Allain, 2016)
1.0 Introduction ......................................................................................................................... 3
2.0 The Scope ............................................................................................................................ 3
3.0 Objective.............................................................................................................................. 5
4.0 Sample Output..................................................................................................................... 6
5.0 Flowchart ........................................................................................................................... 22
6.0 Code................................................................................................................................... 33
7.0 Programming Concept Applied ......................................................................................... 51
8.0Function code ..................................................................................................................... 52
8.1 Header file ......................................................................................................................... 52
8.2 Data type ........................................................................................................................... 53
8.3 Printf and Scanf ................................................................................................................. 54
8.4 IF & ELSE statement........................................................................................................... 55
8.5 Strcmp ............................................................................................................................... 56
8.6 Loop(While) ....................................................................................................................... 56
8.7 Switch ................................................................................................................................ 57
8.8 Structure ............................................................................................................................ 58
8.9 File Handling ...................................................................................................................... 59
8.10 Declaring File ................................................................................................................... 59
8.11 Open Files ........................................................................................................................ 60
9.0 References ......................................................................................................................... 61
10.0 Conclusion ....................................................................................................................... 62

2
1.0 Introduction

In this assignment, we use hospital reservation system as our assignment question and
we have to do c programming in this hospital reservation system. In hospital
reservation system, we can booking an appointment either from phone or from online
booking. But, we use computer to book the reservation to people. You can add a new
patient or a new appointment in this hospital reservation system before we meet the
doctor. The hospital reservation system operate 24 hours and work in whole year. In
this hospital reservation system, the people who are register as a patient are able to
edit, delete, and view their detail. The doctor also can use this hospital reservation
system to view their patient detail and appointment detail. The hospital reservation
system is easy to use for patient and doctor.

2.0 The Scope

Flowchart

A flowchart is a type of diagram that represents an algorithm, workflow or process,


showing the steps as boxes of various kinds, and their order by connecting them with
arrows. This diagrammatic representation illustrates a solution model to a given
problem.

Add/Delete/Modify Patient Detail

People can add as a patient. As a patient, patient can delete their patient detail. Patient
can modify patient detail.

View Patient Detail

Patient can choose this option for view the detail themselves. The screen will display
the detail clearly in the output.

3
Search Patient Detail

Sometime, there are too many patient, you can choose this option for search your
patient detail. The screen will display the patient detail clearly and fast.

Add/Delete/Modify Appointment Detail

After you add you as a patient, you can book an appointment in this system. This
system are able to add delete and modify appointment detail anytime.

View Appointment Detail

After you add an appointment, then you forget the appointment detail. You can
choose this function, for refer your appointment again.

Search Appointment Detail

There are too many appointment at a same time. You can choose this function for
search your appointment detail. And the system will display your appointment detail
only.

4
3.0 Objective

Time saving

Staff spends less time on the phone booking and managing appointments, thereby
freeing up their schedule for more important and pressing tasks. Booking individuals
also save time, as they no longer have to commit a part of their busy schedule to
calling their medical, healthcare or wellness provider (or remain on hold, which adds
minutes to the scheduling process). As an example, let’s look at a large medical
facility that typically schedules approximately 100 appointments and patients daily.
Each appointment is fielded by an administrative support staffer, who spends an
average of four minutes on the phone. This equates to an average of 400 minutes- or
almost seven hours- of time spend each day just to booking appointment over the
phone.

24-Hour convenience

Scheduling appointments over the phone usually requires and individual to phone in
during office hours, as few facilities offer round-the-clock phone booking. This is an
inconvenience for most patients, as they too are working at this time. Additionally,
many individuals prefer to schedule their appointments online rather than over the
phone. This scheduling system allows for 24- hour scheduling, not just during normal
facility or office hours.

5
4.0 Sample Output

Figure 1

Figure 1 above show output of the log in page. On top of that have
“WELCOME” and “HOSPITAL RESERVATION SYSTEM”. Then, there are two
choice for you. There are “Administrator” and “User” and last you can enter “1” or
“2” to continue. “1” is for admin. For example, patient. “2” is for doctor. Doctor can
view patient or appointment.

6
Figure 2

Figure 2 show the output of the log in page. When we choose “1”, the screen
will display the”1”.

Figure 3

Figure 3 show the next output of the log in page. You can enter ID and Password. If
the password and ID are correct, then will go to the next page.

7
Figure 4

Figure 4 show when we choose 2, the screen will display the “2” when we tap 2.

Figure 5

Figure 5 show the output when enter the ID and PASSWORD. Then the display will
bring you to next page.

8
Figure 6

Figure 6 show after you enter your ID and password correctly, will display this page.
You got 3 option to choose, there are “1. View Patient”, “2. View Appointment”, “3.
Exit”.

9
Figure 7

Figure 7 show the output after enter ID and password correctly, you will go to this
page. In this page, you got 3 option to choose, “1. Patient”, “2. Appointment” and “3.
Exit”.

10
Figure 8

Figure 8 show the output when you choose patient, you got 5 options to choose, “1.
Add patient detail”, “2. View patient detail”, “3. Delete patient detail”, “4. Modify
patient detail”, “5. Search patient detail”.

Figure 9

Figure 9 show the output after you choose”1. Add patient detail”. You can enter
patient detail, like ID, name, gender, age and so on.

11
Figure 10

Figure 10 show the output after you enter all your detail and the system will ask you
would you like to go to the main menu. You got two options to choose “1- yes”, “0 –
no”. If you choose “1” will go to the main menu and you choose “0” will exit the
program.

12
Figure 11

Figure 11 show the output after add patient detail and you choose “2. View patient
detail”. The output will list out all the detail on the output.

13
Figure 12

Figure 12 show the output of “Delete patient detail”, you enter your ID, then the
system will displays “Patient Deleted”, which mean your ID are deleted.

14
Figure 13

Figure 13 show the output of “Modify patient detail”. In this page, you have to enter
your ID, then you enter your new detail for all. After, the screen will display
“Complete Edit Patient Detail”.

15
Figure 14

Figure 14 show the output of the “search patient detail”, you have to enter your ID,
then there will list out the patient detail clearly.

Figure 15

Figure 15 show the output when u choose “patient”, then will go to this page. There
are also have 5 options to choose from this page. There are “1. Add appointment
detail”, “2. View appointment detail”, “3. Delete appointment detail”, “4. Modify
appointment detail”, “5. Search appointment detail”.

16
Figure 16

Figure 16 show the output when you choose “1. Add appointment detail”. You able to
add appoint id, doctor id, appointment date, patient disease, appointment description.
The above show you when u enter all detail in the output.

Figure 17

Figure 17 show the output of “View appointment detail”. The output will displays all
detail that you enter into the output. There also show other patient detail on the
output.

17
Figure 18

Figure 18 show the output of the “Delete appointment detail”. You have to enter your
id, then u are able to delete. After you enter id, below there will show “appointment
deleted”. Then you are already deleted.

18
Figure 19

Figure 19 show the output of “modify appointment detail”. In this output, you able to
edit your appointment detail when you want to edit anytime. You have reenter all
your appointment detail again. When you enter all detail, the output will displays
“complete edit appointment detail”.

19
Figure 20

Figure 20 show the output of “Search appointment detail”. You only enter your ID,
you able to view your appointment detail.

Figure 21

Figure 21 show the output when you log in as user and you log in successful, it will
bring you to this output. In this output, you have 3 options to choose, there are “1.
View Patient”, “2. View Appointment”, “3. Exit”.

20
Figure 22

Figure 22 show the output of “View Patient”. In this output, you are able to view all
patient detail in this output.

Figure 23

Figure 23 show the output of “View Appointment”. In this output, you are able to
view all appointment detail in the same time.

21
5.0 Flowchart

22
23
24
25
26
27
28
29
30
31
32
6.0 Code

#include<stdio.h>
#include<string.h>
void module1();//function prototype for add patient detail
void module2();//function prototype for view patient detail
void module3();//function prototype for delete patient detail
void module4();//function prototype for search patient detail
void module5();//function prototype for modify patient detail
void module6();//function prototype for add appointment detail
void module7();//function prototype for view appointment detail
void module8();//function prototype for delete appointment detail
void module9();//function prototype for search appointment detail
void module10();//function prototype for modify appointment detail
void admin2();
void menu();//function prototype for patient
void menu2();//function prototype for appointment
void user2();
struct patient
{
char patid[20];
char patname[25];
char patgender[30];
char patage[35];
char patbloodtype[40];
char pataddress[45];
char patdiagnosis[50];
};
struct patient c1;

struct appointment
{
char appid[20];
char docid[30];
char appdate[20];
char patdisease[20];
char appdescription[25];
};
struct appointment z1;

char privilage = '\0';

33
void userchk();//function prototype for giving privilages between doctor and
administrator
void menu();
void main()
{
printf("\t\t\t\t\t******************WELCOME******************\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t* Hospital Reservation System *\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t*******************************************\n");
userchk();//module checks the user and administrator
}
void userchk()//module that diffrentiates user & administrator
{
char userID[20] = "user";
char userpasswrd[20] = "abcd";
char user[20];
char passuser[20];
char adminID[25] = { "admin" };
char adminpasswrd[25] = { "1234" };
char admin[25];
char passadmin[25];
int i = 0;
char ch = '\0';
int us_choice = 1;// choice between user and administrator
int us_check;
int us_check2;// variable that compare integers
printf("\n\t\t\t\t\tLOG IN \n\n\t\t\t\t\t 1) Administrator \n\t\t\t\t\t
2) User \n\n\t\t\t\t\tEnter Your Choice:");
scanf("%d", &us_choice);
if (us_choice == 1)
{
for (i = 0;i < 20;i++)
{
passuser[i] = '\0';
}
system("cls");
i = 0;
printf("\n\t\t\t\t\tEnter ID:");
scanf("%s", &admin);
printf("\n\t\t\t\t\tEnter Password:");
while (ch != 13)

34
{
ch = getch();
passuser[i++] = ch;
printf("*");
}
passuser[i] = '\0';
us_check = stricmp(admin, adminID);
us_check2 = stricmp(passadmin, adminpasswrd);
//printf("us_check=%d",us_check)
if (us_check == 0)
{
system("cls");
privilage = 'a';
admin2();
//return;
}
else
{
printf("\nEntered password is wrong\n");
getch();
system("cls");
userchk();
}
}
if (us_choice == 2)
{
system("cls");
printf("\n\t\t\t\t\t\tEnter ID:");
scanf("%s", &user);
printf("\n\t\t\t\t\t\tEnter Password:");
while (ch != 13)
{
ch = getch();
passadmin[i++] = ch;
printf("*");
}
admin[i] = '\0';
us_check = stricmp(user, userID) && (passuser, userpasswrd);
// printf("%d",us_check);
if (us_check == 0)
{
system("cls");

35
privilage = 'u';
user2();
}
else
{
printf("Entered password is wrong");
}
}
getch();
}

void user2()
{
int choice;
printf("\t\t\t\t\t******************WELCOME******************\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t* 1.View Patient *\n");
printf("\t\t\t\t\t* 2.View Appointment *\n");
printf("\t\t\t\t\t* 3. Exit *\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t*******************************************\n");
printf("\tEnter Your Choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
system("cls");
module2();
printf("\n Would you like to goto the main menu");
printf("\n 1-yes \t\t 0-no\n\t");
scanf("%d", &choice);
system("cls");
if (choice == 1)
{
user2();
}
else
{
break;
}
break;

36
case 2:
system("cls");
module7();
printf("\n Would you like to goto the main menu");
printf("\n 1-yes \t\t 0-no\n\t");
scanf("%d", &choice);
system("cls");
if (choice == 1)
{
user2();
}
else
{
break;
}
break;

case 3:
exit(0);
}
}

void admin2()
{
int choice;
printf("\t\t\t\t\t******************WELCOME******************\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t* 1. Patient *\n");
printf("\t\t\t\t\t* 2. Appointment *\n");
printf("\t\t\t\t\t* 3. Exit *\n");
printf("\t\t\t\t\t* *\n");
printf("\t\t\t\t\t*******************************************\n");
printf("\t Enter Your Choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
menu();
printf("\nYou Choose Patient........");
printf("\n\n\nPress any key to continue......");
getch();
system("cls");

37
module2();
break;

case 2:
menu2();
printf("\nYou choose patient........");
printf("\n\n\nPress any key to continue......");
getch();
system("cls");
module7();
break;

case 3:
exit(0);
}
}

void menu()
{
int choice;//choice for main menu
int mm;// choice for the goto tag
system("cls");
printf("\n\t\t\t\t\t*******************Welcome to******************");
printf("\n\t\t\t\t\t**********Hospital Reservation System**********");
printf("\n\t\t\t\t\t* *");
printf("\n\t\t\t\t\t* 1.Add patient detail *");
printf("\n\t\t\t\t\t* 2.View patient detail *");
printf("\n\t\t\t\t\t* 3.Delete patient detail *");
printf("\n\t\t\t\t\t* 4.Modify patient detail *");
printf("\n\t\t\t\t\t* 5.Search patient detail *");
printf("\n\t\t\t\t\t* *");
printf("\n\t\t\t\t\t***********************************************");
printf("\n\n\t\t\t\t Enter Your Choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Add Patient Detail");
module1();//module for add patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);

38
if (mm == 1)
{
menu();
}
else
{
break;
}
case 2:
printf("View Patient Detail");
module2();//module for veiw patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);
if (mm == 1)
{
menu();
}
else
{
break;
}
case 3:
printf("Delete Patient Detail");
module3();//module for delete patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);
if (mm == 1)
{
menu();
}
break;
case 4:
printf("Modify Patient Detail");
module4();// module for modify patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);
if (mm == 1)
{
menu();

39
}
else
{
break;
}
case 5:
printf("Search Patient Detail");
module5();// module search patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);
if (mm == 1)
{
menu();
}
else
{
break;
}
default:
printf("not valid");
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &mm);
if (mm == 1)
{
menu();
}
else
{
break;
}
}
}
void module1()
{
system("cls");
FILE *AddPatient;
AddPatient = fopen("patient_info.txt", "a");
struct patient c1;
fseek(stdin, 0, SEEK_END);

40
printf("\nEnter Patient Details:");
printf("\nPatient ID:");
scanf("%[^\n]%*c", &c1.patid);
printf("\nPatient Name:");
scanf("%[^\n]%*c", &c1.patname);;
printf("\nPatient Gender:");
scanf("%[^\n]%*c", &c1.patgender);
printf("\nPatient Age:");
scanf("%[^\n]%*c", &c1.patage);
printf("\nPatient Bloodtype:");
scanf("%[^\n]%*c", &c1.patbloodtype);
printf("\nPatient Address:");
scanf("%[^\n]%*c", &c1.pataddress);
printf("\nPatient Diagnosis:");
scanf("%[^\n]%*c", &c1.patdiagnosis);
fwrite(&c1, sizeof(c1), 1, AddPatient);
fclose(AddPatient);
getch();
}
void module2()
{
system("cls");
FILE *viewpatientinfo;
char io;
viewpatientinfo = fopen("patient_info.txt", "r");//=read
while (fread(&c1, sizeof(c1), 1, viewpatientinfo) == 1)
{
printf("\nPatient ID:%s\n Patient Name:%s\n Patient Gender:%s\n
Patient Age:%s\n Patient Bloodtype:%s\n Patient Address:%s\n Patient
Diagnosis:%s\n ", c1.patid, c1.patname, c1.patgender, c1.patage,
c1.patbloodtype, c1.pataddress, c1.patdiagnosis);
printf("\n-------------------------------------------------------
---------------------");
}
fclose(viewpatientinfo);
getch();
}
void module3()
{
system("cls");
FILE*patientdelete, *backup;
patientdelete = fopen("patient_info.txt", "r+");

41
backup = fopen("deletepatientinfo.txt", "wb+");
char deleteid[20];
printf("\nEnter the ID:");
scanf("%s", &deleteid);
while (fread(&c1, sizeof(c1), 1, patientdelete) == 1)
{
if (strcmp(deleteid, c1.patid) != 0)
{
fwrite(&c1, sizeof(c1), 1, backup);
}
fclose(patientdelete);
fclose(backup);
remove("patient_info.txt");
rename("deletepatientinfo.txt", "patient_info.txt");
printf("\n\t\t\tPatient Deleted");
getch();
}
}
void module4()
{
system("cls");
FILE *EditPatient, *patientbackup;
char pid[20];
EditPatient = fopen("patient_info.txt", "rb+");
patientbackup = fopen("deletepatientinfo.txt", "wb+");
printf("Enter Your ID:");
scanf("%s", &pid);
rewind(EditPatient);
if (EditPatient == NULL)
{
printf("\n fail to load file");
}
else
{
while (fread(&c1, sizeof(c1), 1, EditPatient) == 1)
{
if (strcmp(pid, c1.patid) == 0)
{
fseek(stdin, 0, SEEK_END);
printf("\nEnter New Patient ID:");
scanf("%[^\n]%*c", &c1.patid);
printf("\nEnter New Patient Name:");

42
scanf("%[^\n]%*c", &c1.patname);
printf("\nEnter New Patient Gender:");
scanf("%[^\n]%*c", &c1.patgender);
printf("\nEnter New Patient Age:");
scanf("%[^\n]%*c", &c1.patage);
printf("\nEnter New Patient Bloodtype:");
scanf("%[^\n]%*c", &c1.patbloodtype);
printf("\nEnter New Patient Address:");
scanf("%[^\n]%*c", &c1.pataddress);
printf("\nEnter New Patient Diagnosis:");
scanf("%[^\n]%*c", &c1.patdiagnosis);
fwrite(&c1, sizeof(c1), 1, patientbackup);
}
else
{
fwrite(&c1, sizeof(c1), 1, patientbackup);
}
}
fclose(EditPatient);
fclose(patientbackup);
remove("patient_info.txt");
rename("deletepatientinfo.txt", "patient_info.txt");
printf("Complete Edit Patient Detail");
getch();
}
}
void module5()
{
system("cls");
char patid[20];
int cnt;
cnt = 0;
FILE *viewpatientinfo;
struct patient c1;
viewpatientinfo = fopen("patient_info.txt", "rb+");
printf("\nEnter Pateint ID:");
scanf("%s", &patid);
while (fread(&c1, sizeof(c1), 1, viewpatientinfo) == 1)
{
if (strcmp(c1.patid, patid) == 0)
{
printf("\nPatient ID:%s", c1.patid);

43
printf("\nPatient Name:%s", c1.pataddress);
printf("\nPatient Gender:%s", c1.patgender);
printf("\nPatient Age:%s", c1.patage);
printf("\nPatient Bloodtype:%s", c1.patbloodtype);
printf("\nPatient Address:%s", c1.pataddress);
printf("\nPatient Diagnosis:%s", c1.patdiagnosis);
cnt++;
}
}

if (cnt == 0)
{
printf("\nPatient does not exist");
}
fclose(viewpatientinfo);
getch();
}

void menu2()
{
int choice;//choice for main menu
int nn;// choice for the goto tag
system("cls");
printf("\n\t\t\t\t\t*******************Welcome to*******************");
printf("\n\t\t\t\t\t**********Hospital Reservation System***********");
printf("\n\t\t\t\t\t* *");
printf("\n\t\t\t\t\t* 1.Add appointment detail *");
printf("\n\t\t\t\t\t* 2.View appointment detail *");
printf("\n\t\t\t\t\t* 3.Delete appointment detail *");
printf("\n\t\t\t\t\t* 4.Modify appointment detail *");
printf("\n\t\t\t\t\t* 5.Search appointment detail *");
printf("\n\t\t\t\t\t *");
printf("\n\t\t\t\t\t************************************************");
printf("\n\n\t\t\t\t\t Enter Your Choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Add appointment detail");
module6();//module for add patient detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");

44
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
case 2:
printf(" View appointment detail");
module7();//module for veiw appointment detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
case 3:
printf("Delete appointment detail");
module8();//module for delete appointment detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
case 4:
printf("Modify appointment detail");
module9();// module for modify appointment detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");

45
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
case 5:
printf("Search appointment detail");
module10();// module for search appointment detail
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
default:
printf("not valid");
printf(" \nWould you like to go to the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d", &nn);
if (nn == 1)
{
menu2();
}
else
{
break;
}
}
}
void module6()
{
system("cls");
FILE *Addappointment;

46
Addappointment = fopen("appointment_info.txt", "a");
struct appointment z1;
fseek(stdin, 0, SEEK_END);
{
printf("\nEnter appointment Details:");
printf("\nAppointment ID:");
scanf("%[^\n]%*c", &z1.appid);
printf("\nDoctor ID:");
scanf("%[^\n]%*c", &z1.docid);;
printf("\nAppointment Date:");
scanf("%[^\n]%*c", &z1.appdate);
printf("\nPatient disease:");
scanf("%[^\n]%*c", &z1.patdisease);
printf("\nAppointment Description:");
scanf("%[^\n]%*c", &z1.appdescription);
fwrite(&z1, sizeof(z1), 1, Addappointment);
fclose(Addappointment);
getch();
}
}
void module7()
{
system("cls");
FILE *viewappointmentinfo;
struct appointment info;
char io;
viewappointmentinfo = fopen("appointment_info.txt", "r");//=read
while (fread(&z1, sizeof(z1), 1, viewappointmentinfo) == 1)
{
printf("\nAppointment ID:%s\n Doctor ID:%s\n Appointment
Date:%s\n Patient Disease:%s\n Appointment Description:%s\n", z1.appid,
z1.docid, z1.appdate, z1.patdisease, z1.appdescription);
printf("\n-------------------------------------------------------
------------------------");
}
fclose(viewappointmentinfo);
getch();
}
void module8()
{
system("cls");
FILE*appointmentdelete, *Backup1;

47
appointmentdelete = fopen("appointment_info.txt", "r+");
Backup1 = fopen("deleteappointmentinfo2.txt", "wb+");
char iddelete[20];
printf("\nEnter the ID:");
scanf("%s", &iddelete);
while (fread(&z1, sizeof(z1), 1, appointmentdelete) == 1)
{
if (strcmp(iddelete, z1.appid) != 0)
{
fwrite(&z1, sizeof(z1), 1, Backup1);
}
fclose(appointmentdelete);
fclose(Backup1);
remove("appointment_info.txt");
rename("deleteappointmentinfo2.txt", "appointment_info.txt");
printf("\n\tAppointment Deleted");
getch();
}
}
void module9()
{
system("cls");
FILE *EditAppointment, *Appointmentbackup;
char aid[20];
EditAppointment = fopen("Appointment_info.txt", "rb+");
Appointmentbackup = fopen("deleteappointmentinfo.txt", "wb+");
printf("Enter Your ID:");
scanf("%s", &aid);
rewind(EditAppointment);
if (EditAppointment == NULL)
{
printf("\n fail to load file");
}
else
{
while (fread(&z1, sizeof(z1), 1, EditAppointment) == 1)
{
if (strcmp(aid, z1.appid) == 0)
{
fseek(stdin, 0, SEEK_END);
printf("\nAppointment ID:");
scanf("%[^\n]%*c", z1.appid);

48
printf("\nDoctor ID:");
scanf("%[^\n]%*c", z1.docid);;
printf("\nAppointment Date:");
scanf("%[^\n]%*c", z1.appdate);
printf("\nPatient disease:");
scanf("%[^\n]%*c", z1.patdisease);
printf("\nAppointment Description:");
scanf("%[^\n]%*c", z1.appdescription);
fwrite(&z1, sizeof(z1), 1, Appointmentbackup);
}
else
{
fwrite(&z1, sizeof(z1), 1, Appointmentbackup);
}
}
fclose(EditAppointment);
fclose(Appointmentbackup);
remove("appointment_info.txt");
rename("deleteappointmentinfo.txt", "appointment_info.txt");
printf("\n\tComplete Edit Appointment Detail");
getch();
}
}
void module10()
{
system("cls");
char appid[20];
int cnt;
cnt = 0;
FILE *viewappointmentinfo;
struct appointment z1;
viewappointmentinfo = fopen("appointment_info.txt", "rb+");
printf("\nEnter Appointment ID:");
scanf("%s", &appid);
while (fread(&z1, sizeof(z1), 1, viewappointmentinfo) == 1)
{
if (strcmp(appid, z1.appid) == 0)
{
printf("\nAppointment ID:%s", z1.appid);
printf("\nDoctor ID:%s", z1.docid);
printf("\nAppointment Date:%s", z1.appdate);
printf("\nPatient Disease:%s", z1.patdisease);

49
printf("\nAppointment Decription:%s", z1.appdescription);
printf("\n------------------------------------------------
---------------------");
cnt++;
}
}

if (cnt == 0)
{
printf("\nAppointment does not exist");
}
fclose(viewappointmentinfo);
getch();
}

50
7.0 Programming Concept Applied

Programming concept is a programming paradigm focusing on how concepts that live


in the programmer’s mind translate into representations that are found in the code
space. This approach was introduced in 2001 by Christophe de Dinechin with the XL

Programming Language. XL is the only programming language known to date to be


explicitly created for concept programming, but concept programming can be done in
nearly any language, with varying degress of success. Lisp and Forth (and their
derivatives) are example of pre-existing languages which lend themselves well to
concept programming. There are 5 types of programming concept, variables, control
structures, data structures, syntax, tools. The memory cells used for storing a
program’s input data and its computational results are called variables because the
values stored in variable declarations in a C program communicate to the C compiler
the names of all variables used in a program. They also tell the compiler what kind of
in each variables and how that information will be represented in memory. Control
Structures control the flow of execution in a program or function. The C control
structures enable you to combine individual instructions into a single logical unit with
one entry point and one exit point. Data structures, structures that expand and contract
as a program executes. C’ facilities for creating these structures allow a program to
defer until a later time its decision regarding how much space to use in processing a
data set. A program that can procrastinate in this way is far more flexible than a
comparable program that must make this decision on space earlier. For each new C
construct introduced in this book, we provide a syntax display that describes and
explain its syntax and shows examples of its use. The following syntax displays
describe the two preprocessor directives. The italicized elements in each construct are
discussed in the interpretation section. There are 6 types of programming tools, there
are debuggers, profilers, linkers, compilation managers and version-control systems.

51
8.0Function code

8.1 Header file


Syntax : #include<standard header file>

Examples: #include<stdio.h>

#include<math.h>

#include directives tell the preprocessor where to find the meanings of standard

Identifiers used in the program. These meanings are collected in files called standard
header files. The header file stdin.h contains information about standard input and
output functions such as scanf and printf. Description of common mathematical
functions are found in the header file math.h. We will investigate header files
associated with other standard libraries in later chapters. The directive gives a
program access to a library. This directive causes the preprocessor to insert definitions
from a standard header file into a program before compilation. The example of header
files, #include <stdio.h>.

52
8.2 Data type

Systax: Int variable_list;

Char variables_list;

Example: Int I,

Char docpasswrd[];

A memory cell is allocated for each name in the variable_list. The type of data( int,
char ) to be stored in each variable is specified at the beginning of the statement. One
statement may extend over multiple lines. A single data type can appear in more than
one variable declaration, so the following two declaration sections are equally
acceptable ways of declaring the variables rate, time, age. Data type int. In
mathematics, integers are whole numbers. The int data type is used to represent
integers in C. Because of the finite size of a memory cell, not all integers can be
represented by type int. ANSI C specifies that the range of the data type int must
include at least the values -32767 through 32767. You can store an integer in a type
int variable, perform the common arithmetic operations (add, subtract, multiply, and
divide), and compare two integers. Data type char. Data type char represents an
individual character value – a letter, a digit, or a special symbol. The next to last
character value above represents the character “; the last one represents the blank
character, which is typed by pressing the apostrophe key, the space bar, and the
apostrophe key. Although a type char value in a program requires apostrophes, a type
char data value should not have them. Thus, for example, when entering the letter z as
a character data item to be read by a program, press the z key instead of the sequence
‘z’. You can store a character in a type char variable and compare character data. C
even allows you to perform arithmetic operations on type char data, but you should
use this facility with care.

53
8.3 Printf and Scanf

In C a function call is used to call or activate a function. Calling a function is


analogous to asking a friend to perform an urgent task. You tell your friend what to
do( but not how to do it ) and wait for your friend to report back that the task is
finished. After hearing from your friend, you can go on and do something else.

Printf

Example: Printf(“That equals %f kilometer. \n”, kms);

The statement call function printf (pronounced “printf-eff). To see the results of a
program execution, we must have a way to specify what variable values should be
displayed. A function call consists of two parts: the function name and the function
arguments, enclosed in parentheses. The arguments for Printf consist of a format
string (in quotes) and a print list (the variables kms).

Scanf

Example: Scanf(“%lf”,&miles);

The statement calls function scanf (pronounced “scan-eff”) to copy data into the
variable miles. Where does function scanf get the data it stores in the variable miles?
It copies the data from the standard input device. In most cases the standard input
device is the keyboard; consequently, the computer will attempt to store in miles
whatever data the program user types at the keyboard. The format string “%lf”
consists of single placeholder that tells scanf what kind of data to copy into the
variables miles. Because the placeholder is %lf, the input operation will proceed
without error only if program user types in a number.

54
8.4 IF & ELSE statement

Example:

if (rest_heart_rate > 56)

Printf(“keep up your exercise program!\n);

else

Printf(“Your heart is in excellent health!\n);

The IF statement selects one of the two calls to printf. It selects the statement
following the parentherized condition evaluates to 1 (true) (that is, if rest_heart_rate is
greater than 56), or it selects the statement following else if the condition evaluates to
0 (false) (if rest_heart_rate is not greater than 56). The section describes if statements
having compound statements after the condition keyword else. When the symbol
{follows the condition or else, the C compiler either executes or skips all statements
through the matching}.

55
8.5 Strcmp

Example:

Strcmp(userid(s1),uid(s2));

Strcmp(userpassword, userpasswrd);

The strcmp function returns a negative, zero, or positive integer depending on whether
the object pointed to by s1 is less than, equal to, or greater than the object pointed to
by s2. S1 and s2 is an array to compare. The strcmp function returns an integer. When
the return values=0, s1 and s2 are equal, the return value= negative integer, then the
stopping character in s1 was less than the stopping character in s2. When the return
values= positive integer, the stopping character in s1 was greater than the stopping
character in s2.

8.6 Loop(While)

Loops are used to carry out certain instruction(s) in continuation for a fixed no of
times.

Syntax of while loop:

//initialization stmt(s)

Do

Statement1;

Statement2;

While(condition)

56
8.7 Switch

Switch case statements are a substitute for long if statement that compare a variable to
“integral” values (“integral” values are simply values that can be expressed as an
integer, such as the value of a char). The basic format for using switch case is outlined
below. The value of the variable given into switch is compared to the value following
each of the cases, and when one value matches the value of the variable, the computer
continues executing the program form that point.

Example:

switch (choice)

case 1:

printf("Add appointment detail");

module6();//module for add patient detail

printf(" \nWould you like to go to the main menu");

printf(" \n 1 - yes \t\t 0 - no\n\t");

scanf("%d", &nn);

if (nn == 1)

menu2();

else

break;

57
8.8 Structure

Structure is a user-defined data type in C which allows you to combine different data
types to store a particular type of record. Structure helps to construct a complex data
type in more meaningful way. It is somewhat similar to an Array. The only difference
is that array is used to store collection of similar datatype while structure can store
collection of any type of data.

Example:

Struct patient

char patid[20];

char patname[25];

char patgender[30];

char patage[35];

char patbloodtype[40];

char pataddress[45];

char patdiagnosis[50];

};

struct patient c1;

58
8.9 File Handling

There are five major operations that can be performed on a file. There are creation of
a new file, opening an existing file, Reading data from a file, Writing data in a file,
Closing a file. The step for processing a file. The first step is declare a file pointer
variable. Second is open a file using fopen() function, third is process the file using
suitable function and the last is close the file using fclose() function.

8.10 Declaring File

A declaration provides basic attributes of a symbol: its type and its name. A definition
provides all of the details of that symbol--if it's a function, what it does; if it's a class,
what fields and methods it has; if it's a variable, where that variable is stored. Often,
the compiler only needs to have a declaration for something in order to compile a file
into an object file, expecting that the linker can find the definition from another file. If
no source file ever defines a symbol, but it is declared, you will get errors at link time
complaining about undefined symbols.

Example:

FILE *AddPatient;

59
8.11 Open Files

Opens the file whose name is specified in the parameter filename and associates it
with a stream that can be identified in future operations by the file pointer returned.

Example:

AddPatient = fopen("patient_info.txt", "a");

60
9.0 References (ride, 2016)
Allain, A., 2011. c programming. [Online]
Available at: http://www.cprogramming.com/declare_vs_define.html
[Accessed 3 6 2011].

Allain, A., 2016. c programming. [Online]


Available at: http://www.cprogramming.com/tutorial/c/lesson5.html
[Accessed 3 6 2016].

cplusplus, 2016. cplusplus. [Online]


Available at: http://www.cplusplus.com/reference/cstdio/fopen/
[Accessed 3 6 2016].

ride, c., 2016. loop. [Online]


Available at: http://www.careerride.com/C++-while-do-while-for-loop.aspx
[Accessed 3 6 2016].

studytonight, 2016. studytonight. [Online]


Available at: http://www.studytonight.com/c/structures-in-c.php
[Accessed 3 6 2016].

w3schools, 2009. Online Quality Education. [Online]


Available at: http://www.w3schools.in/c/file-handling/
[Accessed 3 6 2016].

61
10.0 Conclusion

As my conclusion, c programming is very important for this hospital reservation


system. From this assignment, I learn a lot of knowledge about c programming and
also meet some problem from the c programming, like error and so on.

62

You might also like