All pastes #984334 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2008-04-14 03:05 UTC
rendered paste body
#include <iostream>#include <fstream>#include "position.h"#include <conio.h>using namespace std;bool fflag = true;struct Etudiant {	int numero;	char nom[20];	char telephone[15];	int matiere;	float note;	Etudiant *prec;	Etudiant *suiv;} *dernier, *premier;int MenuRecherchesListes();void retournerMenu(int menu);void MenuGestionEtudiants();int MenuMAJEtudiants();int ajouterEtudiant();void ajouterEtudiant(Etudiant *vdernier, int vnumero, char vnom[20], char vtelephone[15], int vmatiere, float vnote);Etudiant *rechercherEtudiant();int modifierNote(Etudiant *ptr);int supprimerEtudiant(Etudiant *ptr);int afficherTous();int afficherEtudiant(Etudiant *ptr);void afficherMeilleurEtudiant();void SauverFichier();// DEBUT DE SECTION MENUSvoid retournerMenu(int menu) {	switch (menu) {		case 1:			MenuGestionEtudiants();			break;		case 2:			MenuMAJEtudiants();			break;		case 3:			MenuRecherchesListes();			break;	}}void MenuGestionEtudiants() {	int res, i = -2;	effacerEcran();	gotoXY(10,1);	cout << "*******************************";	gotoXY(10,2);	cout << "*\tGestion des Etudiants\t*";	gotoXY(10,3);	cout << "*******************************";	gotoXY(1,5);	cout << "1-\tMise a jour des etudiants";	gotoXY(1,6);	cout << "2-\tRecherches et listes";	gotoXY(1,7);	cout << "3-\tSauvegarde sur fichier";	gotoXY(1,8);	cout << "4-\tChargement de structures";	gotoXY(1,9);	cout << "5-\tFin";	do {		gotoXY(1,10);	cout << "Entrez un numero: ...";		gotoXY(19,10);	cin >> res;	}	while (res < 1 || res > 5);	switch (res) {		case 1:			while (i == -2) {				i = MenuMAJEtudiants();			}			break;		case 2:			while (i == -2) {				MenuRecherchesListes();			}			break;		case 3:			break;		case 4:			SauverFichier();			retournerMenu(1);			break;	}}int MenuMAJEtudiants() {	Etudiant *recherche;	int res, i = 0;	char buffer[20];	effacerEcran();	gotoXY(10,1);	cout << "************************************";	gotoXY(10,2);	cout << "*\tMise a jour des Etudiants    *";	gotoXY(10,3);	cout << "************************************";	gotoXY(1,5);	cout << "1-\tAjout d'un nouvel etudiant";	gotoXY(1,6);	cout << "2-\tModification de la note d'un etudiant";	gotoXY(1,7);	cout << "3-\tSuppression d'un etudiant";	gotoXY(1,8);	cout << "4-\tRetour au menu precedent";	gotoXY(1,9);	cout << "5-\tFin";	do {		gotoXY(1,10);	cout << "Entrez un numero: ...";		gotoXY(19,10);	cin >> res;	}	while (res < 1 || res > 5);	switch (res) {		case 1:			while (i == 0) {				i = ajouterEtudiant();			}			break;		case 2:			i = 0;			do {				if ((recherche = rechercherEtudiant()) != NULL) 					i = modifierNote(recherche);				else {					cout << endl << "Numero d'Etudiant inexistant" << endl << endl << endl;					cout << "Appuyez sur Enter pour continuer" << endl;					gets_s(buffer);					gets_s(buffer);				}			recherche = NULL;							}			while (i == -1);			break;		case 3:			i = 0;			do {				if ((recherche = rechercherEtudiant()) != NULL) 					i = supprimerEtudiant(recherche);				else {					cout << endl << "Numero d'Etudiant inexistant" << endl << endl << endl;					cout << "Appuyez sur Enter pour continuer" << endl;					gets_s(buffer);					gets_s(buffer);				}			recherche = NULL;							}			while (i == -1);			break;		case 4:			i = -3;			break;		case 5:			return 0;			}	if (i == -2) return -2;		else retournerMenu(1);	return -3;}int MenuRecherchesListes() {	Etudiant *recherche;	char buffer[20];	int res, i;	effacerEcran();	gotoXY(10,1);	cout << "*******************************";	gotoXY(10,2);	cout << "*\tRecherches et Listes    *";	gotoXY(10,3);	cout << "*******************************";	gotoXY(1,5);	cout << "1-\tAfficher un etudiant selon son numero";	gotoXY(1,6);	cout << "2-\tAfficher le meilleur etudiant";	gotoXY(1,7);	cout << "3-\tAfficher tous les etudiants par ordre de note";	gotoXY(1,8);	cout << "4-\tRetour au menu precedent";	gotoXY(1,9);	cout << "5-\tFin";	do {		gotoXY(1,10);	cout << "Entrez un numero: ...";		gotoXY(19,10);	cin >> res;	}	while (res < 1 || res > 5);	switch (res) {		case 1:			i = 0;			do {				if ((recherche = rechercherEtudiant()) != NULL) 					i = afficherEtudiant(recherche);				else {					cout << endl << "Numero d'Etudiant inexistant" << endl << endl << endl;					cout << "Appuyez sur Enter pour continuer" << endl;					gets_s(buffer);					gets_s(buffer);				}				recherche = NULL;							}			while (i == -1);			break;		case 2:			afficherMeilleurEtudiant();			return -2;		case 3:			//afficherParOrdre();			break;	}	return  i;}// FIN DE SECTION MENUSint ajouterEtudiant() {	char res;	int position;	int tempNumero, tempCMatiere;	float tempNMatiere;	char tempNom[20], tempTelephone[15], tempDMatiere[30];	effacerEcran();	gotoXY(10,1);	cout << "*******************************" << endl;	gotoXY(10,2);	cout << "*\tAjout d'un Etudiant\t*" << endl;	gotoXY(10,3);	cout << "*******************************" << endl;	gotoXY(2,5);	cout << "Numero: ....................................";	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(10,5);	cin >> tempNumero;	gotoXY(7,6);	cin >> tempNom;	gotoXY(13,7);	cin >> tempTelephone;	do {		gotoXY(16,8);	cin >> tempCMatiere; 	}	while (tempCMatiere < 1 || tempCMatiere > 6); 	if (tempCMatiere == 1) // Affiche le nom equivalent au numero de la matiere (description)		strncpy_s(tempDMatiere, "SQL", _TRUNCATE);	else if (tempCMatiere == 2)		strncpy_s(tempDMatiere, "PL-SQL", _TRUNCATE);	else if (tempCMatiere == 3)		strncpy_s(tempDMatiere, "JAVA", _TRUNCATE);	else if (tempCMatiere == 4)		strncpy_s(tempDMatiere, "VB.NET", _TRUNCATE);	else if (tempCMatiere == 5)		strncpy_s(tempDMatiere, "C++", _TRUNCATE);	else if (tempCMatiere == 6)		strncpy_s(tempDMatiere, "LINUX", _TRUNCATE);	gotoXY(23,10);	cout << tempDMatiere;	gotoXY(16,9);	cin >> tempNMatiere;	position = 12;	do { // Confirme l'enregistrement du nouvel etudiant		gotoXY(1, position);	cout << "Voulez vous enregistrer le nouvel etudiant? (O/N) ";		cin >> res;		position++;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') {	    ajouterEtudiant(dernier, tempNumero, tempNom, tempTelephone, tempCMatiere, tempNMatiere);		gotoXY(1, position); cout << "Donnees ajoutees avec Succes";		position++;	}	do {		gotoXY(1, position);		cout << "Voulez vous ajouter un autre Etudiant? (O/N) ";		cin >> res;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));		if (toupper(res) == 'O')			return 0;	do {			gotoXY(1, position); 			cout << "Avez vous d'autres mises-a-jours a faire? (O/N) ";			cin >> res;		}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O')			return -2;	return -3; }void ajouterEtudiant(Etudiant *vdernier, int vnumero, char vnom[20], char vtelephone[15], int vmatiere, float vnote) {	Etudiant *ptr;	ptr = new Etudiant;	ptr ->suiv = NULL;	ptr ->numero = vnumero;	strncpy_s(ptr ->nom, vnom, 20);	strncpy_s(ptr ->telephone, vtelephone, 20);	ptr ->matiere = vmatiere;	ptr ->note = vnote;	if (fflag == false) {		dernier ->suiv = ptr;		ptr ->prec = vdernier;	}	else	{		ptr ->prec = NULL;		fflag = false;	}	dernier = ptr;	if (premier == NULL) premier = dernier;}int modifierNote(Etudiant *ptr) {	float tempNMatiere;	// Variable temporaire pour ne pas ecraser la note initiale sans confirmation	int position;	char res;	effacerEcran();	gotoXY(10,1);	cout << "************************************************";	gotoXY(10,2);	cout << "*\tModification de la note d'un Etudiant\t   *";	gotoXY(10,3);	cout << "************************************************";	gotoXY(2,5);	cout << "Numero: ....................................";	gotoXY(10,5);	cout << ptr ->numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << ptr ->nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << ptr ->telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << ptr ->matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << ptr ->note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (ptr ->matiere == 1) // Affiche le nom equivalent au numero de la matiere (description)		cout << "SQL";	else if (ptr ->matiere == 2)		cout << "PL-SQL";	else if (ptr ->matiere == 3)		cout << "JAVA";	else if (ptr ->matiere == 4)		cout << "VB.NET";	else if (ptr ->matiere == 5)		cout << "C++";	else if (ptr ->matiere == 6)		cout << "LINUX";	gotoXY(16,9);	cin >> tempNMatiere;	position = 12;		do		{		gotoXY(1,position);	cout << "Etes vous sur de vouloir changer la note de " << 			ptr ->note << " a " << tempNMatiere << "? (O/N) ";		cin >> res;		position++;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') ptr ->note = tempNMatiere;	do { 		gotoXY(1,position); cout << "Voulez vous faire des modifications a d'autres notes? (O/N) ";		cin >> res;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') return -1;	return -2;	}int supprimerEtudiant(Etudiant *ptr) {	char res;	int position;	effacerEcran();	gotoXY(10,1);	cout << "**********************************";	gotoXY(10,2);	cout << "*\tSuppression d'un Etudiant\t   *";	gotoXY(10,3);	cout << "**********************************";	gotoXY(2,5);	cout << "Numero: ....................................";	gotoXY(10,5);	cout << ptr ->numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << ptr ->nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << ptr ->telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << ptr ->matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << ptr ->note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (ptr ->matiere == 1) // Affiche le nom equivalent au numero de la matiere (description)		cout << "SQL";	else if (ptr ->matiere == 2)		cout << "PL-SQL";	else if (ptr ->matiere == 3)		cout << "JAVA";	else if (ptr ->matiere == 4)		cout << "VB.NET";	else if (ptr ->matiere == 5)		cout << "C++";	else if (ptr ->matiere == 6)		cout << "LINUX";	position = 12;		do	// Confirme la modification	{		gotoXY(1,position);		cout << "Etes vous sur de vouloir supprimer l'Etudiant? (O/N) ";		cin >> res;		position++;		}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') {		ptr->prec->suiv = ptr->suiv;		ptr->suiv->prec = ptr->prec;		delete ptr;		memset(ptr,0xA3,sizeof(ptr));	}	do { 		gotoXY(1,position);		cout << "Voulez vous supprimer d'autres Etudiants? (O/N) ";		cin >> res;		position++;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') return -1; 	return -2;	}Etudiant *rechercherEtudiant() {	Etudiant *ptr;	ptr = premier;	int numrech;	effacerEcran();	gotoXY(10,1);	cout << "**********************************";	gotoXY(10,2);	cout << "*\tRecherche d'un Etudiant\t   *";	gotoXY(10,3);	cout << "**********************************";	do {		gotoXY(2,5);	cout << "Numero de l'Etudiant: ....................";		gotoXY(24,5);	cin >> numrech;	}	while (numrech <= 0);	gotoXY(1,7);	cout << "Recherche en cours...";	while (ptr ->suiv != NULL) {		if (ptr ->numero == numrech) return ptr;		ptr = ptr->suiv;	}	return NULL;}int afficherTous() {	int buffer;	Etudiant *ptr;	ptr = premier;		while (ptr != NULL) {		cout << ptr << endl;		cout << ptr ->nom << endl;		ptr = ptr ->suiv;		}		cin >> buffer;		return -2;}int afficherEtudiant(Etudiant *ptr) {	int position;	char res;	effacerEcran();	gotoXY(10,1);	cout << "**********************************";	gotoXY(10,2);	cout << "*\tAffichage d'un Etudiant\t   *";	gotoXY(10,3);	cout << "**********************************";	gotoXY(2,5);	cout << "Numero: ....................................";	gotoXY(10,5);	cout << ptr ->numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << ptr ->nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << ptr ->telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << ptr ->matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << ptr ->note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (ptr ->matiere == 1)		cout << "SQL";	else if (ptr ->matiere == 2)		cout << "PL-SQL";	else if (ptr ->matiere == 3)		cout << "JAVA";	else if (ptr ->matiere == 4)		cout << "VB.NET";	else if (ptr ->matiere == 5)		cout << "C++";	else if (ptr ->matiere == 6)		cout << "LINUX";	position = 12;		do	{		gotoXY(1,position);	cout << "Voulez vous faire une autre recherche? (O/N) ";		cin >> res;		position++;	}	while ((toupper(res) != 'O') && (toupper(res) != 'N'));	if (toupper(res) == 'O') return -1; 	return -2;}void afficherMeilleurEtudiant() {	char buffer[20];	Etudiant *pmax, *ptr;	pmax = premier;	ptr = pmax;	while (ptr != NULL) {		if (pmax ->note < ptr ->note) pmax = ptr;		ptr = ptr ->suiv;		}	effacerEcran();	gotoXY(10,1);	cout << "*****************************************";	gotoXY(10,2);	cout << "*\tAffichage du meilleur Etudiant\t  *";	gotoXY(10,3);	cout << "*****************************************";	gotoXY(2,5);	cout << "Numero: ....................................";	gotoXY(10,5);	cout << pmax ->numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << pmax ->nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << pmax ->telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << pmax ->matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << pmax ->note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (pmax ->matiere == 1)		cout << "SQL";	else if (pmax ->matiere == 2)		cout << "PL-SQL";	else if (pmax ->matiere == 3)		cout << "JAVA";	else if (pmax ->matiere == 4)		cout << "VB.NET";	else if (pmax ->matiere == 5)		cout << "C++";	else if (pmax ->matiere == 6)		cout << "LINUX";	gotoXY(1,12);	cout << "Appuyez sur enter pour continuer. ";	gets_s(buffer);	gets_s(buffer);	}void SauverFichier() {	Etudiant *ptr;	ptr = premier;	effacerEcran();	char res, buffer[20];	int i = 0;	gotoXY(10,1);	cout << "**********************************";	gotoXY(10,2);	cout << "*\tSauvegarde sur fichier\t   *";	gotoXY(10,3);	cout << "**********************************";	do {		gotoXY(1,5);	cout << "Etes-vous sur de vouloir sauvegarder sur fichier? ";		cin >> res;	}	while ((toupper(res) != 'O') && (toupper(res) !=  'N'));	if (toupper(res) == 'O') {		ofstream idFile("c:\\temp\\Etudiants.txt", ios::out);		if (idFile.fail()) {			gotoXY(10,6);	cout << "Erreur lors de l'ecriture";		}		else {			do {				idFile << ptr ->numero << endl;				idFile << ptr ->nom << endl;				idFile << ptr ->matiere << endl;				idFile << ptr ->note << endl;				ptr = ptr ->suiv;				i++;			}			while (ptr != NULL);		}		gotoXY(1,7);	cout << "Ecriture de " << i << " enregistrements effectues avec Succes!" << endl << endl;		idFile.close();		gotoXY(1,9);	cout << "Appuyez sur Enter pour continuer" << endl;		gets_s(buffer);		gets_s(buffer);	}}int main() {	// AJOUT D'ETUDIANTS FICTIFS COLISS        ajouterEtudiant(dernier, 1, "raulin", "514 552334", 3, 4.54);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 2, "olivier", "514 2565234", 1, 43.5);	cout << dernier -> prec << endl; 	ajouterEtudiant(dernier, 3, "jean", "514 5345346", 4, 66);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 4, "carlos", "234 234543", 5, 34);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 5, "alex", "543 43534534", 2, 88.23);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 6, "monica", "543 549 8345", 4, 87.12);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 7, "paola", "(514) 552-3334", 2, 92.65);	cout << dernier -> prec << endl;	ajouterEtudiant(dernier, 8, "katia", "(514) 323-4594", 1, 12.54);	cout << dernier -> prec << endl;	retournerMenu(1);		return 1;}