forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (43 loc) · 1.04 KB
/
main.cpp
File metadata and controls
51 lines (43 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "Element.h"
#include "Visitor.h"
#include "ShoppingCart.h"
#include <Windows.h>
int main()
{
Apple *apple1 = new Apple("红富士苹果", 7);
Apple *apple2 = new Apple("花牛苹果", 5);
Book *book1 = new Book("红楼梦", 129);
Book *book2 = new Book("终结者", 49);
Cashier *cashier = new Cashier();
Customer *jungle = new Customer("Jungle");
jungle->setNum(apple1, 2);
jungle->setNum(apple2, 4);
jungle->setNum(book1, 1);
jungle->setNum(book2, 3);
ShoppingCart *shoppingCart = new ShoppingCart();
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");
delete apple1;
delete apple2;
delete book1;
delete book2;
delete cashier;
delete jungle;
delete shoppingCart;
apple1 = nullptr;
apple2 = nullptr;
book1 = nullptr;
book2 = nullptr;
cashier = nullptr;
jungle = nullptr;
shoppingCart = nullptr;
return 0;
}