2019-11-10 14:59:08 +00:00
|
|
|
#include "Element.h"
|
|
|
|
#include "Visitor.h"
|
|
|
|
#include "ShoppingCart.h"
|
2023-08-26 08:44:30 +00:00
|
|
|
// #include <Windows.h>
|
2019-11-10 14:59:08 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2021-10-28 15:15:51 +00:00
|
|
|
Apple *apple1 = new Apple("红富士苹果", 7);
|
|
|
|
Apple *apple2 = new Apple("花牛苹果", 5);
|
|
|
|
Book *book1 = new Book("红楼梦", 129);
|
|
|
|
Book *book2 = new Book("终结者", 49);
|
2019-11-10 14:59:08 +00:00
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
Cashier *cashier = new Cashier();
|
|
|
|
Customer *jungle = new Customer("Jungle");
|
2019-11-10 14:59:08 +00:00
|
|
|
jungle->setNum(apple1, 2);
|
|
|
|
jungle->setNum(apple2, 4);
|
|
|
|
jungle->setNum(book1, 1);
|
|
|
|
jungle->setNum(book2, 3);
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
ShoppingCart *shoppingCart = new ShoppingCart();
|
2019-11-10 14:59:08 +00:00
|
|
|
shoppingCart->addElement(apple1);
|
|
|
|
shoppingCart->addElement(apple2);
|
|
|
|
shoppingCart->addElement(book1);
|
|
|
|
shoppingCart->addElement(book2);
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
shoppingCart->accept(jungle);
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
shoppingCart->accept(cashier);
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
system("pause");
|
2020-11-29 02:02:40 +00:00
|
|
|
|
|
|
|
delete apple1;
|
|
|
|
delete apple2;
|
|
|
|
delete book1;
|
|
|
|
delete book2;
|
|
|
|
delete cashier;
|
|
|
|
delete jungle;
|
|
|
|
delete shoppingCart;
|
2022-03-09 23:53:38 +00:00
|
|
|
apple1 = nullptr;
|
|
|
|
apple2 = nullptr;
|
|
|
|
book1 = nullptr;
|
|
|
|
book2 = nullptr;
|
|
|
|
cashier = nullptr;
|
|
|
|
jungle = nullptr;
|
|
|
|
shoppingCart = nullptr;
|
2020-11-29 02:02:40 +00:00
|
|
|
|
2019-11-10 14:59:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|