Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- //ofstream out("output_1.txt");
- // out.close();
- struct drug { //лекарство
- string name;
- string substance;
- int dose;
- string form;
- int number;
- int cost;
- bool active;
- };
- void input_drug(drug &a, string info) {
- ifstream in(info);
- cout << "Name ";
- in >> a.name;
- cout << a.name;
- cout << " Substance ";
- in >> a.substance;
- cout << a.substance;
- cout << " Dose ";
- in >> a.dose;
- cout << a.dose;
- cout << " Form ";
- in >> a.form ;
- cout << a.form;
- cout << " Number ";
- in >> a.number;
- cout << a.number;
- cout << " Cost ";
- in >> a.cost;
- cout << a.cost << endl;
- a.active = true;
- in.close();
- }
- bool substance(drug a, string b) {
- if (a.substance == b) return true;
- else return false;
- }
- double cost(drug a) {
- return a.cost;
- }
- struct store { //склад лекарств
- int n;
- drug *M;
- int money;
- store(int);
- void input_store(drug);
- void print_store(string);
- };
- store::store(int m_n) { //конструктор, инициализирующий переменную store
- n = m_n;
- drug *M = new drug[n];
- for (int i = 0; i < n; ++i) {
- M[i].active = false;
- }
- money = 0;
- }
- void store::input_store(drug a) { //метод, принимающий лекарство на склад
- for(int i = 0; i < n; ++i) {
- if (M[i].active == false) {
- M[i] = a;
- M[i].active = true;
- break;
- }
- }
- }
- void store::print_store(string sub) { //метод, выводящий лекарства с нужным веществом
- for(int i = 0; i < n; ++i) {
- cout << M[i].name << endl;
- if (M[i].active == true) {
- if (M[i].substance == sub) {
- cout << M[i].name << endl;
- }
- }
- }
- }
- int main() {
- drug tf;
- input_drug(tf, "input_1.txt");
- cout << substance(tf, "mometazon") << endl;
- cout << cost(tf) << endl;
- drug triderm;
- input_drug(triderm, "input_2.txt");
- cout << substance (triderm, "mometazon") << endl;
- cout << cost(triderm) << endl;
- store store_obj(15);
- store_obj.input_store(triderm);
- store_obj.print_store("krinazol");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement