标题:错在哪里?谢谢
取消只看楼主
DG中专生
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-9-11
 问题点数:0 回复次数:1 
错在哪里?谢谢
#ifndef B
#define B
#include<iostream>
#include<string>
class b{
public:
 std::istream& input(std::istream& in);
 std::ostream& output(std::ostream& out) const;
 double a() const;
 bool isbn(const b &rhs) const
 {
  return isbn==rhs.isbn;
 }
private:
 std::string isbn;
 unsigned units_sold;
 double revenue;
};
#endif
std::istream& b::input(std::istream& in)
{
 double price;
 in>>isbn>>units_sold>>price;
 if(in)
  revenue=units_sold*price;
 else{
  units_sold=0;
  revenue=0.0;
 }
 return in;
}
std::ostream& b::output(std::ostream& out) const
{
 out<<isbn<<"\t"<units_sold<<"\t"<<revenue<<"\t"<<a();
 return out;
}
double b::a() const
{
 if(units_sold)
  return revenue/units_sold;
 else
  return 0;
}
#include<iostream>
using namespace std;
int main()
{
 b item;
 cout<<"Enter"<<endl;
 while(item.input(cin))
 {
  cout<<item.output(cout);
  cout<<endl;
 }
 return 0;
}

请问错在哪里,还有,高手可以解释一下类定义中代码的意思吗,我不太明白,谢谢
2007-12-05 22:19
DG中专生
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-9-11
得分:0 
刚机子卡了下,连续发了2个贴
2007-12-05 22:56



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




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

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