-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (52 loc) · 865 Bytes
/
Copy pathmain.cpp
File metadata and controls
60 lines (52 loc) · 865 Bytes
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
#include <iostream>
using namespace std;
class Pill {
public:
string name;
int price;
Pill() {}
Pill(string a, int b) {
name = a;
price = b;
}
};
struct Sheet {
Pill p[30];
int count=0;
};
ostream &operator<<(ostream &out, const Pill &pill) {
out << pill.name;
out << ",";
out << pill.price;
out << endl;
return out;
}
istream &operator>>(istream &inp, Pill &pill) {
inp >> pill.name;
inp >> pill.price;
return inp;
}
Sheet operator*(Pill P, int i) {
Sheet sh;
for(int j=0;j<i;j++) {
sh.p[j].name = P.name;
sh.p[j].price = P.price;
}
sh.count = i;
return sh;
}
ostream &operator<<(ostream &out, const Sheet &S) {
int res = 0;
for(int i=0;i<S.count;i++) {
out << S.p[i];
res += S.p[i].price;
}
out << "total = " << res;
return out;
}
int main() {
Pill P("Penicillin", 100);
Sheet S;
S = P *10;
cout << S << endl;
}