| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 357 人关注过本帖
标题:请大家帮帮忙
只看楼主 加入收藏
nonganshbl
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-4-2
收藏
 问题点数:0 回复次数:0 
请大家帮帮忙
看看我这程序哪有错误
#include<iostream.h>
#include<string.h>

class base
{
private:
    int num;
    char name[10];
public:
    base(int a,char n[]){num=a;strcpy(name,n);}
    ~base();
    void show()
    {
        cout<<num<<"   "<<name;
    }
};


class book:public base
{
private:
    char author[10];
public:
    book(int a,char b[],char aut[]);
    ~book();
    void show(){base::show();cout<<"   "<<author<<endl;}
};
book::book(int a,char b[],char aut[]):base(a,b)
{
    strcpy(author,aut);
}


class reader:public base
{
private:
    int t;
    book books[10];
public:
    reader(int a,char n[]);
    ~reader();
    void show();
    void borrow(book &b);
};
reader::reader(int a,char n[]):base(a,n)
{
    t=0;
}
void reader::show()
{
    cout<<"reader: ";
    base::show();
    cout<<endl;
    cout<<"    borrow: "<<endl;
    for(int i=0;i<t;i++)
    {
        cout<<"         "<<i+1<<": ";
        books[i].show();
    }
}
void reader::borrow(book &b)
{
    books[t]=b;
        t++;
}


int main()
{
    book b[]={book(1,"aaaaa","aaa"),
        book(2,"bbbbb","bbb"),
        book(3,"ccccc","ccc"),
        book(4,"ddddd","ddd"),
        book(5,"eeeee","eee")};
    reader r[]={reader(1,"zhang"),
        reader(2,"liu"),
        reader(3,"wang")};
    r[0].borrow(b[1]);
    r[2].borrow(b[4]);
    r[1].borrow(b[3]);
    r[2].borrow(b[2]);
    r[0].borrow(b[0]);
    r[0].show();
    r[1].show();
    r[2].show();
    return 0;
}
2008-04-02 14:59
快速回复:请大家帮帮忙
数据加载中...
 
   



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

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