begin process at 2008 07 05 13:34:36
1 205 182 membres
158 nouveaux aujourd'hui
14 119 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

BLACKJACK SIMPLE AVEC DEV-CPP


Information sur la source

Catégorie :Application Classé sous : blackjack, blackjack Niveau : Débutant Date de création : 08/02/2007 Vu / téléchargé: 2 065 / 153

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

Description

Et oui, encore un BlackJack avec Dev-cpp en  interface DOS.

Source

  • #include <iostream>
  • #include <cstdlib>
  • #include <algorithm>
  • #include <ctime>
  • #include <cctype>
  • typedef enum { Trefles = 0, Carreaux, Coeur, Pike } Suit;
  • typedef enum { Continue, Win, Bust } State;
  • typedef struct {
  • Suit suit;
  • char value;
  • } Card;
  • class Deck {
  • public:
  • Deck() {
  • cards = new Card[52];
  • CreateDeck();
  • }
  • ~Deck() {
  • delete[] cards;
  • }
  • void CreateDeck() {
  • for(int x = 0; x < 4; ++x) {
  • for(int i = 1; i <= 13; ++i) {
  • cards[i + (x * 13) - 1].suit = static_cast<Suit>(x);
  • cards[i + (x * 13) - 1].value = i;
  • }
  • }
  • deck = 52;
  • MelangeDeck();
  • }
  • void MelangeDeck() {
  • for(int x = 0; x < 4; ++x) {
  • for(int i = 1; i <= 13; ++i) {
  • std::swap(cards[i + (x * 13) - 1], cards[rand() % 52]);
  • }
  • }
  • int melange = 3;
  • do {
  • for(int x = 0; x < 2; ++x) {
  • for(int i = 1; i < 13; ++i) {
  • std::swap(cards[i + (x * 13) - 1], cards[(i+2) + (x * 13)]);
  • }
  • }
  • } while(--melange);
  • }
  • Card DrawCard() {
  • if(deck <= 0) {
  • Card c = { static_cast<Suit>(-1), 0 };
  • return c;
  • }
  • return cards[--deck];
  • }
  • void ShowCard(int i) {
  • ShowCard(cards[i]);
  • }
  • void ShowCard(Card card) {
  • Suit suit = card.suit;
  • int value = card.value;
  • switch(value) {
  • case 1: std::cout << "As de "; break;
  • case 11: std::cout << "Chevalier de "; break;
  • case 12: std::cout << "Renne de "; break;
  • case 13: std::cout << "Roi de "; break;
  • default: std::cout << value << " de ";
  • }
  • switch(suit) {
  • case Trefles: std::cout << "Trefles"; break;
  • case Carreaux: std::cout << "Carreaux"; break;
  • case Coeur: std::cout << "Coeur"; break;
  • case Pike: std::cout << "Pike"; break;
  • }
  • std::cout << std::endl;
  • }
  • private:
  • Card *cards;
  • int deck;
  • };
  • class BlackJack : public Deck {
  • public:
  • BlackJack() {
  • croupier.score = croupier.index = 0;
  • croupier.cards = new Card[12];
  • joueur.score = joueur.index = 0;
  • joueur.cards = new Card[12];
  • }
  • ~BlackJack() {
  • delete[] croupier.cards;
  • delete[] joueur.cards;
  • }
  • State give_joueur_card(void) {
  • Card card = this->DrawCard();
  • if(!card.value)
  • return Bust;
  • joueur.cards[joueur.index++] = card;
  • joueur.score = count_cards(joueur.cards, joueur.index);
  • if(joueur.score > 21)
  • return Bust;
  • else if(joueur.score == 21)
  • return Win;
  • return Continue;
  • }
  • State give_croupier_card(void) {
  • Card card = this->DrawCard();
  • if(!card.value)
  • return Bust;
  • croupier.cards[croupier.index++] = card;
  • croupier.score = count_cards(croupier.cards, croupier.index);
  • if(croupier.score > 21)
  • return Bust;
  • else if(joueur.score == 21)
  • return Win;
  • return Continue;
  • }
  • void show_joueur_cards(void) {
  • std::cout << " Cartes du joueur" << std::endl;
  • ShowCards(joueur.cards, joueur.index);
  • std::cout << std::endl;
  • }
  • void show_croupier_cards(bool show_all) {
  • std::cout << " Cartes du Croupier" << std::endl;
  • if(show_all) {
  • ShowCards(croupier.cards, croupier.index);
  • std::cout << "Score: " << croupier.score;
  • } else
  • ShowCards(croupier.cards+1, croupier.index-1);
  • std::cout << std::endl;
  • }
  • int get_joueur_score(void) { return joueur.score; }
  • int get_croupier_score(void) { return croupier.score; }
  • void ShowCards(Card *cards, int size) {
  • for(int i = 0; i < size; ++i)
  • ShowCard(cards[i]);
  • }
  • private:
  • struct {
  • int score, index;
  • Card *cards;
  • } croupier, joueur;
  • int count_cards(Card *cards, int size) {
  • int total = 0;
  • bool CAs = false;
  • for(int i = 0; i < size; ++i) {
  • if(CAs && size > 2) {
  • total -= 10;
  • CAs = false;
  • }
  • if(cards[i].value == 1) {
  • if((total + 11) < 21) {
  • total += 10;
  • CAs = true;
  • }
  • ++total;
  • } else if(cards[i].value >= 10)
  • total += 10;
  • else
  • total += cards[i].value;
  • }
  • return total;
  • }
  • };
  • int main(void)
  • {
  • srand(time(0));
  • BlackJack *jack = new BlackJack();
  • bool busted = false, joueur_hit = true;
  • State croup, joueur;
  • std::string message = "";
  • jack->give_croupier_card();
  • jack->give_joueur_card();
  • do {
  • int cscore = jack->get_croupier_score();
  • if(cscore < 15) croup = jack->give_croupier_card();
  • if(joueur_hit) joueur = jack->give_joueur_card();
  • int jscore = jack->get_joueur_score();
  • char b = 0;
  • if(jscore <= 21 && cscore <= 21) {
  • do {
  • jack->show_croupier_cards(false);
  • jack->show_joueur_cards();
  • std::cout << "Que voulez vous faire? " << jscore << ") [P=Prendre/L=Laisser] ";
  • std::cin >> b; b = std::toupper(b);
  • } while(b != 'P' && b != 'L');
  • }
  • joueur_hit = (b == 'P');
  • if(!joueur_hit) {
  • while(cscore < 15) {
  • croup = jack->give_croupier_card();
  • cscore = jack->get_croupier_score();
  • }
  • if(jscore > cscore || joueur == Win || croup == Bust)
  • message = "Gagnant!!!";
  • else if(cscore > jscore || croup == Win || joueur == Bust)
  • message = "Perdu";
  • else if(cscore == jscore)
  • message = "Dommage";
  • break;
  • }
  • busted = (joueur == Bust || croup == Bust);
  • } while(!busted);
  • std::cout << "+---- " << message << " ----+" << std::endl << std::endl;
  • jack->show_croupier_cards(true);
  • std::cout << std::endl;
  • jack->show_joueur_cards();
  • std::cout << "Score: " << jack->get_joueur_score() << std::endl;
  • system("pause");
  • return 0;
  • }
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>

typedef enum { Trefles = 0, Carreaux, Coeur, Pike } Suit;
typedef enum { Continue, Win, Bust } State;
typedef struct  {
	Suit suit;
	char value;
} Card;


class Deck {
public:
	Deck() {
		cards = new Card[52];
		CreateDeck();
	}

	~Deck() {
		delete[] cards;
	}

	void CreateDeck() {
		for(int x = 0; x < 4; ++x) {
			for(int i = 1; i <= 13; ++i) {
				cards[i + (x * 13) - 1].suit = static_cast<Suit>(x);
				cards[i + (x * 13) - 1].value = i;
			}
		}
		deck = 52;
		MelangeDeck();
	}
			
	void MelangeDeck() {
		for(int x = 0; x < 4; ++x) {
			for(int i = 1; i <= 13; ++i) {
				std::swap(cards[i + (x * 13) - 1], cards[rand() % 52]);
			}
		}

		int melange = 3;
		do { 
			for(int x = 0; x < 2; ++x) { 
				for(int i = 1; i < 13; ++i) { 
					std::swap(cards[i + (x * 13) - 1], cards[(i+2) + (x * 13)]);
				}
			}
		} while(--melange);
	}

	Card DrawCard() {
		if(deck <= 0) {
			Card c = { static_cast<Suit>(-1), 0 };
			return c;
		}
		return cards[--deck];
	}

	void ShowCard(int i) {
		ShowCard(cards[i]);
	}

	void ShowCard(Card card) {
		Suit suit = card.suit;
		int value = card.value;

		switch(value) {
			case 1: std::cout << "As de "; break;
			case 11: std::cout << "Chevalier de "; break;
			case 12: std::cout << "Renne de "; break;
			case 13: std::cout << "Roi de "; break;
			default: std::cout << value << " de ";
		}

		switch(suit) {
			case Trefles: std::cout << "Trefles"; break;
			case Carreaux: std::cout << "Carreaux"; break;
			case Coeur: std::cout << "Coeur"; break;
			case Pike: std::cout << "Pike"; break;
		}
		std::cout << std::endl;
	}

private:
	Card *cards;
	int deck;
};

class BlackJack : public Deck {
public:
	BlackJack() {
		croupier.score = croupier.index = 0;
		croupier.cards = new Card[12];

		joueur.score = joueur.index = 0;
		joueur.cards = new Card[12];
	}

	~BlackJack() {
		delete[] croupier.cards;
		delete[] joueur.cards;
	}

	State give_joueur_card(void) {
		Card card = this->DrawCard();
		if(!card.value)
			return Bust;

		joueur.cards[joueur.index++] = card;
		joueur.score = count_cards(joueur.cards, joueur.index);

		if(joueur.score > 21)
			return Bust;
		else if(joueur.score == 21)
			return Win;

		return Continue;
	}

	State give_croupier_card(void) {
		Card card = this->DrawCard();
		if(!card.value)
			return Bust;

		croupier.cards[croupier.index++] = card;
		croupier.score = count_cards(croupier.cards, croupier.index);

		if(croupier.score > 21)
			return Bust;
		else if(joueur.score == 21)
			return Win;

		return Continue;
	}

	void show_joueur_cards(void) {
		std::cout << "         Cartes du joueur" << std::endl;
		ShowCards(joueur.cards, joueur.index);
		std::cout << std::endl;
	}

	void show_croupier_cards(bool show_all) {
		std::cout << "         Cartes du Croupier" << std::endl;
		if(show_all) {
			ShowCards(croupier.cards, croupier.index);
			std::cout << "Score: " << croupier.score;
		} else
			ShowCards(croupier.cards+1, croupier.index-1);

		std::cout << std::endl;
	}

	int get_joueur_score(void) { return joueur.score; }
	int get_croupier_score(void) { return croupier.score; }

	void ShowCards(Card *cards, int size) {
		for(int i = 0; i < size; ++i)
			ShowCard(cards[i]);
	}

private:
	struct {
		int score, index;
		Card *cards;
	} croupier, joueur;

	int count_cards(Card *cards, int size) {
		int total = 0;
		bool CAs = false;

		for(int i = 0; i < size; ++i) {
			if(CAs && size > 2) {
				total -= 10;
				CAs = false;
			}

			if(cards[i].value == 1) {
				if((total + 11) < 21) {
					total += 10;
					CAs = true;
				}
				++total;
			} else if(cards[i].value >= 10)
				total += 10;
			else
				total += cards[i].value;
		}
		return total;
	}
};


int main(void)
{
	srand(time(0));
	BlackJack *jack = new BlackJack();
	bool busted = false, joueur_hit = true;
	State croup, joueur;
	std::string message = "";

	jack->give_croupier_card();
	jack->give_joueur_card();

	do { 
		int cscore = jack->get_croupier_score();
		if(cscore < 15) croup = jack->give_croupier_card();

		if(joueur_hit) joueur = jack->give_joueur_card();
		int jscore = jack->get_joueur_score();

		char b = 0;
		if(jscore <= 21 && cscore <= 21) {
			do {
				jack->show_croupier_cards(false);
				jack->show_joueur_cards();

				std::cout << "Que voulez vous faire?  " << jscore << ") [P=Prendre/L=Laisser] ";
				std::cin >> b; b = std::toupper(b);
			} while(b != 'P' && b != 'L');
		}
		joueur_hit = (b == 'P');

		if(!joueur_hit) {
			while(cscore < 15) {
				croup = jack->give_croupier_card();
				cscore = jack->get_croupier_score();
			}

			if(jscore > cscore || joueur == Win || croup == Bust)
				message = "Gagnant!!!";
			else if(cscore > jscore || croup == Win || joueur == Bust)
				message = "Perdu";
			else if(cscore == jscore)
				message = "Dommage";

			break;
		}
		busted = (joueur == Bust || croup == Bust);
	} while(!busted);

	std::cout << "+---- " << message << " ----+" << std::endl << std::endl;

	jack->show_croupier_cards(true);
	std::cout << std::endl;

	jack->show_joueur_cards();
	std::cout << "Score: " << jack->get_joueur_score() << std::endl;
              system("pause");
	return 0;
	
}
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Sources en rapport avec celle ci

  • signaler à un administrateur
    Commentaire de Renfield le 08/02/2007 12:58:02 administrateur CS

    Merci de cesser ce bla bla inutile, SMS qui plus est...

    utilisez MSN ou tout autre moyen a votre convenance, ne polluez pas inutilement CodeS-SourceS

    Merci.
    Renfield - Admin CS

  • signaler à un administrateur
    Commentaire de BruNews le 08/02/2007 13:10:55 administrateur CS

    C'est nettoyé.

  • signaler à un administrateur
    Commentaire de saoudi86 le 16/02/2007 12:54:08

    salut a tous les ames de cppfrance
    je suis saoudi abderrazzak de maroc je veux propose mon projet de la fine de l'anneé dernier en cpp
    merci..

  • signaler à un administrateur
    Commentaire de saoudi86 le 16/02/2007 12:58:12

    saoudi abderrazzak
    voila mon projet:
    *************************************************************
    #include<stdio.h>
    #include<conio.h>
    #include<ctype.h>
    #include<stdlib.h>
    #include<string.h>
    #include<stdio.h>
    #include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #include <dos.h>
    #define angle M_PI/180

    /*
    ** Fonction permettant l'initialisation graphique
    */

    void Initialisation_graphique(void){
      int GDriver = DETECT,GMode,ErrorCode;
      initgraph( &GDriver, &GMode, " " );
      ErrorCode = graphresult();
      if( ErrorCode != grOk )
       {
    printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
    getch();
    exit( 1 );
       }
    }
    /*
    ** Fonction pour dessiner par pixel dans une forme rectangulaire
    */
    void dessine(int x1,int y1,int x2, int y2,int coul){
    int i,j;
    for(i=x1;i<=x2;i++)
    for(j=y1;j<=y2;j++)
        putpixel(i,j,coul);
    }
    /*
    ** Cette fonction revoie le mois en charact‚re
    ** Corresspodant … l'entier en param‚tre.
    */

    char * det_mois(int val){
         if(val==1) return("Janvier");
         if(val==2) return("F‚vrier");
         if(val==3) return("Mars");
         if(val==4) return("Aril");
         if(val==5) return("Mai");
         if(val==6) return("Juin");
         if(val==7) return("Juillet");
         if(val==8) return("Ao–t");
         if(val==9) return("Septembre");
         if(val==10) return("Octobre");
         if(val==11) return("Novembre");
         if(val==12) return("D‚cembre");

    return(" ");
    }

    /*
    ** Comme son nom l'indique cette fonction
    ** permet d'afficher la date du jour.
    */
    void affiche_date_du_jour(date la_date,char* num){

          getdate(&la_date);

          gcvt(la_date.da_day,3,num);
          settextstyle(2,0,4);
          setcolor(15);
          outtextxy(240,47,num);
          outtextxy(260,47,det_mois(la_date.da_mon));

          gcvt(la_date.da_year,5,num);
          settextstyle(2,0,4);
          setcolor(15);
          outtextxy(320,47,num);

    }

    /*
    ** C'est par cette fonction que les nombreux rectangles
    ** du programme sont construits
    */

    void decoration(void){
          bar3d(getmaxx()-40,20,getmaxx()-20,450,0,0);
          rectangle(getmaxx()-35,25,getmaxx()-25,445);
          rectangle(getmaxx()-35+2,25+2,getmaxx()-25-2,445-2);
          bar3d(20,20,40,450,0,0);
          rectangle(25,25,35,445);
          rectangle(27,27,33,443);
          bar3d(60,417,getmaxx()-60,440,0,0);
          rectangle(65,422,getmaxx()-65,435);
          rectangle(70,427,getmaxx()-70,430);

          setfillstyle(8,9);
          bar3d(95,30,550,150,4,4);

          setfillstyle(1,9);
          bar3d(getmaxx()-60,30,getmaxx()-80,150,0,0);
          rectangle(getmaxx()-62,32,getmaxx()-78,148);
    }

    /*
    ** C'est par cette foction avec l'itulisation
    ** de la pr‚c‚dente que le plateau du programme
    ** prend forme.
    */

    void dessine_plateau(void){
          setfillstyle(7,4);
          bar3d(10,10,getmaxx()-10,getmaxy()-10,0,0);

          setfillstyle(11,9);
          bar3d(50,20,getmaxx()-50,160,0,0);
          rectangle(55,25,getmaxx()-55,155);
          bar3d(50,170,getmaxx()-50,450,0,0);
          rectangle(55,175,getmaxx()-55,445);

          decoration();

          bar3d(230,70,515,100,0,0);
          rectangle(232,72,513,98);
          setcolor(0);
          rectangle(234,75,511,96);
          setcolor(15);

          setfillstyle(1,9);
          bar3d(230,37,515,65,1,1);
          rectangle(232,39,513,63);
          setcolor(0);
          rectangle(234,42,511,61);
          setcolor(15);

          bar3d(230,105,515,130,0,0);
          rectangle(232,107,513,128);
          setcolor(15);

          settextstyle(4,0,1);
          outtextxy(105,70,"Il est       :");
          outtextxy(100,40,"Date du Jour :");
          outtextxy(238,138," gestion d'affectation des stages");

          outtextxy(getmaxx()-76,40,"E");
          outtextxy(getmaxx()-76,60,"X");
          outtextxy(getmaxx()-76,80,"I");
          outtextxy(getmaxx()-76,100,"T");

    }

    /*
    ** L… la montre prend forme graphiquement
    ** avec le cadre et le cercle
    */
    void forme_montre(void){

          setfillstyle(1,9);
          bar3d(230,200,415,410,0,0);
          bar3d(160,200,215,410,0,0);
          bar3d(430,200,485,410,0,0);
          rectangle(235,205,410,405);
          bar3d(95,200,150,410,0,0);
          bar3d(495,200,550,410,0,0);
          setcolor(15);
          rectangle(95,200,150,410);
          rectangle(96,201,149,409);
          rectangle(495,200,550,410);
          rectangle(496,201,549,409);
          rectangle(160,200,215,410);
          rectangle(161,201,214,409);
          rectangle(430,200,485,410);
          rectangle(431,201,484,409);
          setcolor(0);
          rectangle(236,207,409,404);
          setcolor(15);
          circle(320,300,70);
          settextstyle(2,0,4);
          outtextxy(320,372,"6");
          outtextxy(315,215,"12");
          outtextxy(280,360,"7");
          outtextxy(355,225,"1");
          outtextxy(385,250,"2");
          outtextxy(250,330,"8");
          outtextxy(240,293,"9");
          outtextxy(245,255,"10");
          outtextxy(273,225,"11");
          outtextxy(397,293,"3");
          outtextxy(390,325,"4");
          outtextxy(360,360,"5");
          for(int m=1;m<=12;m++){
    setcolor(0);
    int tirx=320+70*sin(m*30*angle);
    int tiry=292-70*cos(m*30*angle);
    outtextxy(tirx,tiry,".");
    }
          setcolor(15);

    }

    /*
    ** Toutes les fonctions pr‚c‚dentes
    ** sont appel‚es ici.
    */
    void erogonomie_centrale(void){
          int i;
          char*num=(char*)malloc(10*sizeof(char));
          struct date la_date;

          dessine_plateau();
          forme_montre();
          settextstyle(5,1,1);
          setcolor(1);
          outtextxy(130,210,"SAOUDI ABDERRAZZAK ");
          outtextxy(520,250,"MARZOUKI JAWAD");
          settextstyle(4,0,1);
          setcolor(10);
          outtextxy(166,220,"  *");
          outtextxy(435,220,"  *");

          for(i=10;i<170;i+=20){
    outtextxy(168,230+i,"* * *");
    outtextxy(170,220+i," . .");
    outtextxy(437,230+i,"* * *");
    outtextxy(439,220+i," . .");
          }

          //Affichage de la date du jour
          affiche_date_du_jour(la_date,num);
          setlinestyle(0,0,3);
    }

    void montre(void){
    int minutes,sec,heu,xminutes,
        yminutes,xheu,yheu,xsec,
        ysec,attendre,traitx,traity,
        varchar,ok,nbout,xs,ys,bg,bd;
    char*num=(char*)malloc(10*sizeof(char));
    char chaine[3];
    struct  time Heure_actuelle;
    xminutes=320+40*sin(minutes*6*angle);
    yminutes=300-40*cos(minutes*6*angle);
    xheu=320+30*sin(minutes*0.5*angle+(heu*30*angle));
    yheu=300-30*cos(minutes*0.5*angle+(heu*30*angle));
    erogonomie_centrale();
    do{
    gettime(&Heure_actuelle);
    sec=Heure_actuelle.ti_sec;
    minutes=Heure_actuelle.ti_min;
    heu=Heure_actuelle.ti_hour;
    attendre=sec;
    setcolor(15);
    settextstyle(4,0,1);
    outtextxy(305,286,"751");

    dessine(238,76,250,87,9);
    gcvt(heu,3,num);
    settextstyle(2,0,4);
    setcolor(15);
    outtextxy(240,77,num);
    outtextxy(260,77,"heure(s)");

    dessine(308,76,320,87,9);
    gcvt(minutes,3,num);
    settextstyle(2,0,4);
    setcolor(15);
    outtextxy(310,77,num);
    outtextxy(330,77,"minute(s)");

    dessine(393,76,405,87,9);
    gcvt(sec,3,num);
    settextstyle(2,0,4);
    setcolor(15);
    outtextxy(395,77,num);
    outtextxy(415,77,"seconde(s)");

    //Affichage aiguille des heures
    setcolor(9);
    line(320,300,xheu,yheu);
    xheu=320+30*sin(minutes*0.5*angle+(heu*30*angle));
    yheu=300-30*cos(minutes*0.5*angle+(heu*30*angle));
    setcolor(4);
    line(320,300,xheu,yheu);

    //Affichage aiguille des minutes
    setcolor(9);
    line(320,300,xminutes,yminutes);
    xminutes=320+40*sin(minutes*6*angle);
    yminutes=300-40*cos(minutes*6*angle);
    setcolor(2);
    line(320,300,xminutes,yminutes);

    //Affichage aiguille des secondes
    xsec=320+60*sin((sec)*6*angle);
    ysec=300-60*cos((sec)*6*angle);
    setcolor(14);
    line(320,300,xsec,ysec);

    while(1){
    gettime(&Heure_actuelle);
    sec=Heure_actuelle.ti_sec;
    if(attendre!=sec) break;
    }
    setcolor(9);
    line(320,300,xsec,ysec);
    settextstyle(2,0,4);
    } while(!kbhit());
    }


    void m(void){

    Initialisation_graphique();

    montre();

    closegraph();
    }

    /***********************structure soci‚t‚*************************/
      int    bool;
    struct societe
    {
    char adresses[40];
    char Email[20];
    char tele[20];
    char fax[40];
    char patente[20];
    char categorie[20];
    char    sigle[20];

    };
    societe so;
    FILE *a,*b,*f2;
    char sigle[20];char adresse[20];char   Email[20];char  tel[20];
    char fax[40];char patente[20];char categorie[20];char choix  ;
    char rep;
    char siglem[20];
    char adressesm[20];
    char Emailm[20];
    char telem[20];
    char faxm[40];
    char patentem[20];
    char categoriem[20];

      /***********************structure stagiaire*************************/

    struct     stagiaire
    {
    char        Prenom [20];
    char            nomst[20];
    char    ninscription[20];
    char            adresse[20];
    char           filiere[20];
    char          daten[20];
    } st;
    FILE           *f,*s,*f1;

    char        Prenom [20];
    char            nomst[20];
    char    ninscription[20];

    char           filiere[20];
    char          daten[20];


    char        Prenomm [20];
    char            nomstm[20];
    char    ninscriptionm[20];
    char            adressem[20];
    char           filierem[20];
    char          datenm[20];
    /***********************structure affectation***********************/
        struct affectation
        {
        char numaf[20];
        char dateaf[10];
        char        Prenom [20];
        char            nomst[20];
        char    ninscription[20];
        char categorie[20];
        char    sigle[20];
        }aff;
         char numaf[20];
        char dateaf[10];
        char numafm[20];
        char dateafm[10];

    /**************************fonction menu1********************************/
    void         menu()
    {
    textbackground(1);
    clrscr();
    gotoxy(4,5) ;printf("  ÉÍÍÍÍ»                                                            ÉÍÍÍÍ»");
    gotoxy(4 ,6);printf(" ɼ   ɼ                                                            È»   È»");
    gotoxy(4 ,7);printf("ɼ    º                    GESTION DES STAGIAIRES                    º    È»");
    gotoxy(4 ,8);printf("º     È»                                                            É¼     º");
    gotoxy(4 ,9);printf("º      ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ      º");
    gotoxy(4,10);printf("º                                                                          º");
    gotoxy(4,11);printf("º                                                                          º");
    gotoxy(4,12);printf("º                                                                          º");
    gotoxy(4,13);printf("º     ÉÍÍÍÍÍÍÍÍÍÍÍ»         ÉÍÍÍÍÍÍÍÍÍÍÍ»         ÉÍÍÍÍÍÍÍÍÍÍÍ»            º");
    gotoxy(4,14);printf("º    É¼           È»       ɼ           È»       ɼ           È»           º");
    gotoxy(4,15);printf("º   ɼ             È»     ɼ             È»     ɼ             È»          º");
    gotoxy(4,16);printf("º   º [A]® Ajoutter º     º[R]® Rechercherº     º [L]® Lister   º          º");
    gotoxy(4,17);printf("º   È»             ɼ     È»             ɼ     È»             ɼ          º");
    gotoxy(4,18);printf("º    È»           ɼ       È»           ɼ       È»           ɼ           º");
    gotoxy(4,19);printf("º     ÈÍÍÍÍÍÍÍÍÍÍͼ         ÈÍÍÍÍÍÍÍÍÍÍͼ         ÈÍÍÍÍÍÍÍÍÍÍͼ            º");
    gotoxy(4,20);printf("º     ÉÍÍÍÍÍÍÍÍÍÍÍ»         ÉÍÍÍÍÍÍÍÍÍÍÍ»         ÉÍÍÍÍÍÍÍÍÍÍÍ»            º");
    gotoxy(4,21);printf("º    É¼           È»       ɼ           È»       ɼ           È»           º");
    gotoxy(4,22);printf("º   ɼ             È»     ɼ             È»     ɼ             È»          º");
    gotoxy(4,23);printf("º   º[M]® Modifier  º     º               º     º[S]® Supprimer º          º");
    gotoxy(4,24);printf("º   È»             ɼ     È»             ɼ     È»             ɼ          º");
    gotoxy(4,25);printf("º    È»           ɼ       È»           ɼ       È»           ɼ           º");
    gotoxy(4,26);printf("º     ÈÍÍÍÍÍÍÍÍÍÍͼ         ÈÍÍÍÍÍÍÍÍÍÍͼ         ÈÍÍÍÍÍÍÍÍÍÍͼ            º");
    gotoxy(4,27);printf("º                           ÉÍÍÍÍÍÍÍÍÍÍÍ»                                  º");
    gotoxy(4,28);printf("º                          É¼           È»                                 º");
    gotoxy(4,29);printf("º                         ɼ             È»                                º");
    gotoxy(4,30);printf("º                         º[Q]® Quitter   º                                º");
    gotoxy(4,31);printf("º                         È»             ɼ                                º");
    gotoxy(4,32);printf("º                          È»           ɼ                                 º");
    gotoxy(4,33);printf("º                           ÈÍÍÍÍÍÍÍÍÍÍͼ                                  º");
    gotoxy(4,34);printf("º                                                                          º");
    gotoxy(4,35);printf("º   ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»       º");
    gotoxy(4,36);printf("º  É¼                                                              È»      º");
    gotoxy(4,37);printf("º  º                  ®® TAPEZ VOTRE CHOIX S.V.P [ ] ¯¯             º      º");
    gotoxy(4,38);printf("º  È»                                                              É¼      º");
    gotoxy(4,39);printf("º   ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ       º");
    gotoxy(4,40);printf("º                                                                          º");
    gotoxy(4,41);printf("È»                                                                        É¼");
    gotoxy(4,42);printf(" È»                                                                      É¼");
    gotoxy(4,43);printf("  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
    textcolor(4);
    gotoxy(11,16);textcolor(14+BLINK);cprintf("A");
    gotoxy(32,16);textcolor(14+BLINK);cprintf("R");
    gotoxy(55,16);textcolor(14+BLINK);cprintf("L");
    gotoxy(10,23);textcolor(14+BLINK);cprintf("M");
    gotoxy(54,23);textcolor(14+BLINK);cprintf("S");
    gotoxy(32,30);textcolor(14+BLINK);cprintf("Q");
    gotoxy(34,23);textcolor(14+BLINK);cprintf("BIENVENUE");
    textcolor(7);
    }
    /***************************************************************************/
    /*                          GESTION DES STAGIAIRES                        */
    /*************************************************************************/
    /**********************fonction ajouter*********************/
    void          ajouterstg()
    {
    do
    {
    flushall();
    clrscr();
    f=fopen("c:\\stag.txt","a+");
        if(f==NULL)
        {f=fopen("c:\\stag.txt","w");}
    gotoxy(13,6); printf("ÉÍËÍ»   ÉÍËÍ»                               ÉÍËÍ»   ÉÍËÍ»       \n");
    gotoxy(13,7); printf("ÌÍÎ͹   ÌÍÎ͹                               ÌÍÎ͹   ÌÍÎ͹       \n");
    gotoxy(13,8); printf("ÈÍÊͼÉÍ»ÈÍÊͼ                               ÈÍÊͼÉÍ»ÈÍÊͼ       \n");
    gotoxy(13,9); printf("ÉÍËÍ»ÈÍ»ÉÍËÍ»                               ÉÍËÍ»ÈÍ»ÉÍËÍ»       \n");
    gotoxy(13,10);printf("ÌÍÎ͹ÈͼÌÍÎ͹                               ÌÍÎ͹ÈͼÌÍÎ͹       \n");
    gotoxy(13,11);printf("ÈÍÊͼ   ÈÍÊͼ                               ÈÍÊͼ   ÈÍÊͼ       \n");
    gotoxy(6,12);printf("                   ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»                  \n");
    gotoxy(6,13);printf("                   º                              º                  \n");
    gotoxy(6,14);printf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  °                        °  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
    gotoxy(6,15);printf("º ÉÍÍÍÍÍ           º                              º         ÍÍÍÍÍÍ» º\n");
    gotoxy(6,16);printf("º º                ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ               º º\n");
    gotoxy(6,17);printf("º º                                                               º º\n");
    gotoxy(6,18);printf("º                        °    STAGIAIRE   °                         º\n");
    gotoxy(6,19);printf("º            ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ       º\n");
    gotoxy(6,20);printf("º    Nø Inscription  :                                              º\n");
    gotoxy(6,21);printf("º                                                                   º\n");
    gotoxy(6,22);printf("º    Nom Stagiaire   :                                              º\n");
    gotoxy(6,23);printf("º                                                                   º\n");
    gotoxy(6,24);printf("º    Pr‚nom stagiaire:                                              º\n");
    gotoxy(6,25);printf("º                                                                   º\n");
    gotoxy(6,26);printf("º    Date Naissance  :                                              º\n");
    gotoxy(6,27);printf("º                                                                   º\n");
    gotoxy(6,28);printf("º   Adresse          :                                              º\n");
    gotoxy(6,29);printf("º                                                                   º\n");
    gotoxy(6,30);printf("º   Fili‚re          :                                              º\n");
    gotoxy(6,31);printf("º º                                                               º º\n");
    gotoxy(6,32);printf("º º                                                               º º\n");
    gotoxy(6,33);printf("º ÈÍÍÍÍÍ              ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»       ÍÍͼ º\n");
    gotoxy(6,34);printf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ VOULEZ VOUS AJOUTER UNE AUTRE  ÌÍÍÍÍÍÍÍÍÍÍÍͼ\n");
    gotoxy(6,35);printf("                      º          O  [    ]  N          º             \n");
    gotoxy(6,36);printf("                      ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ     \n");
    gotoxy(30,34);textcolor(14+BLINK);cprintf("VOULEZ VOUS AJOUTER UN AUTRE ");
    textcolor(7);

        aq:
        flushall();
        gotoxy(29,20);scanf("%s",&st.ninscription);

    bool=0;
         while(!feof(f))
         {flushall();

          fscanf(f,"%s\t%s\t%s\t%s\t%s\t%s\n",ninscription,nomst,Prenom
          ,adresse,daten,filiere);

    if(strcmpi(ninscription,st.ninscription)==0)
         {bool=1;
         break;
         }
         }
         if(bool==1)
         {
         gotoxy(29,20);printf("Ce num‚ro existe!!");
         gotoxy(29,20);getch();
         gotoxy(29,20);printf("                   ");
         goto aq;
         }






        gotoxy(29,22);scanf("%s",&st.nomst);
        gotoxy(29,24);scanf("%s",&st.Prenom);
        gotoxy(29,26);scanf("%s",&st.adresse);
        gotoxy(29,28);scanf("%s",&st.daten);
        gotoxy(29,30);scanf("%s",&st.filiere);

        fprintf(f,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);

        fclose(f);
        flushall();
        gotoxy(45,35);scanf("%c",&rep);
        rep=toupper(rep);
        }while(rep!='N');
           }
    /**********************fonction supprimer*******************/
    void          supprimerstg()

        {
    clrscr();
        f=fopen("c:\\stag.txt","r");
        if(f==NULL)
    {printf("le fichier est absent\n");
      getch();
      exit(0);
      }

    gotoxy(10,12);printf("                  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»                 \n");
    gotoxy(10,13);printf("                  º                              º                 \n");
    gotoxy(10,14);printf("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ° Nø A SUPPRIMER ?:..... °  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n");
    gotoxy(10,15);printf("                  º                              º                 \n");
    gotoxy(10,16);printf("                  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ                 \n");

    gotoxy(52,14);scanf("%s",&ninscription);

        bool=0;
         while(!feof(f))
         {flushall();

    fscanf(f,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);

    if(strcmpi(ninscription,st.ninscription)==0)
         {bool=1;
         break;
         }
         }
         if(bool==1)
         {
         clrscr();
    gotoxy(13,6); printf("ÉÍËÍ»   ÉÍËÍ»                               ÉÍËÍ»   ÉÍËÍ»       \n");
    gotoxy(13,7); printf("ÌÍÎ͹   ÌÍÎ͹                               ÌÍÎ͹   ÌÍÎ͹       \n");
    gotoxy(13,8); printf("ÈÍÊͼÉÍ»ÈÍÊͼ                               ÈÍÊͼÉÍ»ÈÍÊͼ       \n");
    gotoxy(13,9); printf("ÉÍËÍ»ÈÍ»ÉÍËÍ»                               ÉÍËÍ»ÈÍ»ÉÍËÍ»       \n");
    gotoxy(13,10);printf("ÌÍÎ͹ÈͼÌÍÎ͹                               ÌÍÎ͹ÈͼÌÍÎ͹       \n");
    gotoxy(13,11);printf("ÈÍÊͼ   ÈÍÊͼ                               ÈÍÊͼ   ÈÍÊͼ       \n");
    gotoxy(6,12);printf("                   ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»                  \n");
    gotoxy(6,13);printf("                   º                              º                  \n");
    gotoxy(6,14);printf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  °                        °  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\n");
    gotoxy(6,15);printf("º ÉÍÍÍÍÍ           º                              º         ÍÍÍÍÍÍ» º\n");
    gotoxy(6,16);printf("º º                ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ               º º\n");
    gotoxy(6,17);printf("º º                                                               º º\n");
    gotoxy(6,18);printf("º                        °    STAGIAIRE   °                         º\n");
    gotoxy(6,19);printf("º            ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ       º\n");
    gotoxy(6,20);printf("º    Nø Inscription  :                                              º\n");
    gotoxy(6,21);printf("º                                                                   º\n");
    gotoxy(6,22);printf("º    Nom Stagiaire   :                                              º\n");
    gotoxy(6,23);printf("º                                                                   º\n");
    gotoxy(6,24);printf("º    Pr‚nom stagiaire:                                              º\n");
    gotoxy(6,25);printf("º                                                                   º\n");
    gotoxy(6,26);printf("º    Date Naissance  :                                              º\n");
    gotoxy(6,27);printf("º                                                                   º\n");
    gotoxy(6,28);printf("º   Adresse          :                                              º\n");
    gotoxy(6,29);printf("º                                                                   º\n");
    gotoxy(6,30);printf("º   Fili‚re          :                                              º\n");
    gotoxy(6,31);printf("º º                                                               º º\n");
    gotoxy(6,32);printf("º º                                                               º º\n");
    gotoxy(6,33);printf("º ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ º\n");
    gotoxy(6,34);printf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
       gotoxy(29,20);printf("%s",st.ninscription);
        gotoxy(29,22);printf("%s",st.nomst);
        gotoxy(29,24);printf("%s",st.Prenom);
        gotoxy(29,26);printf("%s",st.adresse);
        gotoxy(29,28);printf("%s",st.daten);
        gotoxy(29,30);printf("%s",st.filiere);
      flushall();
      gotoxy(10,40);printf("voulez-vous supprimer(O/N):.........");
      gotoxy(38,40);scanf("%c",&rep);
      rep=toupper(rep);
      if(rep=='O')
      {
        f1=fopen("c:\\stag.txt","r");

      s=fopen("c:\\s.txt","w");
    while(!feof(f1))
    {
    flushall();
    // fprintf(f,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);

       fscanf(f1,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);

    if(strcmpi(ninscription,st.ninscription)!=0)
    fprintf(s,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);
    }

    fclose(f);
    f1=fopen("c:\\stag.txt","w");
    s=fopen("c:\\s.txt","r");
    while(!feof (s))
    {

    flushall();
    fscanf(s,"%s\t%s\t%s\t%s\t%s\t%s\n",&st.ninscription,&st.nomst,&st.Prenom,&st.adresse,&st.daten,&st.filiere);
    fprintf(f1,"%s\t%s\t%s\t%s\t%s\t%s\n",st.ninscription,st.nomst,st.Prenom,st.adresse,st.daten,st.filiere);
    }
      }

         }
         else
         {
          clrscr();
         printf("ce numero n'existe pas\n");
         getch();
         }
         getch();

    }
    /**********************fonction rechercher*****************/
    void          rechercherstg()
    {
        {clrscr();
        char numst[20];
        f=fopen("c:\\stag.txt","r");
         if(f==NULL)
         {printf("fichier inexistant\n");
         getch();
         exit(0);
         }
         flushall();
    gotoxy(10,12);printf("                  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»                 \n");
    gotoxy(10,13);printf("                  º                              º        &nb