C++小型図書管理システムの実現
24678 ワード
カリキュラム設計のため、小型図書管理システムを実現する必要がある.
次の機能があります.
問題の説明:図書情報を管理するシステムを設計し、情報の説明:このシステムの基本情報に関する説明、例えば:図書名、図書番号、単価、著者、存在状態、借書人の名前、性別、学号など.基本要求:基本機能:1、新進図書の基本情報の入力.2、図書の基本情報の照会.3、図書情報の削除を取り消す.4、本を借りる人のために登録します.5、本を借りる手続きをする(登録していない会員は本を借りることができない).6、本を返す手続きをする.7、図書の在庫を統計し、図書の数量を借りた.
3つのテキストファイルを作成する必要があります:record.txt book.txt reader.txt
operating.hのヘッダファイル:
main.cppの主関数
次の機能があります.
問題の説明:図書情報を管理するシステムを設計し、情報の説明:このシステムの基本情報に関する説明、例えば:図書名、図書番号、単価、著者、存在状態、借書人の名前、性別、学号など.基本要求:基本機能:1、新進図書の基本情報の入力.2、図書の基本情報の照会.3、図書情報の削除を取り消す.4、本を借りる人のために登録します.5、本を借りる手続きをする(登録していない会員は本を借りることができない).6、本を返す手続きをする.7、図書の在庫を統計し、図書の数量を借りた.
3つのテキストファイルを作成する必要があります:record.txt book.txt reader.txt
operating.hのヘッダファイル:
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int all_stock = 0;
int out_stock = 0;
int times=0;
void outData(vector res,int n) // n txt
{
for(int i=0;i for(int j=0;j cout<
cout< double price;
string bookname,writer;
fstream out;
out.open("book.txt",ios::app);
if(!out)
{
cerr< }
time_t tt = time(NULL);// cuo
cout< cin>>bookname;
cout< cin>>writer;
cout< while(! (cin>>price) || price <= 0 )
{
cin.clear();
cin.ignore(100,'
');
cout< }
out<
out.close();
}
void BookMes()
{
fstream in;
string line;
//
vector res;
string temp; //
in.open("book.txt",ios::in);
if(!in)
{
cerr< }
all_stock = 0;
while(getline(in,line))
{
all_stock++;
//cout< // input
stringstream input(line); // line input temp, res
while(input>>temp)
{
res.push_back(temp);
}
}
// 0 1 2 3 4
// res
cout< in.close();
}
void DelBook()
{
string del_book;
string line;
vectorres;
string temp;
bool flag=false;
fstream in;
in.open("book.txt",ios::in);
if(!in)
{
cerr< }
cout< cin>>del_book;
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
times=0;
while(input>>temp)
{
if(del_book == temp && times==0)
{
for(int i=0;i<3;i++) // temp del_book
{
input>>temp;
}
input>>temp;
if(temp != "0")
{
cout< in.close();
return ;
}
flag=true;
cout< continue;
}
res.push_back(temp);
times++;
}
}
//outData(res,5);
in.close();
if(!flag)
{
cout< return ;
}
fstream out;
out.open("book.txt",ios::out);
if(!out)
{
cerr< }
for(int j=0;j {
line = res[j] + " " + res[j+1] + " " + res[j+2] + " " + res[j+3] + " " + res[j+4] + "
";
out< }
out.close();
}
void ReaderEntry()
{
string readername,sex_str;
int sex;
fstream out;
out.open("reader.txt",ios::app);
if(!out)
{
cerr< }
time_t readerid = time(NULL);// cuo
cout< cin>>readername;
do
{
cout< while(! (cin>>sex) )
{
cin.clear();
cin.ignore(100,'
');
cout< }
}while(sex != 0 && sex!=1);
if(sex == 1)
{
sex_str = " ";
}else if (sex == 0){
sex_str = " ";
}else{
out.close();
return ;
}
out<
out.close();
}
/* */
void ReaderMes()
{
fstream in;
string line;
//
vector res;
string temp; //
in.open("reader.txt",ios::in);
if(!in)
{
cerr< }
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
while(input>>temp)
res.push_back(temp);
}
// 0 1 2
// res
cout< in.close();
}
/* */
void BorrowBook()
{
string book[5];
string readerid;
string readername;
string line;
vectorres; // ,
string temp;
bool flag_book = false; //
bool flag_reader = false;
/* book , */
fstream in;
in.open("book.txt",ios::in);
if(!in)
{
cerr< }
cout< cin>>book[0];
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
times=0;
while(input>>temp)
{
if(book[0] == temp && times ==0)
{
res.push_back(temp);
for(int i=0;i<3;i++) // ,
{
input>>temp; // , res,
book[1+i]=temp;
res.push_back(temp);
}
input>>temp; // , 0 1
if(temp == "0")
{
book[4]="1";
temp="1";
res.push_back(temp);
flag_book=true;
}else{
cout< in.close();
return ;
}
continue; //
}
res.push_back(temp);
times++;
}
}
in.close();
if(!flag_book)
{
cout< return ;
}
in.open("reader.txt",ios::in);
if(!in)
{
cerr< }
cout< cin>>readerid;
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
times=0;
while(input>>temp)
{
if(readerid == temp && times==0)
{
input>>temp;
readername=temp;
flag_reader=true;
break;
}
times++;
}
}
if(!flag_reader)
{
cout< in.close();
return ;
}
in.close();
fstream out;
out.open("record.txt",ios::app);
if(!out)
{
cerr< }
line = book[0] + " " + book[1] + " " + readername + '
';
out< cout< out.close();
out.open("book.txt",ios::out);
if(!out)
{
cerr< }
for(int j=0;j {
line = res[j] + " " + res[j+1] + " " + res[j+2] + " " + res[j+3] + " " + res[j+4] + "
";
out< }
out.close();
}
void BorrowMes()
{
fstream in;
string line;
//
vector res;
string temp; //
in.open("record.txt",ios::in);
if(!in)
{
cerr< }
out_stock=0;
while(getline(in,line))
{
out_stock++;
//cout< // input
stringstream input(line); // line input temp, res
while(input>>temp)
res.push_back(temp);
}
// 0 1 2
// res
cout<
in.close();
}
void RtnBook()
{
string rtn_book;
string line;
vectorres;
string temp;
bool flag=false;
fstream in;
in.open("record.txt",ios::in); // record
if(!in)
{
cerr< }
cout< cin>> rtn_book;
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
times=0;
while(input>>temp)
{
if(rtn_book == temp && times==0) //
{
flag=true;
for(int i=0;i<2;i++) // temp del_book
{
input>>temp;//
}
continue;
}
res.push_back(temp);
times++;
}
}
//outData(res,3);
in.close();
if(!flag)
{
cout< return ;
}
fstream out;
out.open("record.txt",ios::out); //record
if(!out)
{
cerr< }
for(int j=0;j {
line = res[j] + " " + res[j+1] + " " + res[j+2] + "
";
out< }
out.close();
vectorres_book;
in.open("book.txt",ios::in); //
if(!in)
{
cerr< }
while(getline(in,line))
{
//cout< // input
stringstream input(line); // line input temp, res
times=0;
while(input>>temp)
{
if(rtn_book == temp && times==0)
{
res_book.push_back(temp);
for(int i=0;i<3;i++) // temp rtn_book
{
input>>temp;
res_book.push_back(temp);
}
input>>temp;// ,
temp = "0";
res_book.push_back(temp);
continue;
}
res_book.push_back(temp);
times++;
}
}
//outData(res,5);
in.close();
out.open("book.txt",ios::out); // ;
if(!out)
{
cerr< }
for(int j=0;j {
line = res_book[j] + " " + res_book[j+1] + " " + res_book[j+2] + " " + res_book[j+3] + " " + res_book[j+4] + "
";
out< }
out.close();
cout<
cout< BookMes();
cout< cout< BorrowMes();
cout< cout<
main.cppの主関数
#include "operating.h"
int main()
{
int order;
do
{
order = -1;
cout<>order;
cin.clear();//
cin.ignore(100,'
');
switch(order)
{
case 1:
BookEntry();
break;
case 2:
BookMes();
break;
case 3:
DelBook();
break;
case 4:
ReaderEntry();
break;
case 5:
ReaderMes();
break;
case 6:
BorrowBook();
break;
case 7:
RtnBook();
break;
case 8:
BorrowMes();
break;
case 9:
CountBook();
break;
case 0:
break;
default:
cout<