双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

oj上一个c++,有关类的题目

qq_34660207 qq_34660207 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

这个是题目。
输入的时候怎么这样子??查了好久查不出来,求大神指点

#include <iostream>
#include <iomanip>
using namespace std;
class book
{
public:
book () {}
book(int t,int b)
{
type = t;bno = b;
}
int type;//类型
int bno;//编号
};

class lbook:public book
{
public:
lbook () {}
lbook(int t,int b,int s):book(t,b)
{
storage = s;
}
void set(int t,int b,int s)
{
storage = s;
}
int storage;
};
class pbook :public book
{
public:
pbook () {}
pbook(int t,int b,double p):book(t,b)
{
price = p;
}
void set(int t,int b,double p)
{
price = p;
}

double price;
};

int main()
{
int storge_total = 0;
double price_total = 0;
int count_pbook = 0;
int l = 0,p = 0;
book* lb[10000],* pb[1000];
int type,bno;
double st_pri;
cin >> bno >> type >> st_pri;

while(cin)
{
if (type == 0)
{
pb[p] = new pbook(type,bno,st_pri);
count_pbook ++;
price_total += st_pri;
p++;
}
if (type == 1)
{
lb[l] = new lbook(type,bno,st_pri);
storge_total += st_pri;
l++;
}


cin >> bno >> type >> st_pri;
}

for (int j = 0;j <= l;j++)
{
if (lb[j] -> type == 1)//文学
cout << lb[j] -> bno << " " << lb[j] -> type << " " << ((lbook*)lb[j]) -> storage << endl;
else continue;
}
for (int t = 0;t <= p;t++)
{
if (pb[t] -> type == 0)//理学
cout << pb[t] -> bno << " " << pb[t] -> type << " " << ((pbook*)pb[t]) -> price << endl;
else continue;
}
cout << storge_total << endl;
cout.setf(ios::fixed);
cout << setprecision(1);
cout << price_total / count_pbook << endl;

return 0;
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
qq_34660207
C++ 语言 65,214 成员 250,514 内容