Bonjour à tous.
Voia ma deuxième source après mon gestionnaire mathématiques de Janvier.
Ce gestionnaire est un petit programme permettant de créér des fichiers d'emplois ou de missions intérimaires effectués.L'essentiel de ce programme
réside dans l'écriture et lecture de fichiers.
Comme je ne pratique pas souvent en C++, j'aimerais des commentaires pour connaître les points forts et points faibles du programme.
Comme vous verrez, je suis beaucoup poussé sur la présentation visuelle du programme, ce qui explique les multiples couleurs.
Merci, et bonne programmation à tous.
Source / Exemple :
#include<iostream> // librairie du C++.
#include<stdlib.h> // pour system("");
#include<conio.c> // Affichage des couleurs
#include<conio.h>
#include<fstream>
// Travail sous DEV-C++ Version 4.9.6.0
int menu();
int Ecrire();
int Rappel();
int sup() ;
int modif_emploi();
int numbermenu();
int number();
int rapnumber();
int modif();
int SITE();
int Apropos();
struct NAME // première structure de stockega pour les donnéés emploi
{
char type_de_tr[60];
char societe_de_tr[60];
char lieu_de_tr[60];
char duree_de_tr1[60];
char duree_de_tr2[60];
char boite_int[60];
};
NAME temp;
struct NUMERO // deuxieme structure pour les données numériques sociales
{
char N_S_sociale[20];
char N_ANPE[20];
char N_Assedic[20];
char N_Bancaire[20];
};
NUMERO social;
int main()
{
menu(); // menu principal
}
int menu()
{
system("cls");
int rep;
textcolor(WHITE); cout<<endl;
cout <<" GESTIONNAIRE DE TRAVAIL " << endl<<endl;textcolor(LIGHTCYAN);
cout <<"\n_________________________________________________" << endl<<endl;
cout << " [1] NOUVEAU DOSSIER [5] NUMEROS SOCIAUX " << endl<<endl;
cout << " [2] OUVRIR UN DOSSIER [6] SITE ASSEDIC " << endl<<endl;
cout << " [3] SUPPRIMER UN DOSSIER [7] A PROPOS DE " << endl<<endl;
cout << " [4] MODIFIER UN DOSSIER [8] SORTIR " << endl<<endl;
cout <<"\n_________________________________________________" << endl<<endl;
do{
rep = getch(); // l'affichiage est instantané, ne nécéssitant pas d'appuyer
// sur ENTREE
}while ((rep <'1') || (rep > '8'));
switch(rep)
{
case '1':
Ecrire();
break;
case '2':
Rappel();
break;
case '3':
sup();
break;
case '4':
modif_emploi();
break;
case '5':
numbermenu();
break;
case '6':
SITE();
break;
case '7':
Apropos();
break;
case '8':
return '0';
} // fin d'accolade du menu principal
} // fin d'accolade du main();
//______________________________________________________________________________
//---------------------- PARTIE SUR LES EMPLOIS--------------------------------
//______________________________________________________________________________
int Ecrire() // Entrée des Données
{
// Simple Confirmation pour valider l'entre voulue de données
int confirm;textcolor(YELLOW);
cout << "\n\nCONFIRMATION DE CREATION D'UN FICHIER" << endl<<endl;
textcolor(WHITE);
cout <<"[1] ANNULER " << endl ;
cout <<"[2] CONFIRMATION " << endl << endl;
confirm = getch();
if ( confirm == '1') //reout menu principal si non
menu();
else // entrée des données acceptée
textcolor(LIGHTGREEN);
Beep(800, 40);
system("cls");
cout <<"\n\nCREATION D'UN FICHIER" << endl;
cout <<"\n_________________________________________________" << endl<<endl;
cout <<endl<<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tType de Travail: ";
textcolor(WHITE);
cin.getline (temp.type_de_tr, 60); cout <<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tSociete de Travail: ";
textcolor(WHITE);
cin.getline (temp.societe_de_tr, 60); cout <<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tLieu de Travail: ";
textcolor(WHITE);
cin.getline (temp.lieu_de_tr, 60); cout <<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tDuree de Travail: "<<endl;textcolor(LIGHTGREEN);
cout << "\t\t\tDu : ";
textcolor(WHITE);
cin.getline (temp.duree_de_tr1, 60); cout <<endl;
textcolor(LIGHTGREEN);
cout << "\t\t\tAu : ";
textcolor(WHITE);
cin.getline (temp.duree_de_tr2, 60); cout <<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tSociete Interimaire: ";
textcolor(WHITE);
cin.getline (temp.boite_int, 60); cout <<endl ;
textcolor(LIGHTCYAN);
char REG[15]; // variable de nomination du fichier
cout <<"\n\n\n\n\nENREGISTRER SOUS : ";
cin.getline (REG,15);
ofstream ecriture ( REG, ios::app); // Ecriture dans la structure NAME
ecriture.write((char*)&temp.type_de_tr, sizeof(temp.type_de_tr));
ecriture.write((char*)&temp.societe_de_tr, sizeof(temp.societe_de_tr));
ecriture.write((char*)&temp.lieu_de_tr, sizeof(temp.lieu_de_tr));
ecriture.write((char*)&temp.duree_de_tr1, sizeof(temp.duree_de_tr1));
ecriture.write((char*)&temp.duree_de_tr2, sizeof(temp.duree_de_tr2));
ecriture.write((char*)&temp.boite_int, sizeof(temp.boite_int));
ecriture.close();
return menu(); // fin de cette partie et retour menu
}
//----------------------------rappel des emplois-------------------------------
int Rappel() // rappel du fichier crée
{
textcolor(LIGHTCYAN);
cout << "\n\nOUVRIR SOUS : "; textcolor ( WHITE);
char REG[15];
//--------Test pour determiner si un fichier existe lors de son appel
ifstream fichier;
cin.getline(REG, 15);
fichier.open(REG);
if (fichier.fail())
{
Beep(200, 100);
textcolor(LIGHTRED);
cout << "le fichier demande n'existe pas";
Sleep(1000);
return Rappel();
// si le fichier n'existe pas, inscription d'un message d'erreur
// et renvoie au menu principal
}
else
Sleep(100);
// Sinon, suite et ouvertutr du fichier cible
system("cls");
textcolor(LIGHTCYAN);
cout << "\n\n\nLe fichier ";textcolor(YELLOW);
cout << REG;textcolor(LIGHTCYAN);cout << " est en cours d'ouverture " << endl;
cout <<"\n_________________________________________________" << endl<<endl;
ifstream lecture(REG); // lectute des informations
lecture.read((char*)&temp.type_de_tr, sizeof(temp.type_de_tr));
lecture.read((char*)&temp.societe_de_tr, sizeof(temp.societe_de_tr));
lecture.read((char*)&temp.lieu_de_tr, sizeof(temp.lieu_de_tr));
lecture.read((char*)&temp.duree_de_tr1, sizeof(temp.duree_de_tr1));
lecture.read((char*)&temp.duree_de_tr2, sizeof(temp.duree_de_tr2));
lecture.read((char*)&temp.boite_int, sizeof(temp.boite_int));
// Inscription des données du fichier ouvert
cout <<endl<<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tType de Travail: ";
textcolor(WHITE);
cout <<temp.type_de_tr << endl<< endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tSocietede Travail: ";
textcolor(WHITE);
cout << temp.societe_de_tr << endl<< endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tLieu de Travail: ";
textcolor(WHITE);
cout <<temp.lieu_de_tr << endl<< endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tDuree de Travail: "<<endl<< endl;
textcolor(LIGHTGREEN);
cout << "\t\t\tDu : ";
textcolor(WHITE);
cout <<temp.duree_de_tr1 << endl<< endl;
textcolor(LIGHTGREEN);
cout << "\t\t\tAu : ";
textcolor(WHITE);
cout <<temp.duree_de_tr2 << endl<< endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tSociete Interimaire: ";
textcolor(WHITE);
cout <<temp.boite_int <<endl<< endl;
textcolor(LIGHTCYAN);
lecture.close();
cout << "__________________________________________________________________" <<endl << endl;
system("Pause");
return menu();
}
//----------------------------modif des emplois-------------------------------
int modif_emploi()
{ // debut de modif
char REG[15]; // Encore variable pour nomination du fichier a ouvrir
cout << "\n\nOUVRIR SOUS : "; textcolor ( WHITE);
ifstream emploi; // Identique a la fonction Rappel();
// Toujours pour vérifier l'existence d'un fichier
cin.getline(REG, 15);
emploi.open(REG);
if (emploi.fail())
{ // accolade de if
Beep(200, 100);
textcolor(LIGHTRED);
cout << "le fichier demande n'existe pas";
Sleep(1000);
return Rappel();
} // fin d'accolade de if
else
Sleep(100);
ifstream lecture(REG); // lecture des infos du fichier ouvert
lecture.read((char*)&temp.type_de_tr, sizeof(temp.type_de_tr));
lecture.read((char*)&temp.societe_de_tr, sizeof(temp.societe_de_tr));
lecture.read((char*)&temp.lieu_de_tr, sizeof(temp.lieu_de_tr));
lecture.read((char*)&temp.duree_de_tr1, sizeof(temp.duree_de_tr1));
lecture.read((char*)&temp.duree_de_tr2, sizeof(temp.duree_de_tr2));
lecture.read((char*)&temp.boite_int, sizeof(temp.boite_int));
// indication d'un sous menu pour déterminer quel type de données est à changer
textcolor(LIGHTCYAN);
cout << "\n\n\nLe fichier ";textcolor(YELLOW);
cout << REG;textcolor(LIGHTCYAN);cout << " est en cours de modification" << endl;
cout <<"\n_________________________________________________" << endl<<endl;
textcolor(YELLOW);
cout << "\nQuel numero voulez vous changer ?" << endl << endl;textcolor(WHITE);
cout << "[1] TYPE DE TRAVAIL = "<< endl<< endl;
cout << "[2] SOCIETE DE TRAVAIL" << endl<< endl;
cout << "[3] LIEU DE TRAVAIL" << endl<< endl;
cout << "[4] DEBUT DE DUREE DE TRAVAIL" << endl<< endl;
cout << "[5] FIN DE DUREE DE TRAVAIL" << endl<< endl;
cout << "[6] BOITE INTERIMAIRE" << endl<< endl;textcolor(LIGHTGREEN);
cout << "[7] ANNULER"<< endl << endl;
int demande;
do{
demande = getch();
}while ((demande <'1') || (demande > '8'));
switch(demande)
{
case '1':
textcolor(WHITE);
cout << "\t\t\tType de travail: ";
textcolor(WHITE);
cin.getline (temp.type_de_tr, 60);
break;
case '2':
textcolor(LIGHTCYAN);
cout << "\t\t\tSociete de travail: ";
textcolor(WHITE);
cin.getline (temp.societe_de_tr, 60);
break;
case '3':
textcolor(LIGHTCYAN);
cout << "\t\t\tLieu de travail: ";
textcolor(WHITE);
cin.getline (temp.lieu_de_tr , 60);
break;
case '4':
textcolor(LIGHTCYAN);
cout << "\t\t\tDebut de Duree de travail: ";
textcolor(WHITE);
cin.getline (temp.duree_de_tr1, 60);
break;
case '5':
textcolor(LIGHTCYAN);
cout << "\t\t\tFin de Duree de travail: ";
textcolor(WHITE);
cin.getline (temp.duree_de_tr2, 60);
break;
case '6':
textcolor(LIGHTCYAN);
cout << "\t\t\tBoite Interimaire: ";
textcolor(WHITE);
cin.getline (temp.boite_int, 60);
break;
case '7':
return menu();
}
ofstream ecriture (REG); // réinscription de la nouvelle donnée
ecriture.write((char*)&temp.type_de_tr, sizeof(temp.type_de_tr));
ecriture.write((char*)&temp.societe_de_tr, sizeof(temp.societe_de_tr));
ecriture.write((char*)&temp.lieu_de_tr, sizeof(temp.lieu_de_tr));
ecriture.write((char*)&temp.duree_de_tr1, sizeof(temp.duree_de_tr1));
ecriture.write((char*)&temp.duree_de_tr2, sizeof(temp.duree_de_tr2));
ecriture.write((char*)&temp.boite_int, sizeof(temp.boite_int));
ecriture.close();
return menu();
}
//______________________________________________________________________________
//---------------------- PARTIE SUR LES NUMEROS SOCIAUX------------------------
//______________________________________________________________________________
int numbermenu()
{
system ("cls");cout << endl<< endl << endl;
textcolor(LIGHTRED);
int rep;
cout << " DOSSIER DES NUMEROS SOCIAUX " << endl<<endl;
textcolor(LIGHTCYAN);
cout << " _________________________________________________________________" << endl << endl;
textcolor(WHITE);
cout << " [1] INSCRIPTION [2} LECTURE [3}] MODIFIER [4] MENU " << endl << endl;
textcolor(LIGHTCYAN);
cout << "__________________________________________________________________" << endl << endl;
do{
rep = getch();
}while ((rep <'1') || (rep > '4'));
switch(rep)
{
case '1':
number();
case '2':
rapnumber();
case '3':
modif();
case '4':
menu();
}
}
//---------------------- INSCRIPTION DES NUMEROS SOCIAUX-------------------------
int number() // Fonction d'inscripton des données numériques sociales
{
cout <<endl<<endl;
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero de Securite Sociale: ";
textcolor(WHITE);
cin.getline (social.N_S_sociale, 20);
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero d'identifiant ANPE: ";
textcolor(WHITE);
cin.getline (social.N_ANPE, 20);
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero Code ASSEDIC: ";
textcolor(WHITE);
cin.getline (social.N_Assedic , 20);
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero BANCAIRE: ";
textcolor(WHITE);
cin.getline (social.N_Bancaire, 20);
ofstream ecriture("NUM.txt",ios::app); // Ecriture dans la structure NUMERO
// Les données sont inscrites dans un fichier ".txt".
ecriture.write((char*)&social.N_S_sociale, sizeof(social.N_S_sociale));
ecriture.write((char*)&social.N_ANPE, sizeof(social.N_ANPE));
ecriture.write((char*)&social.N_Assedic , sizeof(social.N_Assedic ));
ecriture.write((char*)&social.N_Bancaire, sizeof(social.N_Bancaire));
return menu();
}
//---------------------- RAPPEL DES NUMEROS SOCIAUX-----------------------------
int rapnumber() // Rappel du fichier NUM.txt ou sont inscrites les données
{
textcolor(LIGHTCYAN);
ifstream lecture("NUM.txt"); // lecture du fichier
lecture.read((char*)&social.N_S_sociale, sizeof(social.N_S_sociale));
lecture.read((char*)&social.N_ANPE, sizeof(social.N_ANPE));
lecture.read((char*)&social.N_Assedic , sizeof(social.N_Assedic ));
lecture.read((char*)&social.N_Bancaire, sizeof(social.N_Bancaire));
cout <<endl<<endl; // inscription des données
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero Securite Sociale: ";
textcolor(WHITE);
cout <<social.N_S_sociale << endl;
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero d'identifiant ANPE: ";
textcolor(WHITE);
cout <<social.N_ANPE << endl;
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero Code ASSEDIC: ";
textcolor(WHITE);
cout <<social.N_Assedic << endl;
textcolor(LIGHTCYAN);
cout << "\n\t\t\tNumero BANCAIRE: ";
textcolor(WHITE);
cout <<social.N_Bancaire << endl;
textcolor(LIGHTCYAN);cout << endl<<endl;
cout << "__________________________________________________________________" <<endl << endl;
textcolor(WHITE);
system("Pause");
return menu();
}
//---------------------- MODIF DES NUMEROS SOCIAUX-----------------------------
int modif() // Similaire à la fonction modif_emploi();
{
textcolor(YELLOW);
cout << "Quel numero voulez vous changer ?" << endl << endl;textcolor(WHITE);
cout << "[1] Numero De SECURITE SOCIALE"<< endl << endl;
cout << "[2] Numero d'identifiant ANPE: "<< endl << endl;
cout << "[3] Numero Code ASSEDIC: "<< endl << endl;
cout << "[4] Numero BANCAIRE "<< endl << endl;
cout << "[5] Annuler "<< endl << endl;
int rep;
do{
rep = getch();
}while ((rep <'1') || (rep > '5'));
switch(rep)
{
case '1':
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero Securite Sociale: ";
textcolor(WHITE);
cin.getline (social.N_S_sociale, 20);
break;
case '2':
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero d'identifiant ANPE: ";
textcolor(WHITE);
cin.getline (social.N_ANPE, 20);
break;
case '3':
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero Code ASSEDIC: ";
textcolor(WHITE);
cin.getline (social.N_Assedic , 20);
break;
case '4':
textcolor(LIGHTCYAN);
cout << "\t\t\tNumero BANCAIRE: ";
textcolor(WHITE);
cin.getline (social.N_Bancaire , 20);
break;
case '5':
return menu();
}
ofstream ecriture ("NUM.txt"); // réécriture de la donné changée dans NUM.txt
ecriture.write((char*)&social.N_S_sociale, sizeof(social.N_S_sociale));
ecriture.write((char*)&social.N_ANPE, sizeof(social.N_ANPE));
ecriture.write((char*)&social.N_Assedic , sizeof(social.N_Assedic ));
ecriture.write((char*)&social.N_Bancaire, sizeof(social.N_Bancaire));
ecriture.close();
return numbermenu();
}
////----------------------------------------------------------------------------
//---------------------- SUPRESSION DES DOSSIERS EN COURS-----------------------
int sup() // supression des fichiers crées
{
textcolor(WHITE);
char filename [15];
cout << " Nom du dossier a supprimer : " ;
cin.getline( filename, 15);
// Ici je n'ai pas pu ajouter le test d'existence d'un fichier.
// Le test se déroule bien, mais, après, les fichiers ne sont plus supprimés
// comme si on supprimait dans le vide.
cout << "\n\nETES VOUS CERTAIN DE VOULOIR SUPPRIMER LE FICHIER ";
textcolor(LIGHTGREEN);cout << filename << " ? ";
cout <<"\n\n[1] SUPPRESSION " << endl << endl;
cout <<"[2] ANNULER " << endl << endl;
int confirmation;
do{
confirmation = getch();
}while ((confirmation <'1') || (confirmation > '2'));
switch(confirmation)
{
case '1':
remove(filename);textcolor(YELLOW);
cout << " DOSSIER SUPPRIME ! " ;Sleep( 1000);
return menu();
break;
case '2':
return menu();
}
}
//---------------------- LISTE DE NUMEROS UTILES-------------------------------
int SITE()
{
int choix;
textcolor(YELLOW);
cout << "[1] ACCES DIRECT AU SITE ASSEDIC : " << endl << endl;textcolor(WHITE);
cout << "[2] RETOUR MENU : "<< endl;
do{
choix = getch();
}while ((choix <'1') || (choix > '2'));
switch(choix )
{
case '1':
system("start http://www.assedic.fr");
return menu();
break;
case '2':
return menu();
}
}
//---------------------- AIDE--------------------------------------------------
int Help()
{
cout<<" Placer l'application dans un nouveau dossier. au cas d'un oubli,"<<endl;
cout <<" pous pouvez retrouver tous les dossiers en cours... " << endl;
system("Pause");
return menu();
}
//---------------------- MON TRAVAIL-------------------------------------------
int Apropos()
{
textcolor(LIGHTGREEN);
cout << "MUNTOYA "<<endl;textcolor(WHITE);
cout << "Gestionnaire D'emplois, version 0.1 , 10 Aout 2003" << endl;
cout << "Pour toute suggestion, mon email = djsantiano2002@yahoo.fr " << endl<< endl;
system("Pause");
return menu();
}
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.