当前位置:编程学习 > C/C++ >>

求一个C++程序

补充:求一图书借阅管理程序,要求如下: 用C++语言和面向对象的思想和方法设计并实现一个学校图书馆图书借阅管理程序。 

程序的功能有:图书信息的录入、删除、修改,用户信息的维护,图书的借还管理以及简单的统计分析功能。具体细节描述如下:

l         图书的信息有:书号、书名、作者名、出版社、出版年份、价格、库存量。

l         图书信息的录入和修改可以涉及到上述所有信息。

l         删除图书不是完全删除该书,而是加删除标记,使其为不可借阅状态。

l         有些图书附带光盘需要录入存储,并可以与书一起借阅。

l         程序的用户有管理员、教师和学生三种。三种用户均需要使用用户名和密码登陆系统,并同时确认了用户的身份,从而具有了不同的权限。

l         系统初始有缺省管理员,用户名为administrator,密码为:1234。

l         用户登录时,如果是老用户,正确输入用户名和密码即可登录,并获得了相应的权限。如果是新用户,选择自己所属用户的种类,输入自行定义的用户名和密码,及详细的用户信息后提交,等待管理员的批准,批准后成为老用户,再登录系统。

l         图书借还管理包括:图书的浏览、借出、归还等功能。有库存时才可以借阅。

l         在用户登录时列出用户借阅的书籍,并提醒用户还有一周就到借阅终止日期,需要归还的书籍。

l         其中每种用户具有的权限分别为:

                        i.              管理员

①     做为新用户、或老用户登录系统。

②     添加/删除/修改图书信息。

③     浏览全部图书信息。

④     借阅和归还图书。

⑤     批准用户申请。批准时需要检查用户名不能有重名。

⑥     可借阅20本图书,借阅期限为12个月。

⑦     登录时列出搜借阅的图书,并并提醒用户还有一周就到借阅终止日期,需要归还的书籍。

⑧     可统计图书被借阅的次数,并按次数多少降序输出。

                      ii.              教师

①     做为新用户、或老用户登录系统。

②     浏览全部图书信息。

③     借阅和归还图书。

④     登录时列出搜借阅的图书,并并提醒用户还有一周就到借阅终止日期,需要归还的书籍。

⑤     可借阅10本图书,借阅期限为6个月。

⑥     所借图书到期,可申请再延期6个月。

                    iii.              学生

①     做为新用户、或老用户登录系统。

②     浏览全部图书信息。

③     借阅和归还图书。

④     可借阅5本图书,借阅期限为3个月。

⑤     登录时列出搜借阅的图书,并并提醒用户还有一周就到借阅终止日期,需要归还的书籍。

l         教师的信息有:职工号、姓名、所属部门、职称。

l         学生的信息有:学号、姓名、所属学院。

要求

l         用面向对象的思想和方法完成程序设计。

l         带有光盘的图书作为没有光盘图书的子类。

l         完成“统计图书被借阅的次数,并按次数多少降序输出”时先重载“<”运算符将书的对象排序。

l         在上述基本需求的基础上创造性的扩展、设计、完善程序,优化程序界面。

追问:谢谢高人~我用microsoft visual C++ 这软件运行后  第一个显示是

  Compiling...
M.cpp
d:\M.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
D:\M.cpp(4) : error C2065: 'list' : undeclared identifier
D:\M.cpp(4) : error C2062: type 'int' unexpected
D:\M.cpp(8) : error C2065: 'lst' : undeclared identifier
D:\M.cpp(8) : error C2228: left of '.push_back' must have class/struct/union type
D:\M.cpp(10) : error C2065: 'cout' : undeclared identifier
D:\M.cpp(10) : error C2297: '<<' : illegal, right operand has type 'char [8]'
D:\M.cpp(10) : error C2228: left of '.size' must have class/struct/union type
D:\M.cpp(10) : error C2065: 'endl' : undeclared identifier
D:\M.cpp(12) : error C2297: '<<' : illegal, right operand has type 'char [11]'
D:\M.cpp(14) : error C2062: type 'int' unexpected
D:\M.cpp(14) : error C2039: 'iterator' : is not a member of '`global namespace''
D:\M.cpp(16) : error C2065: 'p' : undeclared identifier
D:\M.cpp(16) : error C2228: left of '.end' must have class/struct/union type
D:\M.cpp(16) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
M.exe - 1 error(s), 0 warning(s)

第二个是

Compiling...
A.cpp
d:\A.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
d:\A.cpp(4) : error C2065: 'list' : undeclared identifier
d:\A.cpp(4) : error C2062: type 'int' unexpected
d:\A.cpp(8) : error C2065: 'lst1' : undeclared identifier
d:\A.cpp(8) : error C2228: left of '.push_back' must have class/struct/union type
d:\A.cpp(10) : error C2065: 'lst2' : undeclared identifier
d:\A.cpp(10) : error C2228: left of '.push_back' must have class/struct/union type
d:\A.cpp(12) : error C2065: 'cout' : undeclared identifier
d:\A.cpp(12) : error C2297: '<<' : illegal, right operand has type 'char [19]'
d:\A.cpp(14) : error C2062: type 'int' unexpected
d:\A.cpp(14) : error C2039: 'iterator' : is not a member of '`global namespace''
d:\A.cpp(16) : error C2065: 'p' : undeclared identifier
d:\A.cpp(16) : error C2228: left of '.end' must have class/struct/union type
d:\A.cpp(16) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.

A.obj - 1 error(s), 0 warning(s)

 

我不是很懂,请高人帮看看是什么原因。。。

答案:我给你一个吧  但是和你的不是完全相同  大概相似 你看看吧  再改一下



#include<iostream>
#include<fstream>
using namespace std;


struct bookdata
{
int TP;
char bookname[40];
long balance;
};


int endMark(bookdata book)
{
if(book.TP==0)
return 1;
return 0;
}
void Initial( const char * filedat );
void Append( const char * filedat );
void Sale( const char * filedat );
void Inquire( const char * filedat );
const char * filetxt = "d:\\booksfile.text";
void Createtxt( const char * filedat )
{
fstream fdat(filedat, ios::in|ios::binary);
fstream ftxt(filetxt, ios::out);
fdat.seekp( 0, ios::beg);
bookdata book;
cout<<"**********建立文本文件**********\n" ;
do
{
   fdat.read((char *) & book , sizeof(bookdata));
   if(!endMark(book ))
     ftxt<<book.TP<<'\t'<<book.bookname<<'\t'<<book.balance<<endl;
}while( !endMark(book));
ftxt.close();
cout<<"文本文件已建立,要浏览文件吗? (Y/N) \n ";
char answer, s[80];
cin>>answer;
if(answer=='Y'||answer=='y')
{
ftxt.open( "d:\\booksfile.txt", ios::in );
while(!ftxt.eof())
{
ftxt.getline(s, 80);
cout<<s<<endl;
}
ftxt.close();
}
fdat.close();
}


//#endif 


//ex11_18.cpp
//建立主菜单,选择操作
//#include"ex11_18.h"




int main()
{
const char * filedat = "booksfile.dat" ;
char choice;
while(1) 
{
   cout << "**********书库管理**********\n请输入操作选择\n"
    <<"1: 入库 \t"
    <<"2: 售出 \t"
    <<"3: 查询 \t"
    <<"4: 建立文本 \t"
    <<"0: 初始化 \t"
    <<"Q: 退出 \t"<<endl;
   cin >> choice;
    switch( choice)
   { 
       case '1': Append(filedat); break;
case '2': Sale(filedat); break;
case '3': Inquire(filedat); break;
case '4': Createtxt(filedat); break;
case '0': Initial(filedat); break;
   case 'q': 
   case 'Q': cout << "退出系统\n" ; return 0;
   default:  cout << "输入错误,请再输入\n";   
   }
}
}


//Initial.cpp
//初始化账目文件。建立只有一个标志记录的空文件 
//#include"ex11_18.h"
const bookdata mark = {0, "noname\0", 0 };
void Initial(const char * filedat )
{
fstream fdat(filedat, ios::out|ios::binary);
cout<<"若账目文件存在,将删除原有数据,要进行文件初始化吗? (Y/N) \n ";
char answer;
cin>>answer;
if(answer=='Y'||answer=='y')
{
fdat.seekp( 0, ios::beg );
fdat.write((char*) &mark, sizeof(bookdata));
cout<<"文件已经初始化 \n";
}
else 
{
cout<<"取消操作\n";
}
fdat.close();
}


//Append.cpp
//入库操作。如果是新书目,则在文件末尾追加一条记录;如果是已有书目,则增加库存量 
//#include"ex11_18.h"
void Append( const char * filedat )
{
char choice;
bookdata book;
int key;
long num;
fstream fdat(filedat, ios::in|ios::out|ios::binary);
if(!fdat)
{
cout<<"账目文件不存在,请进行初始化操作 \n";
return ;
}
cout<<"**********入库登记**********\n";
while(1)
{
cout << "请输入操作选择\n"
             << "1: 新书号\t"
             << "2: 旧书号\t"
             << "Q: 退出\n";
        cin >> choice;
        switch( choice )
        {
   case '1':
        {
       fdat.seekg( 0, ios::beg );   
do     
{
   fdat.read((char*)&book, sizeof(bookdata)); 
}while(!endMark(book));
fdat.seekp(-long(sizeof(bookdata)), ios::cur);
cout<<"书号(TP),书名 , 数量: \n ? ";
cin>>book.TP;
cout<<" ? ";
cin>>book.bookname ;
cout<<" ? ";
cin>>book.balance;
fdat.write((char *) &book, sizeof(bookdata));
fdat.write((char *) &mark, sizeof(bookdata));
break;
       };
       case '2':
       {
        fdat.seekg(0, ios::beg);
        cout<<"书号(TP): \n? ";
        cin>>key;
        do
        {
       fdat.read((char *) & book, sizeof(bookdata));
       } while(book.TP!=key && !endMark(book));
       if( book.TP == key )
       {
        cout<<book.TP<<'\t'<<book.bookname<<'\t'<<book.balance<<endl;
        cout<<"入库数量 :\n? ";
        cin>>num;
        if( num>0 ) book.balance+=num;
        else
        {
       cout<<"数量输入错误\n";
       continue;
       }
       fdat.seekg(-long(sizeof(bookdata)), ios::cur);
       fdat.write((char *) & book, sizeof(bookdata));
       cout<<"现库存量 :\t\t"<<book.balance<<endl;
        }
        else cout<<"书号输入错误 \n";
        break;
        }
        case 'Q':
        case 'q': return ;
        }
}
fdat.close();
}


//Sale.cpp
//销售登记。根据书号查找文件。如果找到,则用销售数修改库存量 
//#include"ex11_18.h"
void Sale( const char * filedat )
{
char choice;
bookdata book ;
int key;
long num;
fstream fdat(filedat, ios::in|ios::out|ios::binary);
cout<<"**********销售登记**********\n";
while(1)
{
cout<<"请输入操作选择  \n"
   <<"1: 销售登记 \t"
   <<"Q: 退出\n";
        cin>>choice;
        switch( choice )
        {
        case '1':
        {
       fdat.seekg(0,ios::beg );
       cout<<"书号(TP): \n?";
       cin>>key;
       do
       {
       fdat.read((char *) & book , sizeof(bookdata));
       }while(book.TP!=key && !endMark(book));
       if(book.TP ==key)
       {
       cout << " :销售数量 \n? ";
       cin>>num;
       if(num>0 && book.balance>=num)
       book.balance-=num;
       else
       {
       cout<<"数量输入错误 \n";
       continue;
       }
    &n

上一个:插入排序的C++代码
下一个:学C++一定要会英文吗?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,