Advertisement
PiXLFAIL

biobizz

Apr 14th, 2024
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <vector>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. class Fertilizer {
  10. public:
  11.     Fertilizer(const string& name, const vector<int>& schedule) : name(name), schedule(schedule) {}
  12.  
  13.     string getName() const {
  14.         return name;
  15.     }
  16.  
  17.     int getAmount(int week) const {
  18.         if (week >= 0 && week < schedule.size()) {
  19.             return schedule[week];
  20.         }
  21.         return 0;
  22.     }
  23.  
  24. private:
  25.     string name;
  26.     vector<int> schedule;
  27. };
  28.  
  29. class GrowLog {
  30. public:
  31.     void saveWatering(int week, int waterAmount) {
  32.         ofstream logFile("grow_log.txt", ios_base::app);
  33.  
  34.         if (logFile.is_open()) {
  35.             logFile << "Woche: " << week << ", Wassermenge: " << waterAmount << " ml" << endl;
  36.             logFile.close();
  37.         } else {
  38.             cerr << "Fehler: Kann die Datei 'grow_log.txt' nicht öffnen." << endl;
  39.         }
  40.     }
  41. };
  42.  
  43. class FertilizerPlan {
  44. public:
  45.     void addFertilizer(const Fertilizer& fertilizer) {
  46.         fertilizers.push_back(fertilizer);
  47.     }
  48.  
  49.     void run(GrowLog& log) {
  50.         int currentWeek;
  51.         cout << "Aktuelle Woche eingeben (0-10): ";
  52.         cin >> currentWeek;
  53.  
  54.         int waterAmount;
  55.         cout << "Wassermenge in Millilitern: ";
  56.         cin >> waterAmount;
  57.  
  58.         for (const auto& fertilizer : fertilizers) {
  59.             int fertilizerAmount = fertilizer.getAmount(currentWeek);
  60.             cout << fertilizer.getName() << ": " << fertilizerAmount * waterAmount / 1000.0 << " ml" << endl;
  61.         }
  62.  
  63.         char save;
  64.         cout << "Möchten Sie diesen Gießvorgang speichern? (J/N): ";
  65.         cin >> save;
  66.  
  67.         if (tolower(save) == 'j') {
  68.             log.saveWatering(currentWeek, waterAmount);
  69.             cout << "Gießvorgang erfolgreich gespeichert." << endl;
  70.         }
  71.     }
  72.  
  73. private:
  74.     vector<Fertilizer> fertilizers;
  75. };
  76.  
  77. int main() {
  78.     // Überprüfen, ob die Datei "grow_log.txt" existiert, und ihren Inhalt ausgeben
  79.     ifstream logFile("grow_log.txt");
  80.     if (logFile.is_open()) {
  81.         cout << "Inhalt von grow_log.txt:" << endl;
  82.         string line;
  83.         while (getline(logFile, line)) {
  84.             cout << line << endl;
  85.         }
  86.         logFile.close();
  87.     }
  88.     cout << "\n\n";
  89.  
  90.     FertilizerPlan plan;
  91.     GrowLog log;
  92.  
  93.     plan.addFertilizer(Fertilizer("Root-Juice", {4, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
  94.     plan.addFertilizer(Fertilizer("BioGrow", {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}));
  95.     plan.addFertilizer(Fertilizer("BioBloom", {0, 1, 2, 2, 3, 3, 4, 4, 4, 0}));
  96.     plan.addFertilizer(Fertilizer("BioHeaven", {2, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
  97.     plan.addFertilizer(Fertilizer("Top-Max", {0, 1, 1, 1, 1, 4, 4, 4, 4, 0}));
  98.     plan.addFertilizer(Fertilizer("ActiVera", {2, 2, 2, 3, 4, 4, 5, 5, 5, 0}));
  99.  
  100.     plan.run(log);
  101.  
  102.     return 0;
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement