⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2006022008532412933.cpp

📁 是一个比较好的图书管理系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  名称:DateBase Administer
  版本:1.0

  这一程序是自由软件,你可以遵照自由软件基金会出版的GNU通用公共
  许可证条款来修改和重新发布这一程序。或者用许可证的第二版,或者
  (根据你的选择)用任何更新的版本。

  发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特
  定目的的隐含的担保。更详细的情况请参阅GNU通用公共许可证。
  
  如果你在使用本软件时有什么问题或建议,
  发Email到:scoobyjqs@hotmail.com
  希望提出您的宝贵建议!
  开发者:靳清松
  
  功能介绍:实现图书和月刊的借阅管理.功能包括图书和月刊信息的添加,图书和月刊信息的删除,图书和月刊信息的浏览,
  图书和月刊的借阅等功能.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
const int MaxNumber=100;//图书最大存储数量

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class Date  //日期类
{
private:  //日期类成员属性
	char year[5];
	char month[4];
	char day[3];

	void yearToString(int num)  //年转换字符串函数
	{
		int index=4;
		if(num<1000 || num>9999)
		{
			cout<<"Year Set Error!"<<endl;
			strcpy(year,"");
		}
		else
		{
			year[index]='\0';
			while(num)
			{
				year[--index]=num%10+48;
				num=num/10;
			}
		}
	}

	void monthToString(int num)  //月转换字符串函数
	{
		switch(num)  
		{
			case 1:
				strcpy(month,"Jan");
				break;
			case 2:
				strcpy(month,"Feb");
				break;
			case 3:
				strcpy(month,"Mar");
				break;
			case 4:
				strcpy(month,"Apr");
				break;
			case 5:
				strcpy(month,"May");
				break;
			case 6:
				strcpy(month,"Jun");
				break;
			case 7:
				strcpy(month,"Jul");
				break;
			case 8:
				strcpy(month,"Aug");
				break;
			case 9:
				strcpy(month,"Sep");
				break;
			case 10:
				strcpy(month,"Oct");
				break;
			case 11:
				strcpy(month,"Nov");
				break;
			case 12:
				strcpy(month,"Dec");
				break;
			default:
				cout<<"Month Set Error!"<<endl;
				strcpy(month,"");
		}
	}

	void toString(int num)  //数值转换字符串函数
	{
		int index=2;
		day[index]='\0';
		if(num<10)
		{
			day[0]=48;
			day[1]=num+48;
		}
		else
		{
			while(num)
			{
				day[--index]=num%10+48;
				num=num/10;
			}
		}
	}

	void dayToString(int num,int year)  //日转换字符串函数
	{
		if(strcmp(month,"")==0)  
			{
				cout<<"Day Set Error!Because Month Set Error!"<<endl;
				strcpy(day,"");
			}
		else if(strcmp(month,"Jan")==0 || strcmp(month,"Mar")==0 || strcmp(month,"May")==0 || strcmp(month,"Jul")==0 || strcmp(month,"Aug")==0 || strcmp(month,"Oct")==0 || strcmp(month,"Dec")==0)
		{
			if(num<1 || num>31)
			{
				cout<<"Day Set Error!"<<endl;
				strcpy(day,"");
			}
			else
				toString(num);
		}
		else if(strcmp(month,"Apr")==0 || strcmp(month,"Jun")==0 || strcmp(month,"Sep")==0 || strcmp(month,"Nov")==0)
		{
			if(num<1 || num>30)
			{
				cout<<"Day Set Error!"<<endl;
				strcpy(day,"");
			}
			else
			{
				toString(num);
			}

		}
		else if(year%4==0 && year%100==0 || year%400==0)
		{
			if(num<1 || num>29)
			{
				cout<<"Day Set Error!"<<endl;
				strcpy(day,"");
			}
			else
			{
				toString(num);
			}
		}
		else
		{
			if(num<1 || num>28)
			{
				cout<<"Day Set Error!"<<endl;
				strcpy(day,"");
			}
			else
			{
				toString(num);
			}
		}
	}

public:  //日期类成员函数
	Date()
	{
		strcpy(year,"");
		strcpy(month,"");
		strcpy(day,"");
	}

	Date(int year,int month,int day)
	{
		yearToString(year);  //设置年
		monthToString(month); //设置月份 
		dayToString(day,year); //设置日期
	}

	void setYear(int year) { yearToString(year); }
	void setMonth(int month) { monthToString(month); }
	void setDay(int day,int year) { dayToString(day,year); }
	void setDate(int year,int month,int day)
	{
		yearToString(year);  //设置年
		monthToString(month); //设置月份
		dayToString(day,year); //设置日期
	}

	char* getYear() { return this->year; }
	char* getMonth() { return this->month; }
	char* getDay() { return this->day; }
	void getDate()
	{
		cout<<this->year<<"-"<<this->month<<"-"<<this->day<<endl;
	}

	virtual ~Date() {}

	friend ostream & operator<<(ostream & out,Date & date)  //日期类屏幕输出
	{
		out<<date.year<<"-"<<date.month<<"-"<<date.day;
		return out;
	}

	friend fstream & operator<<(fstream & out,Date & date)  //日期类文件输出
	{
		out<<date.year<<" "<<date.month<<" "<<date.day<<endl;
		return out;
	}

	friend istream & operator>>(istream & in,Date & date)  //日期类键盘输入
	{
		int year,month,day;
		in>>year>>month>>day;
		date.setDate(year,month,day);
		return in;
	}

	friend fstream & operator>>(fstream & in,Date & date)  //日期类文件输入
	{
		in>>date.year>>date.month>>date.day;
		return in;
	}

};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class Presswork //印刷品类,图书类和杂志类的共同基类
{
protected:  //印刷品类成员属性
	long id;  //印刷品代码
	char title[31];  //印刷品名称
	char publisher[31];  //印刷品出版商名称
public:  //印刷品类成员函数
	Presswork()
	{
		id=0;
		strcpy(title,"");
		strcpy(publisher,"");
	}

	Presswork(long id,char title[],char publish[])
	{
		this->id=id;
		strcpy(this->title,title);
		strcpy(this->publisher,publisher);
	}
	
	virtual ~Presswork() {}

	void setID(long id) { this->id=id; }
	void setTitle(char title[]) { strcpy(this->title,title); }
	void setPublisher(char publisher[]) { strcpy(this->publisher,publisher); }
	void setInfo(long id,char title[],char publisher[])
	{
		this->id=id;
		strcpy(this->title,title);
		strcpy(this->publisher,publisher);
	}

	long getID() { return this->id; }
	char* getTitle() { return this->title; }
	char* getPublisher() { return this->publisher; }

};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class Book:public Presswork  //图书类,共有继承印刷品类
{
private:  //图书类成员属性
	char author[31];  //图书作者
	Date issue;  //出版日期
	double price;  //图书价格
	char status;  //图书可用性状态("A"代表可借阅,"I"代表已被借阅)

public:
	Book():Presswork()
	{
		strcpy(author,"");
		issue=Date();
		price=0.0;
		status='X';
	}

	Book(long id,char title[],char publisher[],char author[],int year,int month,int day,double price,char status='A'):Presswork(id,title,publisher)
	{
		strcpy(this->author,author);
		this->issue=Date(year,month,day);
		this->price=price;
		if(status!='A' && status!='I')
		{
			cout<<"Book Status Set Error!"<<endl;
			this->status='X';
		}
		else
		{
			this->status=status;
		}
	}

	virtual ~Book() {}

	void setAuthor(char author[]) { strcpy(this->author,author); }
	void setIssue(int year,int month,int day) { issue=Date(year,month,day); }
	void setPrice(double price) { this->price=price; }
	void setStatus(char status) { this->status=status; }
	void setInfo(long id,char title[],char publisher[],char author[],int year,int month,int day,double price,char status='A')
	{
		Presswork::setInfo(id,title,publisher);
		strcpy(this->author,author);
		this->issue=Date(year,month,day);
		this->price=price;
		if(status!='A' && status!='I')
		{
			cout<<"Book Status Set Error!"<<endl;
			this->status='X';
		}
		else
		{
			this->status=status;
		}
	}

	char* getAuthor() { return this->author; }
	void getIssue() { issue.getDate(); }
	double getPrice() { return this->price; }
	char getStatus() { return this->status; }
	void disp()
	{
		cout<<"Code:"<<setw(3)<<id<<" Name:"<<setw(25)<<title<<" Author:"<<setw(25)<<author<<endl;
	}

	void toSave(fstream &fout)  //保存对象属性值到文件
	{
		fout.write((char *)this,sizeof(Book));
	}

	void toLoad(fstream &fin)  //从文件当前位置读取数据到对象
	{
		fin.read((char *)this,sizeof(Book));
	}

	friend ostream & operator<<(ostream & out,Book & book)  //图书类输出到屏幕
	{
		out<<book.id<<" "<<book.title<<" "<<book.publisher<<" "<<book.author<<" "<<book.issue<<" "<<book.price<<" "<<book.status;
		return out;
	}

	friend fstream & operator<<(fstream & out,Book & book)  //图书类输出到文件
	{
		out<<book.id<<" "<<book.title<<" "<<book.publisher<<" "<<book.author<<" "<<book.issue<<" "<<book.price<<" "<<book.status;
		return out;
	}

	friend istream & operator>>(istream & in,Book & book)  //图书类从键盘录入信息
	{
		char title[30],publisher[30],author[30];
		do
		{
			cout<<"\nPlease Enter Book/Periodical Name:";
			in.getline(title,31);
			strcpy(book.title,title);
			if(strcmp(book.title,"")==0)
				cout<<"Book/Periodical Name Is Null,Please Input Again!"<<endl;
		}while(strcmp(book.title,"")==0);
		
		do
		{
			cout<<"\nPlease Enter Publisher Name:";
			in.getline(publisher,31);
			strcpy(book.publisher,publisher);
			if(strcmp(book.publisher,"")==0)
				cout<<"Publisher Name Is Null,Please Input Again!"<<endl;
		}while(strcmp(book.publisher,"")==0);
		
		do
		{
			cout<<"\nPlease Enter Author Name:";
			in.getline(author,31);
			strcpy(book.author,author);
			if(strcmp(book.author,"")==0)
				cout<<"Author Name Is Null,Please Input Again!"<<endl;
		}while(strcmp(book.author,"")==0);

		cout<<"\nPlease Enter Publishing Date(Separate By Blank):";
		in>>book.issue;

		do
		{
			cout<<"\nPlease Enter Price:";
			in>>book.price;
			if(book.price<=0)
				cout<<"Book Price Is Less Than Zero,Please Input Again!"<<endl;
		}while(book.price<=0);

		return in;
	}

	friend fstream & operator>>(fstream & in,Book & book) {}  //图书类从文件输入

};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class Magazine:public Presswork  //期刊类,共有继承印刷品类
{
private:  //期刊类成员属性
	char period;  //期刊周期种类("F"代表两周,"M"代表一个月,"S"代表六个月,"Y"代表一年)

public:
	Magazine():Presswork()
	{
		period='X';
	}

	Magazine(long id,char title[],char publisher[],char period='M'):Presswork(id,title,publisher)
	{
		if(period!='F' && period!='M' && period!='S' && period!='Y')
		{
			cout<<"Magazine Period Set Error!"<<endl;
			this->period='X';
		}
		else
		{
			this->period=period;
		}
	}

	virtual ~Magazine() {}

	void setPeriod(char period) { this->period=period; }
	void setInfo(long id,char title[],char publisher[],char period='M')
	{
		Presswork::setInfo(id,title,publisher);
		this->period=period;
	}

	char getPeriod() { return period;}
	void disp()
	{
		cout<<"Code:"<<setw(3)<<id<<" Name:"<<setw(25)<<title<<" Period"<<setw(2)<<period<<endl;
	}

	void toSave(fstream &fout)  //保存对象属性值到文件
	{
		fout.write((char *)this,sizeof(Magazine));
	}

	void toLoad(fstream &fin)  //从文件当前位置读取数据到对象
	{
		fin.read((char *)this,sizeof(Magazine));
	}

	friend ostream & operator<<(ostream & out,Magazine & magazine)  //期刊类输出到屏幕
	{
		cout<<magazine.id<<" "<<magazine.title<<" "<<magazine.publisher<<" "<<magazine.period;
		return out;
	}

	friend fstream & operator<<(fstream & out,Magazine & magazine)  //期刊类输出到文件
	{
		cout<<magazine.id<<" "<<magazine.title<<" "<<magazine.publisher<<" "<<magazine.period;
		return out;
	}

	friend istream & operator>>(istream & in,Magazine & magazine)  //期刊类从键盘输入
	{	
		char title[30],publisher[30];
		do
		{
			cout<<"\nPlease Enter Book/Periodical Name:";
			in.getline(title,30);
			strcpy(magazine.title,title);
			if(strcmp(magazine.title,"")==0)
				cout<<"Book/Periodical Name Is Null,Please Input Again!"<<endl;
		}while(strcmp(magazine.title,"")==0);
		
		do
		{
			cout<<"\nPlease Enter Publisher Name:";
			in.getline(publisher,30);
			strcpy(magazine.publisher,publisher);
			if(strcmp(magazine.publisher,"")==0)
				cout<<"Publisher Name Is Null,Please Input Again!"<<endl;
		}while(strcmp(magazine.publisher,"")==0);

		do
		{
			cout<<"\nPlease Enter Periodicity(F/M/S/Y):";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -