Actualiser main.cpp
This commit is contained in:
72
main.cpp
72
main.cpp
@@ -1,8 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "auth.h"
|
#include "auth.h"
|
||||||
|
|
||||||
// Tableau d'utilisateurs
|
// --- Tableau d'utilisateurs ---
|
||||||
User users[] = {
|
User users[] = {
|
||||||
{"admin", "1234", ADMIN},
|
{"admin", "1234", ADMIN},
|
||||||
{"prof1", "abcd", PROF},
|
{"prof1", "abcd", PROF},
|
||||||
@@ -12,7 +13,7 @@ User users[] = {
|
|||||||
};
|
};
|
||||||
int nbUsers = 5;
|
int nbUsers = 5;
|
||||||
|
|
||||||
// Tableau d'étudiants et leurs notes
|
// --- Tableau d'étudiants et notes ---
|
||||||
struct Student {
|
struct Student {
|
||||||
std::string nom;
|
std::string nom;
|
||||||
int notes[3];
|
int notes[3];
|
||||||
@@ -26,7 +27,6 @@ Student etudiants[] = {
|
|||||||
int nbEtudiants = 3;
|
int nbEtudiants = 3;
|
||||||
|
|
||||||
// --- Fonctions de vues selon rôle ---
|
// --- Fonctions de vues selon rôle ---
|
||||||
|
|
||||||
void viewAdmin() {
|
void viewAdmin() {
|
||||||
std::cout << "\n--- VUE ADMIN ---\n";
|
std::cout << "\n--- VUE ADMIN ---\n";
|
||||||
std::cout << "Liste des étudiants et notes :\n";
|
std::cout << "Liste des étudiants et notes :\n";
|
||||||
@@ -35,7 +35,6 @@ void viewAdmin() {
|
|||||||
for(int j=0;j<3;j++) std::cout << etudiants[i].notes[j] << " ";
|
for(int j=0;j<3;j++) std::cout << etudiants[i].notes[j] << " ";
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
std::cout << "ADMIN peut ajouter/supprimer étudiants ou modifier notes (optionnel)\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void viewProf() {
|
void viewProf() {
|
||||||
@@ -73,8 +72,65 @@ void viewStudent(const User& user) {
|
|||||||
std::cout << "Aucune information trouvée.\n";
|
std::cout << "Aucune information trouvée.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- MAIN ---
|
// --- Fonctions d'export ---
|
||||||
|
void exportAdmin() {
|
||||||
|
std::ofstream file("data.txt");
|
||||||
|
for(int i=0; i<nbEtudiants; i++){
|
||||||
|
file << etudiants[i].nom << " ";
|
||||||
|
for(int j=0;j<3;j++) file << etudiants[i].notes[j] << " ";
|
||||||
|
file << "\n";
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
std::cout << "Export complet réalisé (ADMIN).\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void exportNotes(const User& user) {
|
||||||
|
std::ofstream file("data.txt");
|
||||||
|
for(int i=0; i<nbEtudiants; i++){
|
||||||
|
if(user.role == STUDENT && etudiants[i].nom != user.login) continue;
|
||||||
|
file << etudiants[i].nom << " ";
|
||||||
|
for(int j=0;j<3;j++) file << etudiants[i].notes[j] << " ";
|
||||||
|
file << "\n";
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
std::cout << "Export réalisé.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Fonctions d'import ---
|
||||||
|
void importAdmin() {
|
||||||
|
std::ifstream file("data.txt");
|
||||||
|
std::string nom;
|
||||||
|
int n1,n2,n3;
|
||||||
|
int i=0;
|
||||||
|
while(file >> nom >> n1 >> n2 >> n3 && i<nbEtudiants){
|
||||||
|
etudiants[i].nom = nom;
|
||||||
|
etudiants[i].notes[0] = n1;
|
||||||
|
etudiants[i].notes[1] = n2;
|
||||||
|
etudiants[i].notes[2] = n3;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
std::cout << "Import complet réalisé (ADMIN).\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void importProf() {
|
||||||
|
std::ifstream file("data.txt");
|
||||||
|
std::string nom;
|
||||||
|
int n1,n2,n3;
|
||||||
|
while(file >> nom >> n1 >> n2 >> n3){
|
||||||
|
for(int i=0;i<nbEtudiants;i++){
|
||||||
|
if(etudiants[i].nom == nom){
|
||||||
|
etudiants[i].notes[0]=n1;
|
||||||
|
etudiants[i].notes[1]=n2;
|
||||||
|
etudiants[i].notes[2]=n3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
std::cout << "Import des notes réalisé (PROF).\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- MAIN ---
|
||||||
int main() {
|
int main() {
|
||||||
std::string login, password;
|
std::string login, password;
|
||||||
|
|
||||||
@@ -89,16 +145,20 @@ int main() {
|
|||||||
if(index != -1) {
|
if(index != -1) {
|
||||||
std::cout << "Connexion réussie !" << std::endl;
|
std::cout << "Connexion réussie !" << std::endl;
|
||||||
|
|
||||||
// Afficher la vue selon le rôle
|
|
||||||
switch(users[index].role) {
|
switch(users[index].role) {
|
||||||
case ADMIN:
|
case ADMIN:
|
||||||
viewAdmin();
|
viewAdmin();
|
||||||
|
exportAdmin();
|
||||||
|
importAdmin();
|
||||||
break;
|
break;
|
||||||
case PROF:
|
case PROF:
|
||||||
viewProf();
|
viewProf();
|
||||||
|
exportNotes(users[index]);
|
||||||
|
importProf();
|
||||||
break;
|
break;
|
||||||
case STUDENT:
|
case STUDENT:
|
||||||
viewStudent(users[index]);
|
viewStudent(users[index]);
|
||||||
|
exportNotes(users[index]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user