标题:关于类的继承的一些程序,请问错在哪了,求解
取消只看楼主
飘羽
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2010-12-24
结帖率:100%
已结贴  问题点数:20 回复次数:0 
关于类的继承的一些程序,请问错在哪了,求解
// Note:Your choice is C++ IDE
#include <iostream>
using namespace std;
class publication{
    private:
     int price,year,month,day;
    public:
     char title[10];
     char name[10];
     int a,int b,int c;
     publication();
     ~publication();
     void inputdata()
     {
         cout<<"请输入出版日期a,b,c的值:"<<endl;
         cin>>a>>b>>c;
         cout<<"请输入出版物的标题:"<<endl;
         for(int i=0;i<10;i++)
         {
             cin>>title[i];
         }
         cout<<"请输入出版物的名称:"<<endl;
         for(i=0;i<10;i++)
         {
             cin>>name[i];
         }
         cout<<"请输入单价:"<<endl;
         cin>>price;
     }
     int getprice(){return price;}
     void date()
     {
         year=a;
         month=b;
         day=c;
         cout<<year<<"."<<month<<"."<<day;
     }
     void display()
     {
         cout<<"出版物的标题为:"<<endl;
         cout<<title<<endl;
         cout<<"出版物的名称为:"<<endl;
         cout<<name<<endl;
         cout<<"出版物的单价为:"<<endl;
         cout<<price<<endl;
         cout<<"出版日期为:"<<endl;
         date();
     }
};

class book:public publication{
    private:
      int page;
    public:
      int getpage(){return page;}
      book();
      ~book();
      void inputdata()
      {
          publication::inputdata();
          cout<<"请输入需要保存的图书页数:"<<endl;
          cin>>page;
      }
      void display()
      {
          publication::display();
          cout<<"保存的图书页数为:"<<endl;
          cout<<page;
      }
};

class tape:public publication{
    private:
      int hour,minute,second;
    public:
    int l,m,n;
    void playtime()
    {
        hour=l;
        minute=m;
        second=n;
        cout<<hour<<"."<<minute<<"."<<second;
    }
    tape();
    ~tape();
    void inputdata()
    {
          publication::inputdata();
          cout<<"请输入要保存的播放时间:"<<endl;
          cin>>l>>m>>n;
    }
    void display()
    {
        publication::display();
        cout<<"保存的播放时间为:"<<endl;
        playtime();
    }
};
   
void main()
{
    publication    p;
    book b;
    tape t;
    p.inputdata();
    p.display();
    b.inputdata();
    b.display();
    t.inputdata();
    t.display();
}
      

     
搜索更多相关主题的帖子: 出版物 
2011-04-12 00:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-336361-1-1.html




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

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