U E D R , A S I H C RSS

C++스터디_2005여름/도서관리프로그램/남도연

No older revisions available

No older revisions available



-----<useclass.h>------
~cpp 
class book {
	
private :	
	// 책 상태 정보
	
public :
	book *next;
	book *first;
	int situation,selection;
	book();
	~book();
	char book_name[30];
	char book_writer[15];
	char book_ISBN[10];
	void input();		
	void search();
	void borrow();
	void restoration();
};
------<cpp.cpp>-------
~cpp 
#include <iostream>
#include "useclass.h"

using namespace std;

void main()
{
	int number = 0;
	book b;	
	
	while(number != 5)
	{
		cout << "1.책 입력 2.검색 3.대여 4.반납 5.종료 : ";
		cin >> number;
		if(number == 5)
			break;
		switch(number)
		{
		case 1 :
			b.input();
			break;
		case 2:
			b.search();
			break;
		case 3:
			b.borrow();
			break;
		case 4:
			b.restoration();
			break;
		default :
			cout<<"잘못 입력하셨습니다."<<endl;
			break;
		}
		
	}
}
------<cpp2.cpp>--------
~cpp 
#include <iostream>
#include <string.h>
#include "useclass.h"
using namespace std;

book :: book(){
	situation=0;
}
book :: ~book(){
}

void book :: input()
{
	book * k = new book;
	
	cout << "책 제목 : ";
	cin >> k->book_name;
	cout << "책 저자 : ";
	cin >> k->book_writer;
	cout << "책 ISBN : ";
	cin >> k->book_ISBN;
	k->next=first;
	first=k;
	
}

void book :: search(){
	char name[30];
	char ISBN[10];
	cout<<"책 이름과 ISBN 중 선택하시오. 1.책 이름 2.ISBN : ";
	cin >> selection;
	if (selection == 1){
		cout<<"찾을 책 이름은?"<<endl;
		cin>>name;
		book *find;
		find = first;
		while(find->next !=NULL ){
			if(strcmp(find->book_name,name)==0)
			{
				cout<<"책 제목 : "<<find->book_name<<endl;
				cout<<"책 저자 : "<<find->book_writer<<endl;
				cout<<"ISBN : "<<find->book_ISBN<<endl;
				if(find->situation==0){
					cout<<"상태 : 반납됨"<<endl;
				}
				else{
					cout<<"상태 : 대여됨"<<endl;
				}
				break;
			}
			else{
				
				if (find->next == NULL){
					cout<<"찾을 수 없습니다."<<endl;
					break;
				}
				else{
					find=find->next;
				}
				
			}			
		}
		
	}
	else if (selection==2){
		cout<<"찾을 책 ISBN은?"<<endl;
		cin>>ISBN;
		book *find;
		find = first;
		while(find->next !=NULL ){
			if(strcmp(find->book_ISBN,ISBN)==0){
				cout<<"책 제목 : "<<find->book_name<<endl;
				cout<<"책 저자 : "<<find->book_writer<<endl;
				cout<<"ISBN : "<<find->book_ISBN<<endl;
				if(find->situation==0){
					cout<<"상태 : 반납됨"<<endl;
				}
				else{
					cout<<"상태 : 대여됨"<<endl;
				}
				break;
			}
			else{
				
				if (find->next == NULL){
					cout<<"찾을 수 없습니다."<<endl;
					break;
				}
				else{
					find=find->next;
				}
				
			}
		}
	}
		else{
			cout<<"잘못 입력하셨습니다."<<endl;
		}
	}
	
	void book :: borrow()
	{
		char name_temp[30];
		char ISBN_temp[10];
		cout << "빌릴 책 제목 혹은 ISBN을 선택하세요.: ";
		cin >>selection;
		if (selection == 1){
			cout<<"빌릴 책 제목 : ";
			cin >> name_temp;
			book *lent;
			lent = first;
			while(lent->next !=NULL ){
				if(strcmp(lent->book_name,name_temp)==0){
					lent->situation = 1;
					break;
				}
				else{
					lent=lent->next;
				}			
			}
			
		}
		else if (selection==2){
			cout<<"빌릴 책 ISBN : ";
			cin >> ISBN_temp;
			book *lent;
			lent = first;
			while(lent->next !=NULL ){
				if(strcmp(lent->book_ISBN,ISBN_temp)==0){
					lent->situation = 1;
					break;
				}
				else{
					lent=lent->next;
				}			
			}			
			
		}
		else{
			cout<<"잘못 입력하셨습니다."<<endl;
		}
	}
	
	void book :: restoration()
	{
		char restoration_name[30];
		char restoration_ISBN[10];
		cout<<"반납 할 책 이름 혹은 ISBN을 입력하세요.  1. 책 이름 2.ISBN: ";
		cin >> selection;
		if ( selection == 1){
			cout << "반납 된 책 이름 : ";
			cin >> restoration_name;
			book *restore;
			restore = first;
			while(restore->next !=NULL ){
				if(strcmp(restore->book_name,restoration_name)==0)
				{
					restore->situation = 0;
					break;
				}
				else{
					restore=restore->next;
				}			
			}
		}
		else if (selection ==2){
			cout << "반납 된 책 ISBN : ";
			cin >> restoration_ISBN;
			book *restore;
			restore = first;
			while(restore->next !=NULL ){
				if(strcmp(restore->book_ISBN,restoration_ISBN)==0)
				{
					restore->situation = 0;
					break;
				}
				else{
					restore=restore->next;
				}			
			}
		}
		else{
			cout<<"잘못 입력하셨습니다."<<endl;
		}
	}	
	

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:46
Processing time 0.0461 sec