Blog/JAVA기반 스마트웹 개발2021

프로그래밍 언어 활용 part 2 - 도서관리 시스템 고도화(라이브러리 적용)

고구마달랭이 2021. 8. 9. 20:41

도서관리 시스템 고도화 (라이브러리 적용)

학습내용 학습목표
▪ 프로그램 설계
▪ 코드 분석
▪ 목표로 하는 시스템에서 요구되는 자료구조를 설계할 수 있다.
▪ 사용 가능한 라이브러리 함수를 개발에 적용할 수 있다.

프로그램 설계

 

1. 고도화 개요

[1] 고도화 개요

☞ 도서를 키워드로 검색하여 결과를 출력하는 프로그램을 개발

☞ 코드 데이터에서 출판연도별 책 목록 출력 기능

 

 

2. 기능 정의

[1] memcmp

 

3. 자료구조 정의

 


 

코드 분석


1. 선언부

#include <stdio.h>
#include <string.h>

typedef struct book{
	char bookTitle[50];
	char bookAuthor[20];
	int bookPrice;
	int bookSale;
	char bookCode[9]; // xxxxxxx 북코드
    
}BOOK;

int inBook(BOOK* , int);
void outBook(BOOK* , int);
void searchBook(BOOK* , int);

 

2. 코드입력 검증

int inBook(BOOK* mb, int cnt)
{
	int number;
	while(1){
		printf("\n책코드 : ");
		gets(mb[cnt].bookCode);
		if (strlen(mb[cnt].bookCode) == 8)
		{
			number = strcspn(mb[cnt].bookCode, "0123456789-");
			if (number==8 && number != 0)
				break;
		}

 

3. 연도별 출력

printf(“\n검색할 출판연도를 입력하세요: ”);
gets(sKey);

printf(“\n-----------------------------------”);
printf(“\n%10s %30s\n”, “코 드”, “제 목”);

for(i=0;i<cnt;i++)
{
	year = strtok(mb[i].bookCode,“-”);
	if (!strcmp(year,sKey))
	{
		printf(“\n%10s %30s”,mb[i].bookCode, mb[i].bookTitle);
	check++;
	}
}
if(check == 0)
{
printf(“\n일치하는 책이 없습니다. \n”);
}

 

4. 키워드 검색

printf(“\n검색할 제목을 입력하세요: ”);
gets(sTitle);
for(i=0;i<cnt;i++)
{
	if (strstr(mb[i].bookTitle,sTitle)!=NULL)
	{
	printf(“\n\n-----------------------------------”);
	printf(“\n코 드 : %s \n”,mb[i].bookCode);
	printf(“제 목 : %s \n”,mb[i].bookTitle);
	printf(“저 자 : %s \n”,mb[i].bookAuthor);
	printf(“가 격 : %d \n”,mb[i].bookPrice);
	printf(“판매수량 : %d \n”,mb[i].bookSale);
	check++;
	}
}
if(check)
{
	printf(“\n-----------------------------------”);
	printf(“\검색 건수 : %d \n”, check);
}
else
{
	printf(“\n-----------------------------------”);
	printf(“\n일치하는 책이 없습니다. \n”);
}

 

 


 

 

학습정리

 

1. 프로그램 설계

▪ 프로그램 개발 시 작업 목표에 맞게 사용할 라이브러리 함수와 자료구조를 결정해야 함

 

2. 코드 분석

▪ 토큰을 이용하여 문자열을 분리할 수 있는 함수 : strtok

▪ 특정 문자로 이루어진 문자열인지 검사하는 것이 가능한 함수 : strcspn

▪ 키워드 검색에 유용한 함수 : strstr