-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.cpp
More file actions
146 lines (121 loc) · 3.21 KB
/
Product.cpp
File metadata and controls
146 lines (121 loc) · 3.21 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <string>
#include <locale>
using namespace std;
class Product {
private:
string name;
double price;
double rating;
public:
Product()
{
name = "";
price = 0.0;
rating = 0.0;
}
Product(string n, double p, double r)
{
name = n;
price = p;
rating = r;
}
string getName() {
return name;
}
double getPrice() {
return price;
}
double getRating() {
return rating;
}
};
class Category {
private:
string categoryName;
Product* products;
int numProducts;
public:
Category(string name, int num)
{
categoryName = name;
numProducts = num;
products = new Product[numProducts];
}
void setProduct(int index, string name, double price, double rating) {
products[index] = Product(name, price, rating);
}
void printProducts() {
cout << "Êàòåãîðèÿ: " << categoryName << endl;
for (int i = 0; i < numProducts; ++i) {
cout << "Íàçâàíèå òîâàðà: " << products[i].getName() << ", Öåíà: " << products[i].getPrice() << ", Ðåéòèíã: " << products[i].getRating() << endl;
}
}
~Category() {
delete[] products;
}
};
class Basket {
private:
Product* products;
int numProducts;
public:
Basket() : products(nullptr)
{
numProducts = 0;
}
void addProduct(Product product) {
Product* newProducts = new Product[numProducts + 1];
for (int i = 0; i < numProducts; ++i) {
newProducts[i] = products[i];
}
newProducts[numProducts] = product;
delete[] products;
products = newProducts;
++numProducts;
}
void printBasket() {
cout << "Ñïèñîê êóïëåííûõ òîâàðîâ:" << endl;
for (int i = 0; i < numProducts; ++i) {
cout << "Íàçâàíèå òîâàðà: " << products[i].getName() << ", Öåíà: " << products[i].getPrice() << ", Ðåéòèíã: " << products[i].getRating() << endl;
}
}
~Basket() {
delete[] products;
}
};
class User {
private:
string login;
string password;
Basket basket;
public:
User(string Login, string Password)
{
login = Login;
password = Password;
}
void addProductToBasket(Product product) {
basket.addProduct(product);
}
void printBasket() {
cout << "Êîðçèíà ïîëüçîâàòåëÿ " << login << ":" << endl;
basket.printBasket();
}
};
int main() {
setlocale(LC_ALL, "RUS");
Category category("Ýëåêòðîíèêà", 3);
category.setProduct(0, "Ñìàðòôîí", 1000.0, 4.5);
category.setProduct(1, "Íîóòáóê", 1500.0, 4.0);
category.setProduct(2, "Ïëàíøåò", 800.0, 4.2);
category.printProducts();
User user1("user1", "password1");
User user2("user2", "password2");
user1.addProductToBasket(Product("Ñìàðòôîí", 1000.0, 4.5));
user1.addProductToBasket(Product("Íàóøíèêè", 50.0, 4.0));
user2.addProductToBasket(Product("Íîóòáóê", 1500.0, 4.0));
user1.printBasket();
user2.printBasket();
return 0;
}