2 / 1 / 1
Регистрация: 29.03.2017
Сообщений: 15
|
|
1 | |
Задача по ООП: классы Аптека/Лекарство/Рецепт25.11.2018, 16:50. Показов 3696. Ответов 2
Метки нет Все метки)
(
Привет. Дайте идею как решить. Использовать ли списки, если да, то как. Или можно использовать массивы объектов? Какие методы реализовать?
Класс АПТЕКА содержит список объектов класса ЛЕКАРСТВА. Класс ЛЕКАРСТВА содержит название препарата, инструкцию к применению, стоимость. Класс РЕЦЕПТ содержит перечень лекарств. Определить необходимые данные, конструкторы, деструкторы и методы работы с элементами данных. Определить наличие нужных лекарств в аптеке и стоимость лекарств по рецепту.
0
|
|
25.11.2018, 16:50 | |
Ответы с готовыми решениями:
2
ООП Классы Классы и объекты в ооп и с++ Начало ООП. Классы
|
Мозгоправ
|
|
26.11.2018, 01:13 | 2 |
Странная задача. Чем отличается класс АПТЕКА от класса РЕЦЕПТ?
Можно конечно изгальнуться и реализовать РЕЦЕПТ как массив указателей на ЛЕКАРСТВА, но тогда РЕЦЕПТ будет гарантированно правильным только для одной АПТЕКИ, а это не есть хорошо. Пофиг. При таком количестве входной информации невозможно определить какой контейнер лучше использовать. У вас же написано: Собрать волю в кулак, сесть и написать.
0
|
0 / 0 / 0
Регистрация: 04.01.2021
Сообщений: 1
|
|
04.01.2021, 22:03 | 3 |
#include <iostream>
#include <algorithm> #include <utility> #include <vector> using namespace std; class Medicine { string name_; double concentr_; string instr_; double price_; public: Medicine(string name, double concentr, string instr, double price) // конструктор : name_(move(name)), concentr_(concentr), instr_(move(instr)), price_(price) {} bool operator==(const Medicine& other) { return name_ == other.name_ && concentr_ == other.concentr_ && instr_ == other.instr_ && price_ == other.price_; } public: const string& getName() const { return name_; } void setName(const string& name) { name_ = name; } double getConcentr() const { return concentr_; } void setConcentr(double concentr) { concentr_ = concentr; } const string& getInstr() const { return instr_; } void setInstr(const string& instr) { instr_ = instr; } double getPrice() const { return price_; } void setPrice(double price) { price_ = price; } }; class Prescription { private: vector<Medicine> medicines_; public: void add(const Medicine& obj) { medicines_.push_back(obj); } public: const vector<Medicine>& getMedicines() const { return medicines_; } void setMedicines(const vector<Medicine>& medicines) { medicines_ = medicines; } }; class ******cy { public: void add(const Medicine& obj) { medicines_.push_back(obj); } bool has(const Medicine& obj) { return find(medicines_.begin(), medicines_.end(), obj) != medicines_.end(); } private: vector<Medicine> medicines_; public: const vector<Medicine>& getMedicines() const { return medicines_; } void setMedicines(const vector<Medicine>& medicines) { medicines_ = medicines; } }; int main() { cout << "Enter the number of medicines in ******cy: "; int n; cin >> n; ******cy ******cy; for (int i = 0; i < n; i++) { string name; double concentr; string instr; double price; cout << "Enter name of medicine: "; cin >> name; cout << "Enter concentration of medicine: "; cin >> concentr; cout << "Enter instruction for medicine: "; cin >> instr; cout << "Enter cost of medicine: "; cin >> price; cout << endl; ******cy.add(Medicine(name, concentr, instr, price)); } cout << "Enter number of medicines in receipt: "; cin >> n; Prescription recipe; for (int i = 0; i < n; i++) { string name; double concentr; string instr; double price; cout << "Enter name of medicine: "; cin >> name; cout << "Enter concentration of medicine: "; cin >> concentr; cout << "Enter instruction for medicine: "; cin >> instr; cout << "Enter cost of medicine: "; cin >> price; cout << endl; recipe.add(Medicine(name, concentr, instr, price)); } double totalPrice = 0; for (auto& medicine : recipe.getMedicines()) { if (!******cy.has(medicine)) cerr << medicine.getName() << " is not available now" << endl; else totalCost += medicine.getPrice(); } cout << "The total price is " << totalPrice << " UAN" << endl; return 0; }
0
|
04.01.2021, 22:03 | |
Помогаю со студенческими работами здесь
3
ООП. Классы, наследование, векторы
VS2012 классы, заголовочные файлы, ООП
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |