-
Notifications
You must be signed in to change notification settings - Fork 549
/
Copy path04_homework_04_answer.cpp
87 lines (68 loc) · 1.85 KB
/
04_homework_04_answer.cpp
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
#include <bits/stdc++.h>
using namespace std;
class Invoice {
private:
int item_number;
string name;
double price;
int quantity;
public:
Invoice(const int &item_number, const string &name, const double &price, const int &quantity = 1);
int GetItemNumber();
void SetItemNumber(int itemNumber);
string& GetName();
void SetName(string& name);
double GetPrice();
void SetPrice(double price);
int GetQuantity();
void SetQuantity(int quantity);
double GetTotalPrice();
void Print();
string ToString();
};
Invoice::Invoice(const int &item_number, const string &name, const double &price, const int &quantity) :
item_number(item_number), name(name), price(price), quantity(quantity) {
}
int Invoice::GetItemNumber() {
return item_number;
}
void Invoice::SetItemNumber(int itemNumber) {
item_number = itemNumber;
}
string& Invoice::GetName() {
return name;
}
void Invoice::SetName(string& name) {
this->name = name;
}
double Invoice::GetPrice() {
return price;
}
void Invoice::SetPrice(double price) {
this->price = price;
}
int Invoice::GetQuantity() {
return quantity;
}
void Invoice::SetQuantity(int quantity) {
this->quantity = quantity;
}
double Invoice::GetTotalPrice() {
return GetPrice() * GetQuantity();
}
void Invoice::Print() {
cout << "Item Name: " << GetName() << "\n";
cout << "Item Price: " << GetPrice() << "\n";
cout << "Item Quantity: " << GetQuantity() << "\n";
cout << "Item item number: " << GetItemNumber() << "\n";
cout << "Item Total Price: " << GetTotalPrice() << "\n";
}
string Invoice::ToString() {
ostringstream oss;
oss << GetName() << "," << GetPrice() << "," << GetQuantity() << "," << GetItemNumber();
return oss.str();
}
// In proper class, there will be more verifications in the class and better coding
int main() {
return 0;
}