Posts Tagged ‘์ž๋ฃŒ๊ตฌ์กฐ’

์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ

์ด๋ฒˆ์— ์ด์‚ฐ์ˆ˜ํ•™ ๊ณผ์ œ๋กœ ๋‚˜์˜จ ์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ……

๊ทธ๋ž˜ํ”„ ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ๊ฝค๋‚˜ ๋งŽ์ด ์“ฐ์ธ๋‹ค๋Š”๋ฐ……

(๋ฌผ๋ก  ๋‹ค์–‘ํ•˜๊ฒŒ ์‘์šฉ ๊ฐ€๋Šฅ?!)

์ด๊ฒŒ ๊ฝค๋‚˜ ๋จธ๋ฆฌ๋ฅผ ์จ์•ผ ๋งŒ๋“œ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ผ์„œ

์ผ๋‹จ ์ดํ•ด ํ•˜๋ฉด์„œ ์™ธ์šฐ๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ฝ”๋”ฉํ•˜์˜€๋‹ค.

์—ํœด ์ด๋Ÿฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋“ฃ์ž๋งˆ์ž ๋ฐ”๋กœ ์งค์ˆ˜ ์žˆ๋‹ค๋ฉด ์–ผ๋งˆ๋‚˜ ์ข‹์„๊นŒ?

์‹ ์ด์‹œ์—ฌ ๋‚˜์—๊ฒŒ ์ฒœ์žฌ์  ์žฌ๋Šฅ์„ ์ œ๋ฐœ;;;;;

์ž์„ธํ•œ ์†Œ์Šค๋Š” ๋ฐ‘์—์„œ ๊ณ„์†~

[spoiler]

#include <stdio.h>

#include <malloc.h>


typedef struct edge // ๊ฐ„์„ ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ตฌ์กฐ์ฒด

{

int vertex[2]; // ์‹œ์ž‘์ ๊ณผ ๋์ 

int cost; // ๊ฐ€์ค‘์น˜

}Edge;

int **make_array(int n);// ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ

void read_array(FILE *file, int *G[], int n);// ํŒŒ์ผ์—์„œ ๋ฐฐ์—ด๊ฐ’ ์ฝ๊ธฐ

void convert_array_to_edge(int* G[], Edge E[], int n);// ๋ฐฐ์—ด์„ ๊ฐ„์„ ์œผ๋กœ ๋ณ€ํ™˜

void convert_edge_to_array(int* G[], Edge E[], int n, int m);// ๊ฐ„์„ ์„ ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜

void print_edgy(Edge E[], int n);// ๊ฐ„์„  ์ง‘ํ•ฉ ์ถœ๋ ฅ

void kruskal(int n, int m, Edge E[], Edge F[]);// ํฌ๋ฃจ์Šค์นผ ์•Œ๊ณ ๋ฆฌ์ฆ˜

void bubble_sort(Edge E[], int m);// ๊ฑฐํ’ˆ ์ •๋ ฌ

void find_merge(int p, int q, int U[]);// ์ง‘ํ•ฉ์„ ํ•ฉ์น˜๋Š” ํ•จ์ˆ˜

int find_set(int i, int U[]);// ํ•ด๋‹น ์ •์ ์ด ์–ด๋–ค ์ง‘ํ•ฉ์— ์†ํ•˜๋Š”์ง€ ์ฐพ๋Š” ํ•จ์ˆ˜

int main()

{

int n, m; // n๊ฐœ์˜ ์ •์ ๊ณผ m๊ฐœ์˜ ๊ฐ„์„ ์„ ์ €์žฅํ•  ๋ณ€์ˆ˜

int **G; // ๋”๋ธ” ํฌ์ธํ„ฐ๋กœ ๋™์  ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•  ๋ณ€์ˆ˜ ์„ ์–ธ

int **result; // ์ตœ์†Œ์‹ ์žฅ ํŠธ๋ฆฌ๋ฅผ ์ธ์ ‘๋ฐฐ์—ด๋กœ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜ ์„ ์–ธ


Edge *E, *F;

FILE* file;

file = fopen(”kruskal_array.txt”, “r”);

if(file == NULL) {

perror(”File open error”);

return 0;

}

fscanf(file, “%d %d”, &n, &m); // ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ m, n์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค

E = (Edge *) malloc(sizeof(Edge)*(m-1)); // ์ฒ˜์Œ ์ž…๋ ฅ ๋ฐ›์€ ๋ฐฐ์—ด์„ ๊ฐ„์„ ์œผ๋กœ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ Edge

F = (Edge *) malloc(sizeof(Edge)*(n-2)); // ์ตœ์†Œ๋น„์šฉ ์‹ ์žฅํŠธ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•  Edge

G = make_array(n); // ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ

result = make_array(n);

read_array(file, G, n); // ํŒŒ์ผ์—์„œ ๋ฐฐ์—ด ์ •๋ณด ์ฝ๊ธฐ

convert_array_to_edge(G, E, n); // ๋ฐฐ์—ด ์ •๋ณด๋ฅผ ๊ฐ„์„  ์ •๋ณด๋กœ ๋ณ€ํ™˜

printf(”\n## Kruskal ์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ ##\n”); // ํฌ๋ฃจ์Šค์นผ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋Œ๋ฆฐ ์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ๋ฅผ F ๊ฐ„์„  ์ง‘ํ•ฉ์— ์‚ฝ์ž…

kruskal(n, m, E, F); // ์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ ๊ฒฐ๊ณผ ์ถœ๋ ฅ

printf(”\n์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ ๊ฒฐ๊ณผ\n”);

print_edgy(F, n);

printf(”\n์ตœ์†Œ ๋น„์šฉ ์‹ ์žฅ ํŠธ๋ฆฌ ๊ฒฐ๊ณผ(์ธ์ ‘ ๋ฐฐ์—ด)\n”);

convert_edge_to_array(result, F, n, m); // n-1๊ฐœ์˜ ๊ฐ„์„ ์ด F์— ํฌํ•จ๋˜๋ฏ€๋กœ

fclose(file);

return 0;

}


void print_edgy(Edge E[], int n) // ๊ฐ„์„  ์ง‘ํ•ฉ ์ถœ๋ ฅ

{

int i;

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

if(E[i].cost != 0)

printf(”v%d -> v%d, ๊ฐ€์ค‘์น˜ = %d\n”, E[i].vertex[0]+1, E[i].vertex[1]+1, E[i].cost);

}

}


int** make_array(int n) // N x N ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ

{

int i, j;

int** array; // N x N ๋™์  ๋ฐฐ์—ด์„ ํ• ๋‹น๋ฐ›์„ ๋”๋ธ” ํฌ์ธํ„ฐ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ

n–;

array = (int**)malloc(sizeof(int*)*n);

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

array[i] = (int*)malloc(sizeof(int)*n);

}


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

for (j = 0; j <= n; j++) {

array[i][j] = 0;

}

}


return array; // array์˜ ์ฃผ์†Œ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค

}


void read_array(FILE *file, int *G[], int n) // ํŒŒ์ผ์—์„œ ๋ฐฐ์—ด ๊ฐ’์„ ์ฝ์–ด ๋ฐฐ์—ด G์— ์ €์žฅ

{

int i, j;

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

for(j = 0; j < n; j++) {

fscanf(file, “%d”, &G[i][j]);

}

}

}


void convert_array_to_edge(int *G[], Edge E[], int n)// ๋ฐฐ์—ด ์ •๋ณด๋ฅผ ๊ฐ„์„  ์ •๋ณด๋กœ ๋ณ€ํ™˜

{

int i, j, num = 0;

for(i = 0; i < n; i++) { // ๋ฐฐ์—ด์˜ ์ •๋ณด๋ฅผ ๊ฐ„์„  ๊ตฌ์กฐ์ฒด์— ์‚ฝ์ž…

for(j = i; j < n; j++) {

if( G[i][j] != 0 && G[i][j] != 99 ) { // ๊ฐ€์ค‘์น˜์˜ ๊ฐ’์ด 1์—์„œ 99 ์‚ฌ์ด๋กœ ์กด์žฌํ• ๋•Œ

E[num].vertex[0] = i; // i๋ฅผ ๋ฐฐ์—ด ์ฒซ๋ฒˆ์งธ ์š”์†Œ์— ๋„ฃ๋Š”๋‹ค(๊ฐ„์„ ์˜ ์‹œ์ž‘์ )

E[num].vertex[1] = j; // j๋ฅผ ๋ฐฐ์—ด ๋‘๋ฒˆ์งธ ์š”์†Œ์— ๋„ฃ๋Š”๋‹ค(๊ฐ„์„ ์˜ ๋์ )

E[num].cost = G[i][j]; // ๊ฐ€์ค‘์น˜๋ฅผ ๋„ฃ๋Š”๋‹ค

num++; // E์˜ ๋‹ค์Œ๋ฐฐ์—ด์„ ์ฆ๊ฐ€์‹œ์ผœ์ค€๋‹ค

}

}

}

}


void convert_edge_to_array(int* G[], Edge F[], int n, int m)

{

int i, j;

int sum = 0;

int num = 0;

while (num < m) {

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

if (F[num].vertex[0] == i) {

for (j = 0; j < n; j++) {

if (F[num].vertex[1] == j) {

G[j][i] = F[num].cost;

G[i][j] = F[num].cost;

sum += F[num].cost;

continue;

}

}

}

}

num++;

}

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

for (j = 0; j < n; j++) {

printf(”%2d “, G[i][j]);

}

printf(”\n”);

}

printf(”์ด๋น„์šฉ : %d\n”, sum);

}

void kruskal(int n, int m, Edge E[], Edge F[]) // ํฌ๋ฃจ์Šค์นผ ์•Œ๊ณ ๋ฆฌ์ฆ˜

{

int start_vertex, end_vertax, i, current_edge;

int p, q; // ์„œ๋กœ์†Œ ์ฒดํฌ๋ฅผ ์œ„ํ•œ ์ง‘ํ•ฉ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ณ€์ˆ˜

int num = 0;

int* U = (int*)malloc(sizeof(int)*(n-1)); // ์ง‘ํ•ฉ ์„ ์–ธ

Edge edge_temp;

printf(”\n์ •๋ ฌ ์ „ Edge E\n”);

print_edgy(E, m);

bubble_sort(E, m); // E์— ์†ํ•œ m๊ฐœ์˜ ๊ฐ„์„ ์„ ๊ฐ€์ค‘์น˜๊ฐ€ ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ์ •๋ ฌ

printf(”\n์ •๋ ฌ ํ›„ Edge E\n”);

print_edgy(E, m);

for (i = 0; i < n; i++) {// ์ง‘ํ•ฉ Initialize

U[i] = i;

}

current_edge = 0;

while(num < n-1) { // ๊ฐ„์„ ์˜ ์ˆ˜๊ฐ€ n-1๋ณด๋‹ค ์ž‘์„ ๋™์•ˆ

edge_temp = E[current_edge]; // ์•„์ง ๊ณ ๋ คํ•˜์ง€ ์•Š์€ ๊ฐ„์„  ์ค‘ ๊ฐ€์ค‘์น˜๊ฐ€ ์ตœ์†Œ์ธ ๊ฐ„์„ 

start_vertex = E[current_edge].vertex[0]; // i, j = e์— ์—ฐ๊ฒฐ๋œ ์ •์ 

end_vertax = E[current_edge].vertex[1];

p = find_set(start_vertex, U); // start_vertax๊ฐ€ ์†ํ•˜๋Š” ์ง‘ํ•ฉ์„ p์— ์ €์žฅ

q = find_set(end_vertax, U); // end_vertax๊ฐ€ ์†ํ•˜๋Š” ์ง‘ํ•ฉ์„ q์— ์ €์žฅ

if(p != q ) { // p์™€ q ๊ฐ€ ์„œ๋กœ ์†ํ•œ ์ง‘ํ•ฉ์ด ๋‹ค๋ฅด๋‹ค๋ฉด

find_merge(p, q, U); // p, q๊ฐ€ ์†ํ•œ ์ง‘ํ•ฉ์„ ํ•ฉ์นจ

F[num] = edge_temp; // edge_temp๋ฅผ F์— ์ถ”๊ฐ€

num++;

}

current_edge++;

}

}

int find_set(int i, int U[]) // i๊ฐ€ ์ง‘ํ•ฉ U์˜ ์–ด๋А ์ง‘ํ•ฉ์— ์†ํ•˜๋‚˜?

{

int j;

j = i;

while(U[j] != j) {

j = U[j];

}

return j;

}

void find_merge(int p, int q, int U[]) // p, q๋ฅผ ์ง‘ํ•ฉ U์— ํ•ฉ์นฉ

{

if (p < q) { // p๋Š” ํ•ฉ๋ณ‘๋œ ์ง‘ํ•ฉ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ

U[q] = p; // q๋Š” ๋” ์ด์ƒ ์ง‘ํ•ฉ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ๊ฐ€ ์•„๋‹˜

}

else {

U[p] = q;

}

}

void bubble_sort(Edge E[], int m) // E ์—ฃ์ง€ ์ง‘ํ•ฉ์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์ •๋ ฌํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜

{

int i, Sorted = 0;

Edge tmp;

while( !S
orted ) {// ์ •๋ ฌ์ด ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์œผ๋ฉด

Sorted = 1;

for(i = 1; i < m; i++) {

if( E[i-1].cost > E[i].cost ) {

tmp = E[i-1];

E[i-1] = E[i];

E[i] = tmp;

Sorted = 0;

}

}

}

}

[/spoiler]

์ž๋ฃŒ๊ตฌ์กฐ 4๋ฒˆ๊ณผ์ œ(์ž…, ํ‡ด์› ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ)

์ด๋ฒˆ์— ๋งŒ๋“  ํ”„๋กœ๊ทธ๋žจ์€ ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ด์šฉํ•œ

๊ฐ„๋‹จํ•œ? ์ž…,ํ‡ด์› ๋ฐ ๋ณ‘์‹ค ๋ฐ ๋ณ‘๋™ ์ž…์›ํ˜„ํ™ฉ์„ ์•Œ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค.

ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ํ™˜์ž์™€ ๋ณ‘์‹ค ๋ชฉ๋ก์„ ์ด์šฉํ•ด์„œ

๋ณ‘์‹ค ์ •๋ณด ์•ˆ์— ๋งํฌ๋“œ๋ฆฌ์ŠคํŠธ๋กœ ์ž…์›์ค‘์ธ ํ™˜์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒŒ

๊ธฐ๋ณธ์ ์ธ ์•„์ด๋””์–ด๋‹ค.

ํ‡ด์›์€ ๋ฐ˜๋Œ€๋กœ ๋งํฌ๋“œ๋ฆฌ์ŠคํŠธ์—์„œ ์ œ์™ธํ•˜๋Š”๊ฒƒ.

ํ™˜์ž ๋ชฉ๋ก์€ ํ˜„์žฌ ์ž…์›์ค‘์ธ ํ™˜์ž์™€ ํ‡ด์›ํ•œ ํ™˜์ž 2๊ฐ€์ง€ ๊ฒฝ์šฐ๋กœ ๋‚˜๋ˆ„์–ด

์ƒ๊ฐํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ชฉ๋ก์„ ๊ฐ๊ฐ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ž…์› ๋ฐ ํ‡ด์›์‹œ ๊ฐ๊ฐ ๋ชฉ๋ก์œผ๋กœ ์˜ฎ๊ฒจ์ฃผ์–ด์•ผ ๋˜๋Š” ๋‹จ์ ์ด ์žˆ์ง€๋งŒ

๋”ฐ๋กœ ๊ด€๋ฆฌ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ํŽธ๋ฆฌํ•œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค.

[spoiler "์†Œ์Šค ๋‚ด์šฉ"]

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <string>

#include <time.h>

using namespace std;

#pragma warning(disable:4996) // warning ์„ ๊ฐ์ถฐ์ฃผ๋Š” ๋งคํฌ๋กœ

#define MAX_PATIENTS 100 // ์ตœ๋Œ€ ํ™˜์ž์ˆ˜

#define MAX_ROOMS 100 // ์ตœ๋Œ€ ๋ฐฉ์ˆ˜

#define MAX_CLINICAL_PARTS 10 // ์ตœ๋Œ€ ์ง„๋ฃŒ๋ถ€์„œ์ˆ˜

#define MAX_LENGTH 20 // ์ตœ๋Œ€๊ธธ์ด

#define MAX_DATE_LEN 9 // “yyyymmdd”

#define EMPTY “”

#define EMPTY_DATE “0″ // empty data of in_date or out_date

#define EMPTY_ROOM -1

#define EMPTY_PATIENT -1

#define DUMMY_P_ID -999 // ๋ณ‘์‹ค ์ž…์› ํ™˜์ž ๋ชฉ๋ก ๋”๋ฏธ๋…ธ๋“œ์˜ Patient ID ๊ฐ’

#define SUCCESS 1

#define NOT_FOUND -1

#define CHECKED_IN -2 // ์ž…์›์ค‘์ธ ํ™˜์ž

#define CHECKED_OUT -3 // ํ‡ด์›ํ•œ ํ™˜์ž

#define WANT_TO_QUIT -999

#define TRUE 1

#define FALSE 0

// menu constants

#define CHECK_IN 1

#define CHECK_OUT 2

#define INQUIRY 3

#define EXIT 4

void get_date(char date[]);

int get_menu();

//ํ™˜์ž ๊ด€๋ จ ํด๋ž˜์Šค

class Patient {

int patient_id; // ๊ณ ์œ  ๋ฒˆํ˜ธ

char patient_name[MAX_LENGTH];

char sex; // F:female, M:male

int age;

char insurance; // Y:๊ฐ€์ž…, N:๋ฏธ๊ฐ€์ž…

char clinic_part;

char in_date[MAX_DATE_LEN]; // yyyymmdd

int room_no; // ํ˜„์žฌ ์ž…์›์ค‘์ธ ํ™˜์ž: ๋ณ‘์‹ค๋ฒˆํ˜ธ, ํ‡ด์›ํ™˜์ž:NULL

char out_date[MAX_DATE_LEN]; // ํ˜„์žฌ ์ž…์›์ค‘์ธ ํ™˜์ž: EMPTY, ํ‡ด์›ํ™˜์ž:ํ‡ด์›์ผ

public:

Patient() { // ์ƒ์„ฑ์ž

patient_id=EMPTY_PATIENT; strcpy(patient_name, “”);

sex=0; age=0; insurance=’N';

clinic_part=0;

strcpy(in_date, “”);

room_no = EMPTY_ROOM, strcpy(out_date, “”);

}

Patient(int p_id, char *p_name, char p_sex, int p_age, char p_insurance, char p_clinic_part, char *p_in_date, int r_no, char *p_out_date) { // ์ƒ์„ฑ์ž ์˜ค๋ฒ„๋ผ์ด๋”ฉ

patient_id=p_id;

strncpy(patient_name, p_name, MAX_LENGTH);

sex=p_sex;

age=p_age;

insurance=p_insurance;

clinic_part=p_clinic_part;

strncpy(in_date, p_in_date, MAX_DATE_LEN);

room_no = r_no;

strncpy(out_date, p_out_date, MAX_DATE_LEN);

}

~Patient() { } // ํŒŒ๊ดด์ž

void setPatientId(int p_id) { patient_id = p_id; } //ํ™˜์ž ID ์ €์žฅ

int getPatientId() { return patient_id; } //ํ™˜์ž ID ๋ฐ˜ํ™˜

char* getPatientName() { return patient_name; } //ํ™˜์ž ์ด๋ฆ„๋ฐ˜ํ™˜

char getSex() { return sex; } //ํ™˜์ž ์„ฑ๋ณ„ ๋ฐ˜ํ™˜

int getAge() { return age; } // ํ™˜์ž ๋‚˜์ด ๋ฐ˜ํ™˜

char getInsurance() { return insurance; } // ํ™˜์ž ๋ณดํ—˜์—ฌ๋ถ€ ๋ฐ˜ํ™˜

char getClinicPartId() { return clinic_part; } // ์ง„๋ฃŒ๋ถ€์„œ ๋ฐ˜ํ™˜

char* getInDate() { return in_date; } // ์ž…์›์ผ์ž ๋ฐ˜ํ™˜

int getRoomNo() { return room_no; } // ์ž…์›๋ณ‘์‹ค ๋ฐ˜ํ™˜

char* getOutDate() { return out_date;} // ํ‡ด์›์ผ์ž ๋ฐ˜ํ™˜

void setRoomNo(int room) { room_no = room; }

void SetOutDate(char date[]) { strcpy(out_date, date); }

};

// ํ™˜์ž ๋ชฉ๋ก ํด๋ž˜์Šค

class PatientList {

int max_number;

int patient_count;

Patient *patient_list; // ํ™˜์ž ๋ชฉ๋ก์˜ ๋ฐฐ์—ด

public:

PatientList() {max_number=MAX_PATIENTS; patient_count=0; patient_list = new Patient[MAX_PATIENTS];}

PatientList(int n) {max_number=n; patient_count=0; patient_list = new Patient[n];}

~PatientList() { delete[] patient_list;}

int getMaxNumber() { return max_number; }

int getPatientCount() { return patient_count; }

Patient *getPatientList() { return patient_list;}

Patient getPatient(int index) {return patient_list[index];}

void InsertPatient(Patient p);

void deletePatient(int p_index);

int findPatientByIndex(int p_id); // ID๋ฅผ ์ด์šฉํ•ด ํ™˜์ž ๋ชฉ๋ก ๊ฒ€์ƒ‰ํ›„ ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜

void SortPatientList();

};

// ํ™˜์ž ์ •๋ณด ํ—จ๋“ค๋ง ํด๋ž˜์Šค

class PatientDataHandler {

ifstream in;

ofstream out; // ํŒŒ์ผ ์ถœ๋ ฅ์šฉ out์„ ์„ ์–ธ

void OpenPatientFile(char *fname) {in.open(fname);}

void SavePatientFile(char *fname) {out.open(fname);}

void ClosePatientFile() {in.close();}

void CloseSavePatientFile() {out.close();}

Patient getPatientFromFile(); // ํ™˜์ž ์ •๋ณด๋ฅผ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.

public:

PatientDataHandler() {}

~PatientDataHandler() {}

int getPatientIdFromKeyboard(); // ํ‚ค๋ณด๋“œ๋กœ๋ถ€ํ„ฐ ํ™˜์žID๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ๋ฐ˜ํ™˜ํ•ด์คŒ

Patient getPatientDataFromKeyboard(int p_id); // ํ‚ค๋ณด๋“œ๋กœ๋ถ€ํ„ฐ ํ™˜์ž์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›์Œ

void getPatientsFromFile(char *fname, PatientList *in_p_list, PatientList *out_p_list); //ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ™˜์ž๋ชฉ๋ก์„ ์ž…๋ ฅ๋ฐ›์Œ

void savePatientToFile(char *fname, PatientList *in_p_list, PatientList *out_p_list); // ํ™˜์ž ๋ชฉ๋ก์„ ํŒŒ์ผ๋กœ ์ €์žฅํ•จ

};

// ๋ณ‘์‹ค ์ •๋ณด์— ์—ฐ๊ฒฐ๋  ํ™˜์ž NODE ํด๋ž˜์Šค

class PatientNode

{

int patient_id;

PatientNode * pNext; // ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ํฌ์ธํ„ฐ

public:

PatientNode() {}

PatientNode(int p_id) {patient_id = p_id; pNext = NULL; }

~PatientNode() {};

int getPatientId() { return patient_id; }

PatientNode* getPatientNodepNext() { return pNext;}

void SetPatientNodepNext(PatientNode *p_pNext) { pNext = p_pNext;}

};

// ์ง„๋ฃŒ๋ถ€์„œ ํด๋ž˜์Šค

class ClinicPart

{

char part_id; // ์ง„๋ฃŒ๋ถ€์„œ ์ฝ”๋“œ

char part_name[MAX_LENGTH]; // ์ง„๋ฃŒ๋ถ€์„œ ์ด๋ฆ„

int ward_no; // ๋ณ‘๋™ ์ธ๋ฑ์Šค

public:

ClinicPart() {part_id = 0; strcpy(part_name, “”); ward_no=0;}

ClinicPart(int p_id, char *p_name, int w_no) {part_id = p_id; strcpy(part_name, p_name); ward_no = w_no; }

~ClinicPart(){}

char getPartId() {return part_id;}

char* getPartName() {return part_name;}

int getWardNo() {return ward_no;}

};

// ์ง„๋ฃŒ๋ถ€์„œ ๋ชฉ๋ก ํด๋ž˜์Šค

class ClinicPartTable

{

int count; // ํ˜„์žฌ ์ง„๋ฃŒ๋ถ€์„œ์˜ ์ˆ˜

ClinicPart * clinicPartTable; // ์ง„๋ฃŒ๋ถ€์„œ ๋ฐฐ์—ด

public:

ClinicPartTable();

~ClinicPartTable() { delete[] clinicPartTable; }

ClinicPart getClinicPartId(char pId); // ์ง„๋ฃŒ๋ถ€์„œ ์ฝ”๋“œ์— ํ•ด๋‹นํ•˜๋Š” ์ง„๋ฃŒ๋ถ€์„œ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์†Œ๋“œ

ClinicPart getClinicPartId(int roomNo); // ๋ณ‘์‹ค ๋ฒˆํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” ์ง„๋ฃŒ๋ถ€์„œ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์†Œ

};

// ๋ณ‘์‹ค ์ •๋ณด ํด๋ž˜์Šค

class Room

{

int room_no; // ๋ณ‘์‹ค๋ฒˆํ˜ธ

int capacity; // ์ˆ˜์šฉ์ธ์›

char sex; // B:both, F:female, M:male

int count; // ํ˜„์žฌ ์ž…์› ํ™˜์ž ์ˆ˜

public:

PatientNode *p_list; // ํ•ด๋‹น ๋ณ‘์‹ค ์ž…์›ํ™˜์ž ๋ชฉ๋ก์— ๋Œ€ํ•œ ํฌ์ธํ„ฐ, ๋”๋ฏธ ๋…ธ๋“œ ์‚ฌ์šฉ

public:

Room() { room_no=EMPTY_ROOM; capacity=0; sex=’ ‘; count=0; p_list=new PatientNode(DUMMY_P_ID); }

Room(int r_no, int r_capa, char r_sex) { room_no=r_no; capacity=r_c
apa; sex=r_sex, count=0; p_list=new PatientNode(DUMMY_P_ID); }

~Room(){}

int getRoomNo() { return room_no; }

int getCapacity() { return capacity; }

char getSex() { return sex;}

int getCount() { return count; }

PatientNode * getPatinetList() { return p_list; }

void insertPatient(PatientNode* p); // ํ™˜์ž ๋…ธ๋“œ๋ฅผ ๋ณ‘์‹ค ์ •๋ณด์— ์‚ฝ์ž…

int deletePatient(int p_id); // ๋„˜๊ฒจ๋ฐ›์€ ID๋กœ ํ™˜์ž ์ •๋ณด ์‚ญ์ œ

};

// ๋ณ‘์‹ค ๋ชฉ๋ก ํด๋ž˜์Šค

class RoomList

{

int max_number; // ์ตœ๋Œ€ ๋ณ‘์‹ค ๊ฐฏ์ˆ˜

int count; // ํ˜„์žฌ ๋ณ‘์‹ค์˜ ๊ฐฏ์ˆ˜

Room *room_list; // ๋ณ‘์‹ค ๋ชฉ๋ก์˜ ๋ฐฐ์—ด

public:

RoomList() {max_number = MAX_ROOMS; count = 0; room_list = new Room[MAX_ROOMS]; };

RoomList(int n) {max_number = n; count = 0; room_list = new Room[n]; };

~RoomList(){}

int getCount() { return count;}

int getRoomIndex(int room_no);

Room * getRoom(int index) { return &room_list[index];}

void loadPatientsIntoRoom(PatientList &in_p_list); // ์ฝ์–ด์˜จ ํ™˜์ž ์ •๋ณด๋ฅผ ๋ณ‘์‹ค์— ์‚ฝ์ž…

int findRoomIndexForCheckIn(char clinicPart_id, char sex); // ์„ฑ๋ณ„๊ณผ ์ง„๋ฃŒ๋ถ€์„œ์— ๋งž๋Š” ๋ณ‘์‹ค์„ ์ฐพ์•„ ๋ณ‘๋™๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜

void insertRoom(Room r); // ๋ณ‘์‹ค ์ •๋ณด๋ฅผ ์‚ฝ์ž…

};

// ๋ณ‘์‹ค ์ •๋ณด ํ•ธ๋“ค๋Ÿฌ ํด๋ž˜์Šค

class RoomDataHandler

{

ifstream in;

void openRoomFile(char *fname) { in.open(fname); }

void closeRoomFile() { in.close(); }

Room getRoomFromFile(); // ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ๋ณ‘์‹ค ์ •๋ณด๋ฅผ ์ฝ์–ด์˜จํ›„ ๋ฐ˜ํ™˜ํ•œ๋‹ค

public:

RoomDataHandler(){}

~RoomDataHandler(){}

int getClinicPartIdIdFromKeyboard(); // ์ง„๋ฃŒ๋ถ€์„œ๋ฅผ ํ‚ค๋ณด๋“œ๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

void getRoomListFromFile(char *fname, RoomList *r_list); // ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ๋ณ‘์‹ค ์ •๋ณด๋ฅผ ์ฝ์–ด์™€ ๋ณ‘์‹ค ๋ชฉ๋ก์„ ๋งŒ๋“ ๋‹ค

};

// ์‚ฌ์šฉ์ž๋กœ ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ๋ฉ”๋‰ด๋ฅผ ์ง„ํ–‰

class RoomListProcessor {

public :

RoomListProcessor() {};

~RoomListProcessor() {};

void checkInHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list);

void checkOutHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list);

void inquiryHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list);

};

// ===== Class ์ •์˜ ์‹œ์ž‘======

void PatientList::InsertPatient(Patient p)

{

if(patient_count >= max_number) {

cout << “ํ™˜์ž ์ •๋ณด๋ฅผ ์ €์žฅํ•  ๊ณต๊ฐ„์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.\n” << endl;

exit(1);

}

patient_list[patient_count] = p;

patient_count++;

}

void PatientList::deletePatient(int p_index)

{

int i;

if (patient_count == 0) {

cout << “Patient List Empty!!” << endl;

return;

}

for (i = p_index; i < patient_count; i++) {

patient_list[i] = patient_list[i+1];

}

patient_count–;

}

// ID๋ฅผ ์ด์šฉํ•ด ํ™˜์ž ๋ชฉ๋ก ๊ฒ€์ƒ‰ํ›„ ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜

int PatientList::findPatientByIndex(int p_id)

{

for(int i=0; i<patient_count; i++ )

if(p_id == patient_list[i].getPatientId()) return i;

return NOT_FOUND;

}

// ๋ฒ„๋ธ” sort ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ด์šฉํ•œ ์ •๋ ฌ

void PatientList::SortPatientList()

{

Patient temp; // ์Šค์™‘์„ ์œ„ํ•œ temp

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

int min = i;

for(int j=i+1; j<patient_count; j++)

if(patient_list[j].getPatientId() < patient_list[min].getPatientId())

min = j;

if(min != i) {

temp = patient_list[i];

patient_list[i] = patient_list[min];

patient_list[min]= temp;

}

}

}

int PatientDataHandler::getPatientIdFromKeyboard()

{

int p_id;

cout << “\nType patient id, (quit to ” << WANT_TO_QUIT << ” )==> “;

cin >> p_id;

return p_id;

}

// ํ™˜์ž ์ •๋ณด๋ฅผ ํ‚ค๋ณด๋“œ๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค

Patient PatientDataHandler::getPatientDataFromKeyboard(int p_id)

{

char name[MAX_LENGTH];

char sex; // F:female, M:male

int age;

char insurance; // Y:๊ฐ€์ž…, N:๋ฏธ๊ฐ€์ž…

char clinic_part;

char in_date[MAX_DATE_LEN];

char out_date[MAX_DATE_LEN];

// ID๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์ •๋ณด๋ฅผ ํ‚ค๋ณด๋“œ๋กœ ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

cout << “\nType a patient name ==> “;

cin >> name;

cout << “\nType sex of patient. (F:female, M:male) ==> “;

cin >> sex;

cout << “\nType age of patient ==> “;

cin >> age;

cout << “\nType insurance. (0:๋ฏธ๊ฐ€์ž…, 1:๊ฐ€์ž…) ==> “;

cin >> insurance;

cout << “\nType a clinical part id. ==> “;

cin >> clinic_part;

get_date(in_date); // ์ž…์›์ผ์ž๋ฅผ ํ˜„์žฌ๋‚ ์งœ๋กœ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

strcpy(out_date, “”); // ํ‡ด์›์ผ์ž์— “”๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

Patient p(p_id, name, sex, age, insurance, clinic_part, in_date, EMPTY_ROOM, out_date); // ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์œผ๋กœ Patient ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑ

return p; // Patient ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค.

}

// ํ™˜์ž ์ •๋ณด๋ฅผ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ์ €์žฅ๋ฐ›๊ณ  ์ €์žฅ๋ฐ›์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

Patient PatientDataHandler::getPatientFromFile()

{

int id;

char name[MAX_LENGTH];

char sex; // F:female, M:male

int age;

char insurance; // Y:๊ฐ€์ž…, N:๋ฏธ๊ฐ€์ž…

char clinic_part;

char in_date[MAX_LENGTH];

int room_no;

char out_date[MAX_LENGTH];

if( in.eof() ) {

Patient p(EMPTY_PATIENT,”", 0, 0, 0, 0, “”, 0, “”);

return p;

}

in >> id >> name >> sex >> age >> insurance >> clinic_part >> in_date >> room_no >> out_date;

Patient p(id, name, sex, age, insurance, clinic_part, in_date, room_no, out_date);

return p;

}

// ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ์ฝ์–ด๋“ค์ธ ํ™˜์ž ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ํ™˜์ž ๋ชฉ๋ก์„ ๋งŒ๋“ ๋‹ค

void PatientDataHandler::getPatientsFromFile(char *fname, PatientList *in_p_list, PatientList *out_p_list)

{

Patient p;

OpenPatientFile(fname);

while(1) { // ํŒŒ์ผ๋กœ ๋ถ€ํ„ฐ ์ฝ์–ด์˜จ ํ™˜์ž ์ •๋ณด๊ฐ€ NULL ๊ฐ’์„ ๊ฐ€์งˆ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต

p = getPatientFromFile();

if (p.getPatientId() == EMPTY_PATIENT) break;

if ( strcmp(p.getOutDate(), EMPTY_DATE) == 0) in_p_list->InsertPatient(p); // ์ž…์›ํ™˜์ž ๋ชฉ๋ก์„ ๋งŒ๋“ ๋‹ค

else out_p_list->InsertPatient(p); // ํ‡ด์›ํ™˜์ž ๋ชฉ๋ก์„ ๋งŒ๋“ ๋‹ค

}

ClosePatientFile();

}

void PatientDataHandler::savePatientToFile(char *fname, PatientList *in_p_list, PatientList *out_p_list)

{

Patient p;

SavePatientFile(fname);

int i;

for (i = 0; i < in_p_list->getPatientCount(); i++) {

p = in_p_list->getPatient(i);

out << p.getPatientId() <<” “<< p.getPatientName() << ” ” << p.getSex() << ” ” << p.getAge() << ” ” << p.getInsurance() << ” ” << p.getClinicPartId() << ” ” << p.getInDate() << ” ” << p.getRoomNo() << ” ” << “0″ << endl;

}

for (i = 0; i < out_p_list->getPatientCount(); i++) {

p = out_p_list->getPatient(i);

out << p.getPatientId() <<” “<< p.getPatientName() << ” ” << p.getSex() << ” ” << p.getAge() << ” ” << p.getInsurance() << ” ” << p.getClinicPartId() << ” ” << p.getInDate() << ” ” << p.getRoomNo() << ” ” << p.getOutDate() << endl;

}

CloseSavePatientFile();

}

// ์ง„๋ฃŒ๋ถ€์„œ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ ๋‹ค

ClinicPartTable::ClinicPartTable()

{

cli
nicPartTable = new ClinicPart[5];

clinicPartTable[0] = ClinicPart(’A', “๋‚ด๊ณผ”, 61);

clinicPartTable[1] = ClinicPart(’B', “์™ธ๊ณผ”, 62);

clinicPartTable[2] = ClinicPart(’C', “์‹ ๊ฒฝ๊ณผ”, 63);

clinicPartTable[3] = ClinicPart(’D', “์†Œ์•„๊ณผ”, 64);

clinicPartTable[4] = ClinicPart(’E', “์‚ฐ๋ถ€์ธ๊ณผ”, 65);

count = 5;

}

ClinicPart ClinicPartTable::getClinicPartId(char pId)

{

for(int i=0; i<count; i++)

if(clinicPartTable[i].getPartId() == pId) return clinicPartTable[i];

return ClinicPart(NOT_FOUND, NULL, 0); // NOT_FOUND

}

ClinicPart ClinicPartTable::getClinicPartId(int roomNo)

{

for(int i=0; i<count; i++)

if( clinicPartTable[i].getWardNo() == (roomNo/10) ) return clinicPartTable[i];

return ClinicPart(NOT_FOUND, NULL, 0); // NOT_FOUND

}

// ํ™˜์ž ๋…ธ๋“œ๋ฅผ ์—ฐ๊ฒฐํ•ด์ค€๋‹ค.(๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ)

void Room::insertPatient(PatientNode* p)

{

PatientNode *ptr = p_list;

// ๋”๋ฏธ ๋‹ค์Œ Node๋กœ ์—ฐ๊ฒฐ

p->SetPatientNodepNext(ptr->getPatientNodepNext());

ptr->SetPatientNodepNext(p);

count++;

}

// ํ™˜์ž ๋…ธ๋“œ๋ฅผ ์‚ญ์ œํ•œ๋‹ค.

int Room::deletePatient(int p_id)

{

PatientNode *ptr = p_list;

PatientNode *trail;

while(ptr != NULL) {

if(ptr->getPatientId()== p_id) {

trail->SetPatientNodepNext(ptr->getPatientNodepNext());

delete ptr; // ptr ์„ ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œ ํ•ด์คŒ

count–; // ํ˜„์žฌ ํ™˜์ž์ˆ˜๋ฅผ -1 ํ•ด์คŒ

return SUCCESS;

}

trail = ptr;

ptr = ptr->getPatientNodepNext();

}

return NOT_FOUND;

}

void RoomList::loadPatientsIntoRoom(PatientList &in_p_list)

{

int p_list_count = in_p_list.getPatientCount();

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

// ํ™˜์ž ๋ฐ์ดํ„ฐ ํ•˜๋‚˜ ์„ ํƒ

Patient p = in_p_list.getPatient(i);

// ๊ธฐ์กด ์ž…์› ๋ณ‘์‹ค์„ ์„ ํƒ

int roomNo = p.getRoomNo();

int r_index = getRoomIndex(roomNo);

if( r_index == NOT_FOUND) {

cout << “์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ณ‘์‹ค ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.” << endl;

continue;

}

Room *room = getRoom(r_index);

if( room->getCount() >= room->getCapacity() ) {

cout << “์ž…์› ๊ฐ€๋Šฅ ํ™˜์ž์ˆ˜๋ฅผ ์ดˆ๊ณผํ•˜์—ฌ ” << p.getPatientId() << “ํ™˜์ž๋Š” ์ฒ˜๋ฆฌ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.” << endl;

continue;

}

// ํ™˜์ž ๋…ธ๋“œ ๋งŒ๋“ค์–ด์„œ ๋ณ‘์‹ค์— ํ™˜์ž ์‚ฝ์ž…

PatientNode *pNode = new PatientNode(p.getPatientId());

room->insertPatient(pNode);

}

}

int RoomList::findRoomIndexForCheckIn(char clinicPart_id, char sex)

{

ClinicPartTable clinicPartTable;

ClinicPart clinicPart;

Room room;

char r_sex;

clinicPart = clinicPartTable.getClinicPartId(clinicPart_id);

// ์ž…์› ๊ฐ€๋Šฅํ•œ ๋ณ‘์‹ค์„ ์ฐพ๋Š” ์กฐ๊ฑด ๊ฒ€์‚ฌ

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

room = room_list[i];

if( room.getRoomNo()/10 != clinicPart.getWardNo() ) continue;

r_sex = room.getSex();

if( r_sex != ‘B’ && r_sex != sex ) continue;

if( room.getCount() >= room.getCapacity()) continue;

return i;

}

return NOT_FOUND;

}

int RoomList::getRoomIndex(int room_no)

{

for(int i=0; i<count; i++)

if(room_list[i].getRoomNo() == room_no) return i;

return NOT_FOUND;

}

void RoomList::insertRoom(Room r)

{

if( count >= max_number) {

cout << “๋ณ‘์‹ค ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ๊ณต๊ฐ„์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.\n” << endl;

exit(1);

}

room_list[count] = r;

count++;

}

Room RoomDataHandler::getRoomFromFile()

{

int room_no; // ๋ณ‘์‹ค๋ฒˆํ˜ธ

int capacity; // ์ˆ˜์šฉ์ธ์›

char sex; // B:both, F:female, M:male

Room nullRoom;

if( in.eof()) return nullRoom;

in >> room_no >> capacity >> sex;

Room r(room_no, capacity, sex);

return r;

}

void RoomDataHandler::getRoomListFromFile(char *fname, RoomList *r_list)

{

Room r;

openRoomFile(fname);

while(1) { // ๋ณ‘์‹ค ์ •๋ณด๊ฐ€ NULL ์ผ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต

r = getRoomFromFile();

if( r.getRoomNo() == EMPTY_ROOM ) break;

r_list->insertRoom(r);

}

closeRoomFile();

}

int RoomDataHandler::getClinicPartIdIdFromKeyboard()

{

int r_no;

cout << “\nType Room Number, (quit to ” << WANT_TO_QUIT << ” )==> “;

cin >> r_no;

return r_no;

}

void RoomListProcessor::checkInHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list)

{

Patient p;

int p_id;

int p_index; // index for patient list

int r_index; // index for room list

PatientDataHandler pdh;

while(1) {

// ํ™˜์ž ์ฝ”๋“œ๋ฅผ ๋ฐ›๋Š”๋‹ค.

p_id = pdh.getPatientIdFromKeyboard();

// ์ข…๋ฃŒ๋ฅผ ์›ํ•˜๋ฉด ์ข…๋ฃŒ

if( p_id == WANT_TO_QUIT) return ;

// ์ž…์› ํ™˜์ž ๋ชฉ๋ก์—์„œ p_id ์— ํ•ด๋‹นํ•˜๋Š” index ์–ป์–ด ์ž…์› ํ™˜์ž ์ธ์ง€ ํ™•์ธ

p_index = in_p_list.findPatientByIndex(p_id);

if( p_index != NOT_FOUND ) {

cout << “์ž…์›์ค‘์ธ ํ™˜์ž์ž…๋‹ˆ๋‹ค. ” << endl;

continue ;

}

// ํ‡ด์› ํ™˜์ž ๋ชฉ๋ก์—์„œ p_id ์— ํ•ด๋‹นํ•˜๋Š” index ์–ป์–ด ๊ธฐ์กด ํ™˜์ž ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ

p_index = out_p_list.findPatientByIndex(p_id);

if( p_index == NOT_FOUND )

p = pdh.getPatientDataFromKeyboard(p_id); // ์ƒˆ ํ™˜์ž ์ž…๋ ฅ

else

p = out_p_list.getPatient(p_index); // existing patient

// ์ง„๋ฃŒ๊ณผ ์ฝ”๋“œ์— ํ•ด๋‹นํ•˜๋Š” ๋ณ‘์‹ค ๋ชฉ๋ก์—์„œ ์ž…์› ํ•  ์ˆ˜ ์žˆ๋Š” ๋ณ‘์‹ค์˜ index ์ฐพ๊ธฐ

r_index = room_list.findRoomIndexForCheckIn(p.getClinicPartId(), p.getSex());

if( r_index == NOT_FOUND) {

cout << “ํ•ด๋‹น ์ง„๋ฃŒ ๋ถ€์„œ์—๋Š” ์ž…์› ๊ฐ€๋Šฅํ•œ ๋ณ‘์‹ค์ด ์—†์Šต๋‹ˆ๋‹ค.”;

continue;

}

// ํ•ด๋‹น ๋ณ‘์‹ค์— ํ™˜์ž ๋…ธ๋“œ ์‚ฝ์ž…

Room *room = room_list.getRoom(r_index);

p.setRoomNo(room->getRoomNo());

cout << room->getRoomNo() << ” ๋ณ‘์‹ค์— ์ž…์›” << endl;

// ์ž…์› ํ™˜์ž ๋ชฉ๋ก์— ํ™˜์ž ๋ฐ์ดํ„ฐ ์‚ฝ์ž…

in_p_list.InsertPatient(p);

PatientNode *pNode = new PatientNode(p.getPatientId());

room->insertPatient(pNode);

}

}

// ํ‡ด์› ํ”„๋กœ์„ธ์„œ ๋ฏธ๊ตฌํ˜„

void RoomListProcessor::checkOutHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list)

{

PatientDataHandler pdh;

Patient p;

int p_id;

int p_index;

int r_index;

char out_date[MAX_DATE_LEN];

while (1) {

// ํ™˜์ž ๋ฒˆํ˜ธ ์ž…๋ ฅ

p_id = pdh.getPatientIdFromKeyboard();

// ์ข…๋ฃŒ๋ฅผ ์ž…๋ ฅํ–ˆ์„ ๊ฒฝ์šฐ

if (p_id == WANT_TO_QUIT) return ;

// ์ž…์› ํ™˜์ž ๋ชฉ๋ก์—์„œ p_id์— ํ•ด๋‹นํ•˜๋Š” index๋ฅผ ์–ป์–ด ์ž…์› ํ™˜์ž์ธ์ง€ ํ™•์ธ

p_index = in_p_list.findPatientByIndex(p_id);

if (p_index == NOT_FOUND) {

cout << “์ž…์›์ค‘์ธ ํ™˜์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.” << endl;

continue;

}

// ๋ฐ˜ํ™˜๋ฐ›์€ ํ™˜์ž๋ชฉ๋ก index๋ฅผ ๊ฐ€์ง€๊ณ  ํ™˜์ž ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜๋ฐ›์Œ

p = in_p_list.getPatient(p_index);

// ํ‡ด์›์ผ์ž๋ฅผ ํ˜„์žฌ ๋‚ ์งœ๋กœ

get_date(out_date);

p.SetOutDate(out_date);

r_index = room_list.getRoomIndex(p.getRoomNo());

out_p_list.InsertPatient(p);

in_p_list.deletePatient(p_index);

Room *room = room_list.getRoom(r_index);

room->deletePatient(p_id);

}

//

}

// ์ž…์›ํ™˜์ž ํ˜„ํ™ฉ ํ”„๋กœ์„ธ์„œ

void RoomListProcessor::inquiryHandler(PatientList &in_p_list, PatientList &out_p_list, RoomList &room_list)

{

Patient p;

Room *r_node;

PatientNode *p_node;

<
p>ClinicPartTable *c_temp = new ClinicPartTable();

ClinicPart c;

int r_no; // ๋ณ‘์‹ค๋ฒˆํ˜ธ ์ž…๋ ฅ์„ ์œ„ํ•œ ๋ณ€์ˆ˜

int r_index; // ๋ณ‘์‹ค ๋ชฉ๋ก ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜๋ฐ›์„ ๋ณ€์ˆ˜

RoomDataHandler rdh;

while (1) {

// ๋ณ‘์‹ค ๋ฒˆํ˜ธ ์ž…๋ ฅ

r_no = rdh.getClinicPartIdIdFromKeyboard();

// ์‚ฌ์šฉ์ž๊ฐ€ ์ข…๋ฃŒ๋ฅผ ์„ ํƒํ–ˆ์„ ์‹œ

if (r_no == WANT_TO_QUIT) return ;

// ์ž…๋ ฅ๋ฐ›์€ ๋ณ‘์‹ค๋ฒˆํ˜ธ๋กœ ๋ฐฐ์—ด ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜๋ฐ›๋Š”๋‹ค

r_index = room_list.getRoomIndex(r_no);

// ๋ฐ˜ํ™˜๋ฐ›์€ ๋ฐฐ์—ด ์ธ๋ฑ์Šค๋กœ ์ž…๋ ฅ๋ฐ›์€ ๋ณ‘์‹ค์„ r_node์— ์ €์žฅํ•œ๋‹ค.

r_node = room_list.getRoom(r_index);

c = c_temp->getClinicPartId(r_no);

cout << “๋ณ‘๋™ : ” << c.getWardNo() << endl;

cout << “๋ณ‘์‹ค๋ฒˆํ˜ธ ํ™˜์ž์ฝ”๋“œ ํ™˜์ž์„ฑ๋ช… ์„ฑ๋ณ„ ๋‚˜์ด” << endl;

// p_node์— PatientNode->pNext ๊ฐ’์„ ๋„ฃ๊ณ  NULL ์ผ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต

for (p_node = r_node->p_list->getPatientNodepNext(); p_node; p_node = p_node->getPatientNodepNext()) {

// ํ™˜์ž ์ •๋ณด๋ฅผ Patient p์— ๋Œ€์ž…

p = in_p_list.getPatient(in_p_list.findPatientByIndex(p_node->getPatientId()));

// ํ™˜์ž ์ •๋ณด ์ถœ๋ ฅ

cout << r_node->getRoomNo() << ” ” << p.getPatientId() << ” ” <<p.getPatientName() << ” ” << p.getSex() << ” ” << p.getAge() << endl;

}

}

}

// === ํด๋ž˜์Šค ์ •์˜ ๋ถ€๋ถ„ ๋ ===

// ์˜ค๋Š˜์˜ ๋‚ ์งœ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜

void get_date(char date[])

{

time_t timer;

struct tm *t;

timer = time(NULL); // ํ˜„์žฌ ์‹œ๊ฐ์„ ์ดˆ ๋‹จ์œ„๋กœ ์–ป๊ธฐ

t = localtime(&timer); // ์ดˆ ๋‹จ์œ„์˜ ์‹œ๊ฐ„์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ตฌ์กฐ์ฒด์— ์ €์žฅ

// date์— “YYYYMMDD” ํ˜•์‹์œผ๋กœ ์ €์žฅ

sprintf(date, “%0.4d%0.2d%0.2d”, t->tm_year+1900, t->tm_mon+1, t->tm_mday);

}

// get a menu for user

int get_menu()

{

int menu;

while(1) {

// ๋ฉ”๋‰ด ์ถœ๋ ฅ

printf(” ***menu***\n”);

printf(”1) Check In\n”);

printf(”2) Check Out\n”);

printf(”3) Inquiry\n”);

printf(”4) Exit\n”);

// ๋ฉ”๋‰ด ์„ ํƒ

printf(”\nMENU ==> “);

scanf(”%d”,&menu);

if(menu >= CHECK_IN && menu <= EXIT)

return menu;

// ์ž˜๋ชป๋œ ์ž…๋ ฅ์ผ ๊ฒฝ์šฐ

printf(”\nInvalid menu!! Retry!!”);

}

}

int main()

{

PatientList in_p_list;

PatientList out_p_list;

RoomList room_list;

PatientDataHandler patient_data_handler;

RoomDataHandler room_data_handler;

RoomListProcessor roomListProcessor;

int menu;

patient_data_handler.getPatientsFromFile(”patient.dat”, &in_p_list, &out_p_list);

in_p_list.SortPatientList();

out_p_list.SortPatientList();

room_data_handler.getRoomListFromFile(”room.dat”, &room_list);

// ๋ณ‘์‹ค๋ชฉ๋ก์— ๊ธฐ์กด ์ž…์› ํ™˜์ž๋ชฉ๋ก ๋กœ๋“œ

room_list.loadPatientsIntoRoom(in_p_list);

// ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฉ”๋‰ด ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค.

while(1)

{

menu = get_menu();

if(menu == EXIT) {

patient_data_handler.savePatientToFile(”patient.dat”, &in_p_list, &out_p_list);

break;

}

switch(menu) {

case CHECK_IN:

roomListProcessor.checkInHandler(in_p_list, out_p_list, room_list);

break;

case CHECK_OUT:

roomListProcessor.checkOutHandler(in_p_list, out_p_list, room_list);

break;

case INQUIRY:

roomListProcessor.inquiryHandler(in_p_list, out_p_list, room_list);

break;

}

}

}

[/spoiler]

๊ฒŒ์‹œ ๋‚ ์งœ : 6์›” 1st, 2008
๊ธ€ ๋ถ„๋ฅ˜ : ํ”„๋กœ๊ทธ๋ž˜๋ฐ
ํƒœ๊ทธ : , , , , , , ,
๋‚จ๊น€๋ง : ํ•˜๋‚˜๋„ ์—†์–ด์šฉ!.

ํ˜„์žฌ์‹œ๊ฐ„ 8์‹œ 2๋ถ„……

์ž๋ฃŒ๊ตฌ์กฐ ๋ฐœํ‘œ

ํ•˜์ง€๋งŒ ์–ด์ œ ์˜คํ›„ 1์‹œ 30๋ถ„์— ์‹œ์ž‘ํ•œ ์ˆ˜์—…์ด

์•„์ง๊นŒ์ง€ ๋๋‚˜์ง€ ์•Š์•˜๋‹ค๋Š”๊ฑฐ……

ํ›„์ƒˆ๋“œ.. ๊ฒŒ๋‹ค๊ฐ€ ๋‚œ 10์  ๋งŒ์ ์— 8์  ๋ฐ–์— ๋ชป ๋ฐ›์•˜๋‹ค๋Š”๊ฑฐ……

ย (ํ•จ์ˆ˜ ๊ตฌ์กฐ์ ์ธ ๋ฉด์—์„œ -1์  …… ์ž๋ฃŒ๊ตฌ์กฐ ์„ค๊ณ„ ๋ถ€๋ถ„์—์„œ -1์ ….)

์˜ค ์‰ฃ!! 9์  ๋ฐ›์€ ํ•™์šฐ๋“ค๋„ ๋งŽ๊ณ 

ย ๊ทธ ์ค‘์—์„œ๋Š” ๊ต์ˆ˜๋‹˜์ด ์ธ์ •ํ•  ์ •๋„๋กœ ์ž˜ํ•œ ์• ๋“ค๋„ ๋ช‡๋ช… ์žˆ์—ˆ๋‹ค……

๋„๋Œ€์ฒด ๋‚œ ์–ธ์ œ์ฏค์ด๋ฉด ๊ทธ์ •๋„๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ์งค์ˆ˜ ์žˆ์„์ง€……

๋„ˆ๋ฌด ์Šฌํ”„๋‹ค ํ‘ํ‘……

์งค๋ฐฉ์€ ์ž๋ฃŒ๊ตฌ์กฐ ๋ฐœํ‘œ์ค‘ ์‚ฌ์ง„…..

๊ฒŒ์‹œ ๋‚ ์งœ : 5์›” 4th, 2008
๊ธ€ ๋ถ„๋ฅ˜ : ํ”„๋กœ๊ทธ๋ž˜๋ฐ
ํƒœ๊ทธ : , , ,
๋‚จ๊น€๋ง : ํ•˜๋‚˜๋„ ์—†์–ด์šฉ!.

์ž๋ฃŒ๊ตฌ์กฐ ์ฒซ๋ฒˆ์งธ ๊ณผ์ œ ๊ฒ€์‚ฌ……

๋ง๋กœ๋งŒ ๋“ฃ๋˜ ์ž„์€๊ธฐ ๊ต์ˆ˜๋‹˜์˜ ์ž๋ฃŒ๊ตฌ์กฐ ๊ณผ์ œ ๊ฒ€์‚ฌ……

ย ์‹ค์ œ๋กœ ๊ฒช์–ด๋ณด๋‹ˆ ์ผ๋‹จ ์ •์‹ ์„ ๋†“์„ ์ •๋„์˜ ์••๋ฐ•…-_-;;

ย ์•„ํœด ์ด๊ฑฐ ์–ธ์ œ ๋๋‚˜๋ ค๋‚˜……?

๋‚ด๊ฐ€ ๋งŒ๋“  ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๊ต์ˆ˜๋‹˜์ด ์“ฐ๋ ˆ๊ธฐ๋ผ๊ณ  ํ•˜์ง€๋Š” ์•Š์„์ง€ ๊ฑฑ์ •;;

์ž˜ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค๋„ ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ๊ฐ์ ์ด ๋˜๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ด๋‹ค ใ„ฒใ„ฒ

์†”์งํžˆ ๋‚ด๊ฐ€๋ด๋„ ๋‚ด ์ฝ”๋“œ์— ์“ธ๋ชจ์—†๋Š” ๊ณผ์ •๋„ ์ข€ ์žˆ๊ณ ……

๊ต์ˆ˜๋‹˜์ด ์›ํ•˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์— ๋ถ€ํ•ฉ๋˜๋Š” ๊ฑด ์•„๋‹Œ๊ฑฐ ๊ฐ™๋‹ค.

๊ทธ๋ž˜๋„ ์ผ๋‹จ ๊ณผ์ œ๋ฅผ ์™„์„ฑํ–ˆ๊ณ  ๋ฐœํ‘œ์ž ๋ช…๋‹จ์— ์ด๋ฆ„์ด ์˜ฌ๋ผ๊ฐ€ ์žˆ๋‹ค๋Š”๊ฒƒ์—

์˜์˜๋ฅผ ๊ฐ€์ง€๊ณ ……

์ด๋ฒˆ ๊ณผ์ œ ๋ฐœํ‘œ๋ฅผ ๊ณ„๊ธฐ๋กœ ์ง€์ ๋ฐ›์€ ์‚ฌํ•ญ์€

๋‹ค์Œ ๊ณผ์ œ ๋ฐœํ‘œ๋•Œ์—๋Š” ๋ชจ๋‘ ๊ณ ์น ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผ๊ฒ ๋‹ค…

(๊ณผ์—ฐ ์˜ค๋Š˜์€ ์–ธ์ œ ๋๋‚ ์ง€..??)

๊ฒŒ์‹œ ๋‚ ์งœ : 5์›” 3rd, 2008
๊ธ€ ๋ถ„๋ฅ˜ : ํ”„๋กœ๊ทธ๋ž˜๋ฐ
ํƒœ๊ทธ : , , , ,
๋‚จ๊น€๋ง : ํ•˜๋‚˜๋„ ์—†์–ด์šฉ!.