All pastes #943270 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2008-03-15 02:56 UTC
rendered paste body
#include <iostream>#include <fstream>#include "position.h"using namespace std;struct Etudiant {	int Numero;	char Nom[20];	char Telephone[15];	int Matiere;	float Note;} Etud[30];int curr = 0;int total = 30;int rechercherEtudiant();void afficherMeilleurEtudiant();int modifierNote(int index);int supprimerEtudiant(int index);int afficherEtudiant(int index);int ajouterEtudiant();void afficherParNote();void MenuMAJEtudiants();void MenuRecherchesListes();void MenuGestionEtudiants();// DEBUT DE LA SECTION DES MENUSvoid retournerMenu(int menu) {	switch (menu) {		case 1:			MenuGestionEtudiants();			break;		case 2:			MenuMAJEtudiants();			break;		case 3:			MenuRecherchesListes();			break;	}}void MenuGestionEtudiants() {	int res;	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:			MenuMAJEtudiants();			break;		case 2:			MenuRecherchesListes();			break;		case 3:			break;		case 4:			break;		case 5:			break;	}}void MenuMAJEtudiants() {	int res, i;	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:			do {			i = ajouterEtudiant();			}			while (i != -2);			retournerMenu(2);			break;		case 2:			do {				i = rechercherEtudiant();				if (i > -1)				{					i = modifierNote(i);				}			}			while (i != -2);			retournerMenu(2);			break;		case 3:			do {				i = rechercherEtudiant();				if (i > -1)				{					i = supprimerEtudiant(i);					cout << i;				}			}			while (i != -2);			retournerMenu(2);			break;		case 4:			retournerMenu(1);			break;		case 5:			break;	}}void MenuRecherchesListes() {	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:			do {				i = rechercherEtudiant();				if (i > -1)				{					i = afficherEtudiant(i);					cout << i;				}			}			while (i != -2);			retournerMenu(3);			break;		case 2:			afficherMeilleurEtudiant();			retournerMenu(3);			break;		case 3:			afficherParNote();			retournerMenu(3);			break;		case 4:			MenuGestionEtudiants();			break;		case 5:			break;	}}int modifierNote(int index);// FIN DE LA SECTION DES MENUS// DEBUT DU MENU MISES-A-JOURint modifierNote(int index) {	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 << Etud[index].Numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << Etud[index].Nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << Etud[index].Telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << Etud[index].Matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << Etud[index].Note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (Etud[index].Matiere == 1) // Affiche le nom equivalent au numero de la matiere (description)		cout << "SQL";	else if (Etud[index].Matiere == 2)		cout << "PL-SQL";	else if (Etud[index].Matiere == 3)		cout << "JAVA";	else if (Etud[index].Matiere == 4)		cout << "VB.NET";	else if (Etud[index].Matiere == 5)		cout << "C++";	else if (Etud[index].Matiere == 6)		cout << "LINUX";	gotoXY(16,9);	cin >> tempNMatiere;	position = 12;		do	// Confirme la modification	{		gotoXY(1,position);	cout << "Etes vous sur de vouloir changer la note de " << 			Etud[index].Note << " a " << tempNMatiere << "? (O/N) ";		cin >> res;		position++;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res != 'O' || res != 'o') Etud[index].Note = tempNMatiere;	do { // Demande si l'usager veut faire d'autre modifs		gotoXY(1,position); cout << "Voulez vous faire des modifications a d'autres notes? (O/N) ";		cin >> res;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'O' || res == 'o') return -1; // -1 si on veut faire d'autres modifs --> rechercherEtudiant()	return -2;	// -2 si on ne veut pas faire d'autres modifs --> MenuMAJEtudiants()}int ajouterEtudiant() {	char res;	int position;	int tempNumero, tempCMatiere;	float tempNMatiere;	char tempNom[20], tempTelephone[15], tempDMatiere[30];	// Variables temporaires pour ne pas ecrire sans confirmation	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 ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));			if (res == 'O' || res == 'o') {		Etud[curr].Numero = tempNumero;		strncpy_s(Etud[curr].Nom, tempNom, _TRUNCATE);		strncpy_s(Etud[curr].Telephone, tempTelephone, _TRUNCATE);		Etud[curr].Matiere = tempCMatiere;		Etud[curr].Note = tempNMatiere;		gotoXY(1, position); cout << "Donnees ajoutees avec Succes";		position++;		curr++; // Variable *importante* qui retourne l'index courant		total++; // Variable *importante* qui retourne le total d'etudiants	}	do {	gotoXY(1, position); 	cout << "Avez vous d'autres mises-a-jours a faire? (O/N) ";	cin >> res;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'O' || res == 'o') {		return -1; // --> Recommencer	}	return -2; // --> MenuMAJEtudiants()	}int supprimerEtudiant(int index) {	int position;	char res;	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 << Etud[index].Numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << Etud[index].Nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << Etud[index].Telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << Etud[index].Matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << Etud[index].Note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (Etud[index].Matiere == 1) // Affiche le nom equivalent au numero de la matiere (description)		cout << "SQL";	else if (Etud[index].Matiere == 2)		cout << "PL-SQL";	else if (Etud[index].Matiere == 3)		cout << "JAVA";	else if (Etud[index].Matiere == 4)		cout << "VB.NET";	else if (Etud[index].Matiere == 5)		cout << "C++";	else if (Etud[index].Matiere == 6)		cout << "LINUX";	position = 12;		do // Confirme la suppression de l'etudiant	{		gotoXY(1,position);	cout << "Etes vous sur de vouloir supprimer cet etudiant? (O/N) ";		cin >> res;		position++;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res != 'O' || res != 'o') {		for (;index < total;index++) // Suppresion et redistribution des index		{			Etud[index].Numero = Etud[index+1].Numero;			Etud[index].Matiere = Etud[index+1].Matiere;			Etud[index].Note = Etud[index+1].Note;			strcpy_s(Etud[index].Nom, Etud[index+1].Nom);			strcpy_s(Etud[index].Telephone, Etud[index+1].Telephone);		}		total--; // Variable *importante* qui indique le nombre total d'etudiant		curr--; // Variable *importante* utile pour ajouter un etudiant, indique l'etudiant courant	}	do // Demande si on veut faire une autre suppresion	{		gotoXY(1,position);	cout << "Voulez-vous supprimer un autre etudiant? (O/N) ";		cin >> res;		position++;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'O' || res == 'o') return -1; // Recommencer --> rechercherEtudiant()	return -2;	// Sortir au menu precedent --> MenuMAJEtudiants()}void ajouterEFictif() {	Etud[0].Numero = 2523;	strncpy_s(Etud[0].Nom, "Cynthio", _TRUNCATE);	strncpy_s(Etud[0].Telephone, "348 348 3423", _TRUNCATE);	Etud[0].Note = 35;	Etud[0].Matiere = 3;	Etud[1].Numero = 23;	strncpy_s(Etud[1].Nom, "Olivier", _TRUNCATE);	strncpy_s(Etud[1].Telephone, "5145033433", _TRUNCATE);	Etud[1].Note = 35;	Etud[1].Matiere = 3;	Etud[2].Numero = 26;	strncpy_s(Etud[2].Nom, "Raulin", _TRUNCATE);	strncpy_s(Etud[2].Telephone, "52343433", _TRUNCATE);	Etud[2].Note = 12;	Etud[2].Matiere = 1;	Etud[3].Numero = 53;	strncpy_s(Etud[3].Nom, "Connard", _TRUNCATE);	strncpy_s(Etud[3].Telephone, "(543) 212-2333", _TRUNCATE);	Etud[3].Note = 54;	Etud[3].Matiere = 2;		Etud[4].Numero = 78;	strncpy_s(Etud[4].Nom, "Pendejo", _TRUNCATE);	strncpy_s(Etud[4].Telephone, "543-256-4453", _TRUNCATE);	Etud[4].Note = 98;	Etud[4].Matiere = 4;		total = 5;	curr = 5;}// FIN DE LA SECTION MISES-A-JOUR// DEBUT DE LA SECTION DES RECHERCHES ET LISTESint rechercherEtudiant() {	int i, rech;	char res;	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 >> rech;	}	while (rech <= 0);	gotoXY(1,7);	cout << "Recherche en cours...";	for (i = 0;i <= total; i++) {		if (Etud[i].Numero == rech)			return i;	}	gotoXY(1,8);	cout << "Aucun etudiant n'a ete trouve avec ce numero.";	do  	{		gotoXY(1,9);	cout << "Voulez vous essayez a nouveau? (O/N) ";		cin >> res;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'O' || res == 'o') {		return -1; // Reessayer --> rechercherEtudiant()	}	return -2; // Ne pas reessayer}int afficherEtudiant(int index) {	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 << Etud[index].Numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << Etud[index].Nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << Etud[index].Telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << Etud[index].Matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << Etud[index].Note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (Etud[index].Matiere == 1)		cout << "SQL";	else if (Etud[index].Matiere == 2)		cout << "PL-SQL";	else if (Etud[index].Matiere == 3)		cout << "JAVA";	else if (Etud[index].Matiere == 4)		cout << "VB.NET";	else if (Etud[index].Matiere == 5)		cout << "C++";	else if (Etud[index].Matiere == 6)		cout << "LINUX";	position = 12;		do	{		gotoXY(1,position);	cout << "Voulez vous faire une autre recherche? (O/N) ";		cin >> res;		position++;	}	while ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'O' || res == 'o') return -1; // Recommencer --> rechercherEtudiant()	return -2; // --> MenuRecherchesListes();}void afficherMeilleurEtudiant() {	char buffer;	int i, max = 0, indmax;	for (i = 0; i <= total; i++) {		if (Etud[i].Note > max) 			indmax = i;	}	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 << Etud[indmax].Numero;	gotoXY(2,6);	cout << "Nom: .......................................";	gotoXY(7,6);	cout << Etud[indmax].Nom;	gotoXY(2,7);	cout << "Telephone: .................................";	gotoXY(13,7);	cout << Etud[indmax].Telephone;	gotoXY(2,8);	cout << "Code Matiere: ..............................";	gotoXY(16,8);	cout << Etud[indmax].Matiere;	gotoXY(2,9);	cout << "Note Matiere: ..............................";	gotoXY(16,9);	cout << Etud[indmax].Note;	gotoXY(2,10);	cout << "Description Matiere: .......................";	gotoXY(23,10);		if (Etud[indmax].Matiere == 1)		cout << "SQL";	else if (Etud[indmax].Matiere == 2)		cout << "PL-SQL";	else if (Etud[indmax].Matiere == 3)		cout << "JAVA";	else if (Etud[indmax].Matiere == 4)		cout << "VB.NET";	else if (Etud[indmax].Matiere == 5)		cout << "C++";	else if (Etud[indmax].Matiere == 6)		cout << "LINUX";	gotoXY(1,12);	cout << "Appuyez sur n'importe quelle touche pour retourner au menu precedent. ";	cin >> buffer;	}void afficherParNote() {	effacerEcran();	Etudiant permute;	char buffer;	int i, j, dim, position;	dim = total;	for (i = 0; i < dim - 1; i++) {		for (j = i + 1; j < dim; j++) {			if (Etud[i].Note < Etud[j].Note) {				permute = Etud[i];				Etud[i] = Etud[j];				Etud[j] = permute;			}		}	}	gotoXY(10,1);	cout << "***************************************";	gotoXY(10,2);	cout << "*\tAffichage des Etudiants par\t*";	gotoXY(10,3);	cout << "*\tordre decroissant\t\t*";	gotoXY(10,4);	cout << "***************************************" << endl;	position = 7;	for (i = 0; i < dim; i++) {		gotoXY(1, position);	cout << "Etudiant: ........................";		gotoXY(11, position);	cout << Etud[i].Nom;		position++;		gotoXY(1, position);	cout << "Note: ............................";		gotoXY(7, position);	cout << Etud[i].Note << endl << endl << endl;		position += 2;		}	gotoXY(1,position);	cout << "Appuyez sur n'importe quelle touche pour retourner au menu precedent. ";	cin >> buffer;}// FIN DE LA SECTION DES RECHERCHES ET LISTESint SauverFichier() {	char res;	int i;		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 ((res != 'O' && res != 'o') && (res != 'N' && res != 'n'));	if (res == 'N' || res == 'n') return -2; // Sortir	ofstream idFile("c:\\temp\\Etudiants.txt", ios::out);	if (idFile.fail()) {		gotoXY(10,6);	cout << "Erreur lors de l'ecriture";	}	else {		for (i = 0; i < total; i++) {			idFile << Etud[i].Numero << endl;			idFile << Etud[i].Nom << endl;			idFile << Etud[i].Matiere << endl;			idFile << Etud[i].Note << endl;		}		gotoXY(1,7);	cout << "Ecriture de " << i << " enregistrements effectues avec Succes!" << endl << endl;		idFile.close();		return -1;	}}void main() {	ajouterEFictif();	//MenuGestionEtudiants();	SauverFichier();}