DesignPattern/24.VisitorPattern/2.Code/visitor.cpp

50 lines
1.1 KiB
C++
Raw Normal View History

2019-11-10 14:59:08 +00:00
#include "Visitor.h"
#include "Element.h"
/***** Customer *******/
Customer::Customer(){
this->name = "";
}
Customer::Customer(string iName){
this->name = iName;
}
void Customer::setNum(Apple* apple, int iNum){
apple->setNum(iNum);
}
void Customer::setNum(Book* book, int iNum){
book->setNum(iNum);
}
void Customer::visit(Apple* apple){
int price = apple->getPrice();
printf(" %s \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: \t%d Ԫ/kg\n", apple->getName().c_str(), apple->getPrice());
}
void Customer::visit(Book* book){
int price = book->getPrice();
string name = book->getName();
printf(" <20><>%s<><73>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: \t%d Ԫ/<2F><>\n", book->getName().c_str(), book->getPrice());
}
/***** Cashier *******/
Cashier::Cashier(){
}
void Cashier::visit(Apple* apple){
string name = apple->getName();
int price = apple->getPrice();
int num = apple->getNum();
int total = price*num;
printf(" %s <20>ܼۣ<DCBC> %d Ԫ\n", name.c_str(), total);
}
void Cashier::visit(Book* book){
int price = book->getPrice();
string name = book->getName();
int num = book->getNum();
int total = price*num;
printf(" <20><>%s<><73> <20>ܼۣ<DCBC> %d Ԫ\n", name.c_str(), total);
}