| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 542 人关注过本帖
标题:图书管理系统代码。要注释
只看楼主 加入收藏
ZJSZJS
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-3-26
结帖率:0
收藏
已结贴  问题点数:10 回复次数:1 
图书管理系统代码。要注释
#include<iostream.h>
#include<string.h>
#include<iomanip.h>

class book
{
private:
    static int n;
    char author[30];
    char title[30];
    char number[30];
    int stock;
    int out;
    char reader[30];
    char id[30];
public:
    book();
    book(char a[],char b[],char c[],int d[],int e[],char f[],char g[]);
    void setbook();
    void outcom();
    friend class group;
};

class group
{
 private:
    book *a;
    int len;
 public:
    group(int s)
    {
        len=s;a=new book[len];book::book();
    }     
    ~group(){ delete []a;}
    void add();
    void del();
    void find();
    void get();
    void back();
    void inquire();
    int menu();

};

int book::n=0;
book::book()
{
    strcpy(author,"-");
    strcpy(title,"-");
    strcpy(number,"-");
    strcpy(reader,"-");
    strcpy(id,"-");
}
book::book(char a[],char b[],char c[],int d[],int e[],char f[],char g[])
{
    strcpy(author,a);
    strcpy(title,b);
    strcpy(number,c);
    strcpy(reader,f);
    strcpy(id,g);
    n++;
}
void book::setbook()
{
    cout<<"请输入书籍数据"<<endl;
    cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
    cin>>author>>title>>number>>stock>>out>>reader>>id;
    cout<<endl;
    n++;
}
void book::outcom()
{
    if(strlen(number)!=0)
    cout<<author<<setw(10)<<title<<setw(12)<<number<<setw(12)<<stock<<setw(12)<<out<<setw(11)<<reader<<setw(12)<<id<<endl;
}
void group::add()
{
    if(book::n!=0)
    {
        for(int i=book::n-1;i<len;i++)
        {
            a[i+1].book::setbook();
            cout<<"还要继续添加吗?确定(y)/取消(n):";
            char c;
            cin>>c;
            if(c=='y') continue;
            else if(c=='n')
            {  
                cout<<"退出添加!"<<endl; return;
            }
            else
            {  
                cout<<"选择错误,默认退出添加!"<<endl;
                return;
            }
        }
    }
    else
    {
        for(int i=0;i<len;i++)
        {
            a[i].book::setbook();
            cout<<"还要继续添加吗?确定(y)/取消(n):";
            char c;
            cin>>c;
            if(c=='y') continue;
            else if(c=='n')
            {  
                cout<<"退出添加!"<<endl; return;
            }
            else
            {  
                cout<<"选择错误,默认退出添加!"<<endl;
                return;
            }
       }
     }
}  
void group::del()
{
    int i,j;
    char c;
    char n[15];
    cout<<"请输入登录号"<<endl;
    cin>>n;
        
        for( i=0;i<book::n;i++)
            if(!strcmp(a[i].id,n))
            {
                j=i;
                cout<<"将要删除该书目:"<<endl;
                cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
                a[j].book::outcom();
                cout<<"确定要删除吗?确定(y)/取消(n)";
                cin>>c;
                if(c=='y')
                {
                    for( i=j;i<book::n-1;i++)
                        a[i]=a[i+1];
                    cout<<"已删除该书目信息:"<<endl;
                    book::n--;return;
                }
            }
            else if(c=='y'||c=='Y')
            {
                cout<<"取消删除 !"<<endl;
                return;
            }
   
   
    cout<<"你要删除的书不存在!"<<endl;
    return;
}

void group::find()
{
    char n[15];
    int i,j;
    cout<<"请输入登录号"<<endl;
    cin>>n;
    for(i=0;i<book::n;i++)
        if(!strcmp(a[i].id,n))
        {
            j=i;
            cout<<"你要查找的书d信息:"<<endl;
            cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
            a[j].book::outcom();
            return;
        }
        else
        {
            cout<<"输入错误!"<<endl;
            break;
        }
}
void group::get()
{
    char s[40];
    int i;
    cout<<"请输入你要借的书的登录号:"<<endl;
    cin>>s;
    {
        for(i=0;i<book::n;i++)
            if(!strcmp(a[i].id,s))
            {
                cout<<"你要借书的信息:"<<endl;
                cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
                a[i].book::outcom();
                cout<<"该书可借阅,是否借阅确定(y)/取消(n),请输入:"<<endl;
                char c;
                cin>>c;
                if(c=='y')
                {
                    strcpy(a[i].id,s);
                    return;
                }
                else
                {
                    cout<<"取消借阅!"<<endl;
                    return;
                }
            
            }
    }
}
void group::back()
{
    char n[15];
    int i;
    cout<<"请输入你要还书的登录号:";
    cin>>n;
    {
        for(i=0;i<book::n;i++)
            if(!strcmp(a[i].id,n))
            {
                cout<<"你要还d书的信息:"<<endl;
                cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
                a[i].book::outcom();
                cout<<"还书成功!"<<endl;
                return;
            }
    }
}
void group::inquire()
{
    char n[15];
    cout<<"请输入书目登录号"<<endl;
    cin>>n;
    cout<<"借走的人是:"<<a->reader<<endl;
    return;
}

int group::menu()
{
    int i;
    cout<<"                         ***图书管理系统***~"<<endl;
    cout<<"                             1.添加新书"<<endl;
    cout<<"                             2.删除旧书"<<endl;
    cout<<"                             3.查找书目"<<endl;
    cout<<"                             4.借书"<<endl;
    cout<<"                             5.还书"<<endl;
    cout<<"                             6.查询借书人"<<endl;
    for(;;)
    {
        cin>>i;
        if(i<1||i>10)
            cout<<"输入错误,请重试,并选择(1~6)!:"<<endl;
        else break;
    }
    return i;
}
void main()
{
    char c='y';
    int n;
    cout<<"请输入藏书数目---n"<<endl;
    cin>>n;
    group a(n);
    while(c=='y')
    {
        switch(a.menu())
        {
            case 1: a.add();break;
            case 2: a.del();break;
            case 3: a.find();break;
            case 4: a.get();break;
            case 5: a.back();break;
            case 6: a.inquire();break;
        }
    }
}
搜索更多相关主题的帖子: 管理系统 private include public number 
2013-06-19 15:32
joy2
Rank: 2
等 级:论坛游民
帖 子:5
专家分:47
注 册:2013-6-18
收藏
得分:10 
感谢分享
---------------------------------------
斗破乾坤 http://www.
2013-06-19 16:12
快速回复:图书管理系统代码。要注释
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036653 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved