版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Fiverya/article/details/88884551
编写一个程序,其中有一个书类book,该类的数据成员包括:书号、书名、出版社和定价;有一个作者类author,该类的数据成员包括:姓名、年龄和写作时间,每个类都有相应的数据输入、输出。以此两个类为基类,派生出图书查询卡card,并增加一个数据成员表示书籍系统名称,及一个可以显示系统名称、书名、作者、作者年龄、出版社和定价等数据的函数。
注: 输入数据内容有
系统名称 图书编号 图书名 出版社 定价
作者姓名 作者年龄 写作时间
输入:
BitLibrary
1001
C++Language
Bitcon
24.8
Lichunbao
40
2001 10 10
输出:
SysName:BitLibrary
Num:1001
BookName:C++Language
BookConcern:Bitcon
Price:24.8
AuthorName:Lichunbao
AuthorAge:40
PrintTime:2001-10-10
#include<iostream>
using namespace std;
class Book
{ protected:
int Num;
char BookName[20];
char BookConcern[10];
float Price;
};
class Author
{ protected:
char AuthorName[15];
int AuthorAge;
int PrintTime[3];
};
class Card:public Book,public Author
{
char SysName[15];
public:
Card(){}
void Get()
{cin>>SysName>>Num>>BookName>>BookConcern>>Price>>AuthorName>>AuthorAge>>PrintTime[0]>>PrintTime[1]>>PrintTime[2];}
void show()
{cout<<"SysName:"<<SysName<<endl<<"Num:"<<Num<<endl<<"BookName:"<<BookName<<endl<<"BookConcern:"<<BookConcern<<endl<<"Price:"<<Price<<endl;
cout<<"AuthorName:"<<AuthorName<<endl<<"AuthorAge:"<<AuthorAge<<endl<<"PrintTime:"<<PrintTime[0]<<"-"<<PrintTime[1]<<"-"<<PrintTime[2]<<endl;
}
};
int main()
{
Card card1;
card1.Get();
card1.show();
return 0;
}