-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoice.cpp
More file actions
114 lines (101 loc) · 2.28 KB
/
Copy pathInvoice.cpp
File metadata and controls
114 lines (101 loc) · 2.28 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<iostream>
#include<string.h>
#include<vector>
#include <sstream>
using namespace std;
class Invoice
{
private:
string name;
int item_number;
double price;
int quantity;
public:
Invoice(const string &name, const int &item_number, const double &price, const int &quantity);
Invoice()
{
this -> name = "";
this -> item_number = 0;
this -> price = 0;
this -> quantity = 0;
}
void setName (string s);
string getName();
void setItemNum(int n);
int getItemNum();
void setPrice(double n);
double getPrice();
void setQuantity(int n);
int getQuantity();
double getTotalPrice();
void print();
string toString();
};
int main()
{
Invoice In;
In = Invoice("Laptop", 2, 50, 2);
cout << In.toString() << endl;
return 0;
}
Invoice::Invoice(const string &name, const int &item_number, const double &price, const int &quantity)
{
this -> name = name;
this -> item_number = item_number;
this -> price = price;
this -> quantity = quantity;
}
void Invoice::setName (string s)
{
this -> name = s;
}
string Invoice::getName()
{
return this -> name;
}
void Invoice::setItemNum(int n)
{
item_number = n;
}
int Invoice::getItemNum()
{
return item_number;
}
void Invoice::setPrice(double n)
{
price = n;
}
double Invoice::getPrice()
{
return price;
}
void Invoice::setQuantity(int n)
{
quantity = n;
}
int Invoice::getQuantity()
{
return 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: " << getItemNum() << "\n";
cout << "Item Total Price: " << getTotalPrice() << "\n";
}
string Invoice::toString()
{
//why the first method printed garbage values ???
//char buffer[200];
//sprintf(buffer,"%s,%d,%lf,%d",getName(), getItemNum(), getPrice(),getQuantity());
//return buffer;
ostringstream oss;
oss << getName() << "," << getPrice() << "," << getQuantity() << "," << getItemNum();
return oss.str();
}