| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:错在哪里?谢谢
取消只看楼主 加入收藏
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
快速回复:错在哪里?谢谢
数据加载中...
 
   



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

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