Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. //ofstream out("output_1.txt");
  8. // out.close();
  9.  
  10. struct drug { //лекарство
  11. string name;
  12. string substance;
  13. int dose;
  14. string form;
  15. int number;
  16. int cost;
  17. bool active;
  18. };
  19.  
  20. void input_drug(drug &a, string info) {
  21. ifstream in(info);
  22. cout << "Name ";
  23. in >> a.name;
  24. cout << a.name;
  25. cout << " Substance ";
  26. in >> a.substance;
  27. cout << a.substance;
  28. cout << " Dose ";
  29. in >> a.dose;
  30. cout << a.dose;
  31. cout << " Form ";
  32. in >> a.form ;
  33. cout << a.form;
  34. cout << " Number ";
  35. in >> a.number;
  36. cout << a.number;
  37. cout << " Cost ";
  38. in >> a.cost;
  39. cout << a.cost << endl;
  40. a.active = true;
  41. in.close();
  42. }
  43.  
  44. bool substance(drug a, string b) {
  45. if (a.substance == b) return true;
  46. else return false;
  47. }
  48.  
  49. double cost(drug a) {
  50. return a.cost;
  51. }
  52.  
  53. struct store { //склад лекарств
  54. int n;
  55. drug *M;
  56. int money;
  57. store(int);
  58. void input_store(drug);
  59. void print_store(string);
  60. };
  61.  
  62. store::store(int m_n) { //конструктор, инициализирующий переменную store
  63. n = m_n;
  64. drug *M = new drug[n];
  65. for (int i = 0; i < n; ++i) {
  66. M[i].active = false;
  67. }
  68. money = 0;
  69. }
  70.  
  71. void store::input_store(drug a) { //метод, принимающий лекарство на склад
  72. for(int i = 0; i < n; ++i) {
  73. if (M[i].active == false) {
  74. M[i] = a;
  75. M[i].active = true;
  76. break;
  77. }
  78. }
  79. }
  80.  
  81. void store::print_store(string sub) { //метод, выводящий лекарства с нужным веществом
  82. for(int i = 0; i < n; ++i) {
  83. cout << M[i].name << endl;
  84. if (M[i].active == true) {
  85. if (M[i].substance == sub) {
  86. cout << M[i].name << endl;
  87. }
  88. }
  89. }
  90. }
  91.  
  92. int main() {
  93. drug tf;
  94. input_drug(tf, "input_1.txt");
  95. cout << substance(tf, "mometazon") << endl;
  96. cout << cost(tf) << endl;
  97.  
  98. drug triderm;
  99. input_drug(triderm, "input_2.txt");
  100. cout << substance (triderm, "mometazon") << endl;
  101. cout << cost(triderm) << endl;
  102.  
  103. store store_obj(15);
  104. store_obj.input_store(triderm);
  105. store_obj.print_store("krinazol");
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement