#include<iostream>
using namespace std;
class Sales_item{
public:
double avg_price() const;
bool same_isbn(const Sales_item &rhs) const
{
//this->units_sold = 99;
return this->isbn == rhs.isbn;
}
public:
std::string isbn;
unsigned units_sold;
double revenue;
};
double Sales_item::avg_price() const{
return (this->revenue / this->units_sold);
}
int main()
{
Sales_item item1,item2;
item1.isbn = "0-201-78345-X";
item1.units_sold =10;
item1.revenue = 300;
item2.isbn = "0-201-78345-X";
item2.units_sold = 2;
item2.revenue = 70;
if(item1.same_isbn(item2))
cout<<"Same"<<endl;
else
cout<<"Different"<<endl;
cout<<"item1:"<<item1.avg_price()<<endl;
cout<<"item2:"<<item2.avg_price()<<endl;
return 0;
}
|