목표는 이렇게 만드는 것이다.
**기능 일람
1. 도서 검색기능이 있다. 제목, 저자, 출판사, 도서번호
2. 도서 추가, 제거 기능이 있다.
3. 도서 반납, 대출 기능이 있다.
코드는 아래와 같다.
#include <stdio.h>
char search_number(int *k, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
char search_title(int *book_num, char *search, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
char search_auth(int *book_num, char (*book_title)[100], char *search, char (*book_author)[50], char (*book_publ)[30]);
char search_publ(int *book_num, char (*book_title)[100], char (*book_author)[50], char *search, char (*book_publ)[30]);
char book_borr(int *k, char (*book_title)[100], int *book_borrow);
char book_return(int *k, char (*book_title)[100], int *book_borrow);
char book_change(int *book_num, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
int main()
{
int book_num[100];
char book_title[100][100];
char book_author[100][50];
char book_publ[100][30];
char search[100];
int book_borrow[100];
int i, j, k;
for(i=0;i<100;i++)
{
book_borrow[i] = 1;
book_num[i] = i;
}
printf("도서관리 프로그램에 오신 것을 환영합니다. 원하시는 메뉴를 선택해 주십시오. \n");
for(;;)
{
printf("1. 도서 검색\n2. 도서 대출\n3. 도서 반납\n4. 도서 교체\n5. 나가기 :");
scanf("%d", &i);
if(i == 1)
{
printf("무엇으로 검색하시겠습니까? \n");
printf(" 1) 도서 번호\n 2) 도서 제목\n 3) 저자\n 4) 출판사 : ");
scanf("%d", &j);
if(j == 1)
{
printf("검색할 도서의 번호를 입력해 주십시오.");
scanf("%d", &k);
search_number(&k, book_title,book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 2)
{
printf("검색할 도서의 제목 또는 제목의 일부를 입력해 주십시오. :");
scanf("%s", search);
search_title(book_num, search, book_title, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 3)
{
printf("검색할 도서의 저자 또는 저자 이름의 일부를 입력해 주십시오. :");
scanf("%s", search);
search_auth(book_num, book_title, search, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 4)
{
printf("검색할 도서의 출판사, 또는 출판사 이름의 일부를 입력해주십시오. :");
scanf("%s", search);
search_publ(book_num, book_title, book_author, search, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else
{
printf("잘못 입력하셨습니다. 처음 메뉴로 돌아갑니다. \n");
}
}
else if(i == 2)
{
printf("대출하고자 하는 도서의 번호를 입력해 주십시오. :");
scanf("%d", &k);
book_borr(&k, book_title, book_borrow);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 3)
{
printf("반납하고자 하는 도서의 번호를 입력해 주십시오. :");
scanf("%d", &k);
book_return(&k, book_title, book_borrow);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 4)
{
printf("수행하고자 하는 작업의 번호를 입력해 주십시오. :\n");
book_change(book_num, book_title, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 5)
{
printf("도서관에서 나갑니다. 도서관을 이용해주셔서 감사합니다. \n");
break;
}
else
{
printf("잘못 입력하셨습니다. 다시 입력해주세요. \n");
}
}
}
char search_number(int *k, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i;
i = *k;
printf("검색하신 번호의 도서 정보는 아래와 같습니다. \n");
printf("도서 제목 : %s \n", (book_title[i]));
printf("저자 : %s \n", (book_author[i]));
printf("출판사 : %s \n", (book_publ[i]));
return 0;
}
char search_title(int *book_num, char *search, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<100;k++)
{
if(*search == book_title[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
char search_auth(int *book_num, char (*book_title)[100], char *search, char (*book_author)[50], char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<50;k++)
{
if(*search == book_author[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
char search_publ(int *book_num, char (*book_title)[100], char (*book_author)[50], char *search, char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<30;k++)
{
if(*search == book_publ[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
char book_borr(int *k, char (*book_title)[100], int *book_borrow)
{
int i;
i = *k;
if(book_borrow[i] == 1)
{
printf("책이 정상적으로 대출되었습니다. \n");
printf("도서 제목 : %s \n",(book_title[i]));
book_borrow[i] = 2;
}
else
{
printf("대출이 가능한 도서가 아닙니다. \n");
}
return 0;
}
char book_return(int *k, char (*book_title)[100], int *book_borrow)
{
int i;
i = *k;
if(book_borrow[i] == 2)
{
printf("책이 정상적으로 반납되었습니다. \n");
printf("도서 제목 : %s \n",(book_title[i]));
book_borrow[i] = 1;
}
else
{
printf("반납이 가능한 도서가 아닙니다. \n");
}
return 0;
}
char book_change(int *book_num, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i, j;
char yn[4];
printf(" 1) 도서 교체\n 2) 도서 제거 : ");
scanf("%d", &i);
if(i == 1)
{
printf("도서를 교체할 경우 기존의 도서 정보는 사라집니다. 계속하시겠습니까? yes/no :");
scanf("%s", yn);
if(yn[0] = 'y')
{
printf("새로운 도서 정보를 입력해 주십시오. \n");
printf("도서 번호 :");
scanf("%d", &j);
if(j < 101)
{
printf("도서 제목 :");
scanf("%s", &book_title[j][0]);
printf("도서 저자 :");
scanf("%s", &book_author[j][0]);
printf("출판사 :");
scanf("%s", &book_publ[j][0]);
printf("도서 정보가 교체되었습니다. \n");
}
else
{
printf("잘못된 입력입니다. \n");
}
}
else
{
printf("작업이 취소되었습니다. \n");
}
}
else if(i == 2)
{
printf("제거할 도서 번호를 입력해 주십시오 :");
scanf("%d", &j);
(*book_title[j]) = '\0';
(*book_author[j]) = '\0';
(*book_publ[j]) = '\0';
printf("해당 번호의 도서 정보가 초기화되었습니다. \n");
}
else
{
printf("잘못된 명령입니다. \n");
}
return 0;
}
#include <stdio.h>
char search_number(int *k, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
char search_title(int *book_num, char *search, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
char search_auth(int *book_num, char (*book_title)[100], char *search, char (*book_author)[50], char (*book_publ)[30]);
char search_publ(int *book_num, char (*book_title)[100], char (*book_author)[50], char *search, char (*book_publ)[30]);
char book_borr(int *k, char (*book_title)[100], int *book_borrow);
char book_return(int *k, char (*book_title)[100], int *book_borrow);
char book_change(int *book_num, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30]);
//프로그램 안의 데이터를 다룰 함수들이다.
int main()
{
int book_num[100];
char book_title[100][100];
char book_author[100][50];
char book_publ[100][30];
char search[100];
int book_borrow[100];
int i, j, k;
for(i=0;i<100;i++)
{
book_borrow[i] = 1;
book_num[i] = i;
}
printf("도서관리 프로그램에 오신 것을 환영합니다. 원하시는 메뉴를 선택해 주십시오. \n");
for(;;)
{
printf("1. 도서 검색\n2. 도서 대출\n3. 도서 반납\n4. 도서 교체\n5. 나가기 :");
scanf("%d", &i);
if(i == 1)
{
printf("무엇으로 검색하시겠습니까? \n");
printf(" 1) 도서 번호\n 2) 도서 제목\n 3) 저자\n 4) 출판사 : ");
scanf("%d", &j);
if(j == 1)
{
printf("검색할 도서의 번호를 입력해 주십시오.");
scanf("%d", &k);
search_number(&k, book_title,book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 2)
{
printf("검색할 도서의 제목 또는 제목의 일부를 입력해 주십시오. :");
scanf("%s", search);
search_title(book_num, search, book_title, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 3)
{
printf("검색할 도서의 저자 또는 저자 이름의 일부를 입력해 주십시오. :");
scanf("%s", search);
search_auth(book_num, book_title, search, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(j == 4)
{
printf("검색할 도서의 출판사, 또는 출판사 이름의 일부를 입력해주십시오. :");
scanf("%s", search);
search_publ(book_num, book_title, book_author, search, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else
{
printf("잘못 입력하셨습니다. 처음 메뉴로 돌아갑니다. \n");
}
}
else if(i == 2)
{
printf("대출하고자 하는 도서의 번호를 입력해 주십시오. :");
scanf("%d", &k);
book_borr(&k, book_title, book_borrow);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 3)
{
printf("반납하고자 하는 도서의 번호를 입력해 주십시오. :");
scanf("%d", &k);
book_return(&k, book_title, book_borrow);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 4)
{
printf("수행하고자 하는 작업의 번호를 입력해 주십시오. :\n");
book_change(book_num, book_title, book_author, book_publ);
printf("원하는 메뉴를 선택해 주십시오. \n");
}
else if(i == 5)
{
printf("도서관에서 나갑니다. 도서관을 이용해주셔서 감사합니다. \n");
break;
}
else
{
printf("잘못 입력하셨습니다. 다시 입력해주세요. \n");
}
}
}
//메인 함수는 여기서끝난다.
char search_number(int *k, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i;
i = *k;
printf("검색하신 번호의 도서 정보는 아래와 같습니다. \n");
printf("도서 제목 : %s \n", (book_title[i]));
printf("저자 : %s \n", (book_author[i]));
printf("출판사 : %s \n", (book_publ[i]));
return 0;
}
//도서 번호로 검색을 하는 부분
char search_title(int *book_num, char *search, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<100;k++)
{
if(*search == book_title[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
//도서 제목으로 검색하는 부분
/*참고로 제목, 저자, 출판사로 검색하는 부분은 문자열 검색의 원리를 갖고 있기 때문에 그 안의 내용들은 전부 동일하다. 그냥 안에 함수 이름 같은 것만 다를 뿐이다.*/
char search_auth(int *book_num, char (*book_title)[100], char *search, char (*book_author)[50], char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<50;k++)
{
if(*search == book_author[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
//도서 저자로 검색하는 부분
char search_publ(int *book_num, char (*book_title)[100], char (*book_author)[50], char *search, char (*book_publ)[30])
{
int i, j,k;
j = 0;
printf("입력하신 키워드와 일치하는 결과는 아래와 같습니다. \n");
for(i=0;i<100;i++)
{
for(k=0;k<30;k++)
{
if(*search == book_publ[i][k])
{
search++;
j++;
if(*search == '\0')
{
printf("도서 번호 : %d / 제목 : %s / 저자 : %s / 출판사 : %s \n", book_num[i], (book_title[i]), (book_author[i]), (book_publ[i]));
search = search - j;
j = 0;
}
}
else
{
search = search - j;
j = 0;
}
}
}
return 0;
}
//출판사로 검색하는 부분
char book_borr(int *k, char (*book_title)[100], int *book_borrow)
{
int i;
i = *k;
if(book_borrow[i] == 1)
{
printf("책이 정상적으로 대출되었습니다. \n");
printf("도서 제목 : %s \n",(book_title[i]));
book_borrow[i] = 2;
}
else
{
printf("대출이 가능한 도서가 아닙니다. \n");
}
return 0;
}
//도서 대출하는 부분
char book_return(int *k, char (*book_title)[100], int *book_borrow)
{
int i;
i = *k;
if(book_borrow[i] == 2)
{
printf("책이 정상적으로 반납되었습니다. \n");
printf("도서 제목 : %s \n",(book_title[i]));
book_borrow[i] = 1;
}
else
{
printf("반납이 가능한 도서가 아닙니다. \n");
}
return 0;
}
//도서 반납하는 부분
char book_change(int *book_num, char (*book_title)[100], char (*book_author)[50], char (*book_publ)[30])
{
int i, j;
char yn[4];
printf(" 1) 도서 교체\n 2) 도서 제거 : ");
scanf("%d", &i);
if(i == 1)
{
printf("도서를 교체할 경우 기존의 도서 정보는 사라집니다. 계속하시겠습니까? yes/no :");
scanf("%s", yn);
if(yn[0] = 'y')
{
printf("새로운 도서 정보를 입력해 주십시오. \n");
printf("도서 번호 :");
scanf("%d", &j);
if(j < 101)
{
printf("도서 제목 :");
scanf("%s", &book_title[j][0]);
printf("도서 저자 :");
scanf("%s", &book_author[j][0]);
printf("출판사 :");
scanf("%s", &book_publ[j][0]);
printf("도서 정보가 교체되었습니다. \n");
}
else
{
printf("잘못된 입력입니다. \n");
}
}
else
{
printf("작업이 취소되었습니다. \n");
}
}
else if(i == 2)
{
printf("제거할 도서 번호를 입력해 주십시오 :");
scanf("%d", &j);
(*book_title[j]) = '\0';
(*book_author[j]) = '\0';
(*book_publ[j]) = '\0';
printf("해당 번호의 도서 정보가 초기화되었습니다. \n");
}
else
{
printf("잘못된 명령입니다. \n");
}
return 0;
}
//도서 교체하는 부분
C언어 예제, 도서관리 프로그램-구조체 응용 (0) | 2014.06.10 |
---|---|
C 언어 예제, 줄 세우기, 동점자 처리(구조체 사용) (0) | 2014.06.06 |
C 언어 예제, 문자열 내에서 검색하기 (0) | 2014.02.16 |
C 언어 예제, 문자열 대조하기 (0) | 2014.02.12 |
C 언어 예제, 문자열 대소문자 전환하기 (0) | 2014.02.09 |
댓글 영역