From de7d24858fffec126563a7da8532ed8332fc508e Mon Sep 17 00:00:00 2001 From: rubisalpha Date: Fri, 20 Feb 2026 14:30:21 +0000 Subject: [PATCH] Actualiser db.cpp --- db.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/db.cpp b/db.cpp index af6b890..7f1b59b 100644 --- a/db.cpp +++ b/db.cpp @@ -2,31 +2,48 @@ #include #include -bool exportData(const std::string& filename, const std::vector& students) { +bool exportData(const std::string& filename, const std::vector& students, const std::string& role, const std::string& login){ std::ofstream file(filename); if(!file.is_open()) return false; - for(auto& s : students){ - file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n"; + if(role == "ADMIN" || role == "PROF"){ + for(const auto& s : students){ + file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n"; + } + } else if(role == "STUDENT"){ + for(const auto& s : students){ + if(s.nom == login){ + file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n"; + } + } } + file.close(); return true; } -bool importData(const std::string& filename, std::vector& students) { +bool importData(const std::string& filename, std::vector& students, const std::string& role){ + if(role == "STUDENT"){ + std::cout << "Import interdit pour STUDENT.\n"; + return false; + } + std::ifstream file(filename); if(!file.is_open()) return false; std::string nom; int n1,n2,n3; - int i = 0; - while(file >> nom >> n1 >> n2 >> n3 && i < students.size()){ - students[i].nom = nom; - students[i].notes[0] = n1; - students[i].notes[1] = n2; - students[i].notes[2] = n3; - i++; + + while(file >> nom >> n1 >> n2 >> n3){ + for(auto& s : students){ + if(s.nom == nom){ + s.notes[0] = n1; + s.notes[1] = n2; + s.notes[2] = n3; + } + } } + file.close(); return true; } \ No newline at end of file