Skip to content

Instantly share code, notes, and snippets.

@tabvn
Last active June 15, 2019 02:23
Show Gist options
  • Save tabvn/25c835ce9b08e34ebc35526e8c822b48 to your computer and use it in GitHub Desktop.
Save tabvn/25c835ce9b08e34ebc35526e8c822b48 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Device {
private:
string code;
int sold;
double price;
public:
void setPrice(double price) {
Device::price = price;
}
double getPrice() const {
return price;
}
void setCode(string code) {
Device::code = code;
}
void setSold(int sold) {
Device::sold = sold;
}
string getCode() {
return code;
}
int getSold() {
return sold;
}
};
class Computer : public Device {
private:
string name, type;
public:
string getName() {
return name;
}
string getType() {
return type;
}
void setName(string name) {
Computer::name = name;
}
void setType(string type) {
Computer::type = type;
}
};
class Store {
private:
vector<Device> devices;
vector<Computer> computers;
public:
vector<Device> getDevices() {
return devices;
}
vector<Computer> getComputers() {
return computers;
}
void addComputer(Computer computer) {
Store::computers.push_back(computer);
}
void addDevice(Device device) {
Store::devices.push_back(device);
}
Computer getMaximumComputerSold() {
Computer c;
int maxSold = Store::computers[0].getSold();
for (int i = 1; i < Store::computers.size(); ++i) {
if (Store::computers[i].getSold() > maxSold) {
maxSold = Store::computers[i].getSold();
c = Store::computers[i];
}
}
return c;
}
Device getMaxiumDeviceSold() {
Device d;
int maxSold = Store::devices[0].getSold();
for (int j = 0; j < Store::devices.size(); ++j) {
if (Store::devices[j].getSold() > maxSold) {
maxSold = Store::devices[j].getSold();
d = Store::devices[j];
}
}
return d;
}
string getMaximum() {
int maxSold = Store::computers[0].getSold();
string code = Store::computers[0].getCode();
for (int i = 1; i < Store::computers.size(); ++i) {
if (Store::computers[i].getSold() > maxSold) {
maxSold = Store::computers[i].getSold();
code = Store::computers[i].getCode();
}
}
for (int j = 0; j < Store::devices.size(); ++j) {
if (Store::devices[j].getSold() > maxSold) {
maxSold = Store::devices[j].getSold();
code = Store::devices[j].getCode();
}
}
return code;
}
void print() {
Computer c;
Device d;
double total = 0;
cout << "Danh sach may tinh la: " << endl;
for (int i = 0; i < Store::computers.size(); ++i) {
c = Store::computers[i];
cout << "Name: " << c.getName() << endl;
cout << "type: " << c.getType() << endl;
cout << "Code: " << c.getCode() << endl;
cout << "Price: " << c.getPrice() << endl;
cout << "Sold: " << c.getSold() << endl;
cout << "Doanh thu:" << c.getPrice() * c.getSold() << " USD" << endl;
total += c.getPrice() * c.getSold();
cout << "-------------------------------------------" << endl;
}
cout << "Danh sach thiet bi la: " << endl;
for (int i = 0; i < Store::computers.size(); ++i) {
d = Store::devices[i];
cout << "Code: " << d.getCode() << endl;
cout << "Price: " << d.getPrice() << endl;
cout << "Sold: " << d.getSold() << endl;
cout << "Doanh thu:" << c.getPrice() * c.getSold() << " USD" << endl;
total += c.getPrice() * c.getSold();
cout << "-------------------------------------------" << endl;
}
cout << "Ma thiet bi co so luong ban cao nhat la: " << this->getMaximum() << endl;
cout << "-------------------------------------------" << endl;
cout << "Thong ke:" << endl;
cout << "Tong tien ban ra ca computer va devices:"<< total << " USD" << endl;
cout << "Thiet bi co so luong ban ra nhieu nhat la: " << this->getMaximum() << endl;
}
};
int main() {
Store s;
Computer c;
Device d;
// may tinh 1
c.setName("Dell Computer");
c.setSold(100);
c.setCode("del-001");
c.setType("desktop");
c.setPrice(100.5);
// them may tinh vao store
s.addComputer(c);
// may tinh 2
c.setName("HP Computer");
c.setSold(99);
c.setCode("hp-002");
c.setType("laptop");
c.setPrice(200.5);
// them may tinh vao store
s.addComputer(c);
// Device 1
d.setCode("banphim-001");
d.setPrice(100);
d.setSold(50);
s.addDevice(d);
// Device 2
d.setCode("chuot-002");
d.setPrice(50);
d.setSold(100);
s.addDevice(d);
// in ra danh sach
s.print();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment