-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (74 loc) · 2.03 KB
/
main.cpp
File metadata and controls
91 lines (74 loc) · 2.03 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "SalesTax.h"
#include "Good.h"
#include "GoodCreator.h"
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
using std::string;
int main()
{
typedef vector<Good*> listOfGood;
listOfGood::iterator theIterator;
listOfGood Basket;
char answer = 'n';
double totalprice = 0;
double totaltax = 0;
cout<<"1 for good with no sales tax and no import duty"<<endl;
cout<<"2 for good with no sales tax only import duty"<<endl;
cout<<"3 for good with only sales tax and no import duty"<<endl;
cout<<"4 for good with both sales tax and import duty"<<endl;
do
{
// 1. get good's category
int type_of_good;
cout << "Enter the type of Good...1,2,3,4" << endl;
cin >> type_of_good;
GoodCreator* goodCreator = new GoodCreator();
try
{
// 2. create new good with the category
Good* good = goodCreator->Create(type_of_good);
// 3. init new good
cout << "Enter the title of the Good" << endl;
string title;
cin >> title;
good->SetTitle(title);
cout << "Enter the number of the Good" << endl;
double num;
cin >> num;
good->SetNum(num);
cout << "Enter the unit price of the Good" << endl;
double price;
cin >> price;
good->SetPrice(price);
// 4. add to vector
Basket.push_back(good);
}
catch(Not_A_Standard_Good_Type_Exception& e)
{
e.printerrormsg();
}
cout << "Do you want to continue... Y/N"<<endl;
cin >> answer;
}
while (answer =='y');
theIterator = Basket.begin();
/* 5. get total tax and total price */
int pos = 0;
while (theIterator != Basket.end())
{
Basket.at(pos)->CalculateTotalTax();
totaltax += Basket.at(pos)->GetTax();
Basket.at(pos)->CalculatePriceTaxed();
double priceTaxed = Basket.at(pos)->GetPriceTaxed();
totalprice += priceTaxed;
cout << Basket.at(pos)->GetNum() << " " << Basket.at(pos)->GetTitle() << ": " << Basket.at(pos)->GetPrice() << endl;
theIterator++;
pos++;
}
cout << "------------" << endl;
cout << "Toal tax " << totaltax << endl;
cout << "Total price " << totalprice << endl;
return 1;
}