http://blog.csdn.net/ly21st http://ly21st.blog.chinaunix.net
分类: C/C++
2011-12-01 10:53:03
#include
//#inclde
#include
using namespace std;
class Base{
public:
Base(const string& str,double i):book(str),price(i) {}
virtual double net_price(int n) const
{
// cout<<"调用Base中的函数"<
return n*price;
}
protected:
string book;
double price;
};
class DisCount:public Base {
public:
DisCount(const string& str,double i,int n,double dis):Base(str,i),min(n),discount(dis) {}
double net_price(int n) const=0;
protected:
int min;
double discount;
};
class Bulk:public DisCount {
friend istream& operator>>(istream &in,Bulk &bulk);
//friend ostream& operator<<(ostream &out,Bulk &bulk);
public:
Bulk(const string& str,double i,int n,double dis): DisCount(str,i,n,dis) {}
double net_price(int n) const
{
// cout<<" 调用Bulk中的函数"<
if (n >= min)
return n*(1-discount)*price;
else
return n*price;
}
};
istream& operator>>(istream &in,Bulk &bulk)
{
int solds;
cout<<"输入isbn、price、solds、打折至少的数量、折扣:";
in>>bulk.book>>bulk.price>>solds>>bulk.min>>bulk.discount;
cout<
return in;
}
int main()
{
// vector
vector
string book;
double price;
int min;
double discount;
double sum=0;
/* while(cout<<"输入isbn、price、打折至少的数量、折扣:",
cin>>book>>price>>min>>discount) {
vect.push_back(Bulk(book,price,min,discount));
}
*/
while(cout<<"输入isbn、price、打折至少的数量、折扣:",
cin>>book>>price>>min>>discount) {
Bulk *bulk=new Bulk(book,price,min,discount);
vect.push_back(bulk);
}
for(vector
sum+=(*iter)->net_price(100);
cout<<"总售价为:"<
for(vector
delete *iter;
/*
string str="java";
Bulk b(str,30,50,0.1);
cout<<"总费用为:"<
cout<<"总费用为:"<
*/
getchar();
return 0;
}