Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <vector>
- #include <string>
- using namespace std;
- class Fertilizer {
- public:
- Fertilizer(const string& name, const vector<int>& schedule) : name(name), schedule(schedule) {}
- string getName() const {
- return name;
- }
- int getAmount(int week) const {
- if (week >= 0 && week < schedule.size()) {
- return schedule[week];
- }
- return 0;
- }
- private:
- string name;
- vector<int> schedule;
- };
- class GrowLog {
- public:
- void saveWatering(int week, int waterAmount) {
- ofstream logFile("grow_log.txt", ios_base::app);
- if (logFile.is_open()) {
- logFile << "Woche: " << week << ", Wassermenge: " << waterAmount << " ml" << endl;
- logFile.close();
- } else {
- cerr << "Fehler: Kann die Datei 'grow_log.txt' nicht öffnen." << endl;
- }
- }
- };
- class FertilizerPlan {
- public:
- void addFertilizer(const Fertilizer& fertilizer) {
- fertilizers.push_back(fertilizer);
- }
- void run(GrowLog& log) {
- int currentWeek;
- cout << "Aktuelle Woche eingeben (0-10): ";
- cin >> currentWeek;
- int waterAmount;
- cout << "Wassermenge in Millilitern: ";
- cin >> waterAmount;
- for (const auto& fertilizer : fertilizers) {
- int fertilizerAmount = fertilizer.getAmount(currentWeek);
- cout << fertilizer.getName() << ": " << fertilizerAmount * waterAmount / 1000.0 << " ml" << endl;
- }
- char save;
- cout << "Möchten Sie diesen Gießvorgang speichern? (J/N): ";
- cin >> save;
- if (tolower(save) == 'j') {
- log.saveWatering(currentWeek, waterAmount);
- cout << "Gießvorgang erfolgreich gespeichert." << endl;
- }
- }
- private:
- vector<Fertilizer> fertilizers;
- };
- int main() {
- // Überprüfen, ob die Datei "grow_log.txt" existiert, und ihren Inhalt ausgeben
- ifstream logFile("grow_log.txt");
- if (logFile.is_open()) {
- cout << "Inhalt von grow_log.txt:" << endl;
- string line;
- while (getline(logFile, line)) {
- cout << line << endl;
- }
- logFile.close();
- }
- cout << "\n\n";
- FertilizerPlan plan;
- GrowLog log;
- plan.addFertilizer(Fertilizer("Root-Juice", {4, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
- plan.addFertilizer(Fertilizer("BioGrow", {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}));
- plan.addFertilizer(Fertilizer("BioBloom", {0, 1, 2, 2, 3, 3, 4, 4, 4, 0}));
- plan.addFertilizer(Fertilizer("BioHeaven", {2, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
- plan.addFertilizer(Fertilizer("Top-Max", {0, 1, 1, 1, 1, 4, 4, 4, 4, 0}));
- plan.addFertilizer(Fertilizer("ActiVera", {2, 2, 2, 3, 4, 4, 5, 5, 5, 0}));
- plan.run(log);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement