64,636
社区成员
发帖
与我相关
我的任务
分享
//============================================================================
// Name : work02.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#define N 2
using namespace std;
class Book
{
public:
void getDate(char *n,char *m,char *o,double a,double b)
{
cout << "请输入书名" << endl;
cin >> n ;
cout << "请输入作者" << endl;
cin >> m;
cout << "请输入出版社" << endl;
cin >> o;
cout << "请输入页数" << endl;
cin >> a;
pages = a;
cout << "请输入价格" << endl;
cin >> b;
price = b;
}
void setData(char *n,char *m,char *o )
{
strncpy(bookname,n,19);
strncpy(authors,m,19);
strncpy(house,o,19);
}
void outDate1()
{
cout << " 书名 "
<< "作者 "
<< "出版社 "
<< "页数 "
<< "价格 " << endl;
}
void outDate2(int i)
{
cout << i+1
<< "、 "
<< bookname
<< " "
<< authors
<< " "
<< house
<< " "
<< pages
<< " "
<< price
<< endl;
}
void invoking()
{
Book p[N];
char m[20],n[20],o[20];
int i;
double a,b;
for(i = 0;i < N;i++)
{
p[i].getDate(n,m,o,a,b);
p[i].setData(n,m,o);
}
p[0].outDate1();
for(i = 0;i < N;i++)
{
p[i].outDate2(i);
}
}
private:
char bookname[20];
char authors[20];
char house[20];
double pages;
double price;
};
int main() {
Book p;
p.invoking();
return 0;
}