Methode de NEWTON RAPSON
Programme de codage
Programme de DECODAGE
TABLEUR

Methode de NEWTON RAPSON

#include<iostream.h>
#include<math.h>

double eps,L;
 

double f(double x)
{

 double a,k,P,alpha,T;int n;
 n=0;a=3;P=8;
 k=n*3.1416/(5*a);
 alpha=sqrt(L*x);
 T=alpha*a;

 return P*sin(T)/T+cos(T)-cos(a*k);  // fonction
 

}

double df(double x)
{
 double h;
 h=eps*x;

 return (f(x+h)-f(x))/h;
}

int main()
{
cout.precision(16);
// Initialisation des valeurs

L=1/3.818; // = 2m/hb^2

eps=1E-12;

//****************************** Algo

int i;
double x;

cout << eps << endl << "x=";
cin >> x;
i=1;

while ( abs(f(x))>eps )
{
 cout << "x" << i << "=" << x << ",\t f(x)=" << f(x) << endl;
 x=x-f(x)/df(x);
 i++;
}
cout << "x" << i << "=" << x << ",\t f(x)=" << f(x) << endl;

}
 
 
 
 
 
 
 
 
 
 

Programme de codage ( le texte a codeer doit se terminer par @)

#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <string.h>

const int Long=100;
typedef char TypTab[Long];

// *************************************************************************************

int Longueur_de_chaine(TypTab Tab)
{
        int i;i=0;
        while (Tab[i]!='\0') {i++;}
        return i;
}
// *************************************************************************************

int Test_Caract(int c)
{
        if ( (c>='0') && (c<='9') ) return 1;
        if ( (c>='A') && (c<='Z') ) return 2;
        if ( (c>='a') && (c<='z') ) return 3;
        else return 0;
}
// *************************************************************************************

void Demande_Fichier(TypTab FE,TypTab FS)
{
        cout << "Nom du Fichier a coder: ";
        cin.getline(FE,Long-1,'\n');
        cout << endl << "Nom du fichier recepteur: ";
        cin.getline(FS,Long-1,'\n');
        cout << endl;
        if ( FS[0]=='\0' ) { strcpy(FS,"Result");cout << "Le fichier recepteur sera : " << FS << endl ;}

}
// *************************************************************************************

void Init(int &S,int &T)
{
        srand48(time(NULL));
        S = int(drand48()*22)+3 ;
        T = int(drand48()*10)+4 ;
}
// *************************************************************************************

char Hexa(int N)
{
        if (N<=9) return ('0'+N) ;
        else return ('A'+N-10) ;
}
// *************************************************************************************

void Code(int S,int T,int &A,int &B,int &C)
{
        int v;
        v=100*S+T;
        A=int(v/256); B=int((v%256)/16); C=v%16;
        // F_sortie << Hexa(A) << Hexa(B) << Hexa(C);
}
// *************************************************************************************

void Subst(int S,TypTab Tab)
{
        int i,c,nbcar;
        char caract;
        nbcar=Longueur_de_chaine(Tab);

        for(i=0;i<=nbcar;i++)
                {
                caract=Tab[i]; c=(int)caract;
                switch(Test_Caract(c))
                {
                        case 1:Tab[i]='0'+(c-'0'+S%10)%10 ; break ;
                        case 2:Tab[i]='A'+(c-'A'+S)%26    ; break ;
                        case 3:Tab[i]='a'+(c-'a'+S)%26    ; break ;
                }
                }
}
// *************************************************************************************

void Trans(int T,TypTab LE,TypTab LS)
        {
        int param,nbcar,i,c;
        i=0;c=0;
        nbcar=Longueur_de_chaine(LE);

        for (param=0;param<nbcar;param++)
                {
                if ( c+i >= nbcar)  { c=0 ; i++ ; };
                LS[param]=LE[c+i] ; c=c+T;
                }
        }
// *************************************************************************************

/* Prog. Princ. */

int main()
{
        TypTab LigneE,LigneS,Fichier_E,Fichier_S;
        int S,T,i;

        Demande_Fichier(Fichier_E,Fichier_S);
        ifstream F_entree(Fichier_E);
        ofstream F_sortie(Fichier_S);

        if ( F_entree.fail() ) cout << "Fichier d'entre " << Fichier_E << " introuvable." << endl ;
                else
                {
                int A,B,C,nbligne,nb_total_car;
                Init(S,T);
                Code(S,T,A,B,C);
                F_sortie << Hexa(A) << Hexa(B) << Hexa(C);

                F_entree.getline(LigneE,Long-1,'\n');
                nbligne=1;nb_total_car=0;
                while (LigneE[0]!='@')
                        {
                                cout << LigneE << endl;
                                int i,nbcar;

                                nbcar=Longueur_de_chaine(LigneE);
                                for (i=0;i<=nbcar;i++) {LigneS[i]=LigneE[i];}

                                Subst(S,LigneE);
                                Trans(T,LigneE,LigneS);
                                F_sortie << LigneS << endl;

                                nbligne++ ; nb_total_car=nb_total_car+nbcar ;

                                F_entree.getline(LigneE,Long-1,'\n');
                        }
                F_sortie << LigneE << endl;
                cout << endl << "Codage termine." << (char) 7 << endl;
                cout << nbligne << " lignes codees." << endl ;
                cout << nb_total_car << " caracteres." ;
                }
}
 
 
 
 

Programme de DECODAGE
 

#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream.h>
#include <math.h>

const int Long=100;
typedef char TypTab[Long];
//*****************************************************************************************
int Deci(char A)
{   int N;
    N=(int)A;
    if (isdigit(A)) return (N-'0');
    else return (N-'A'+10);
    }
// ****************************************************************************************
void decode(TypTab LE,int&S,int&T)
{  int v,i,nbcar;
        char A,B,C;
       A=LE[0];  B=LE[1];  C=LE[2];
        v=256*Deci(A) +16*Deci(B) +Deci(C);
 S=floor(v/100); T=v%100;
 nbcar=strlen(LE);
 for(i=0;i<=nbcar-1;i++)  {LE[i]=LE[i+3];}
 }

// ****************************************************************************************
void Substitute(TypTab Tab,int S)
{
        int i,c,nbcar;
        char caract;
        nbcar=strlen(Tab);

                for(i=0;i<=nbcar;i++)
                        {
                        caract=Tab[i]; c=(int)caract;
 

                        if (isdigit(caract))   Tab[i]='0'+(c-'0'-S%10+10)%10;
                        else if (islower(caract)) Tab[i]='a'+(c-'a'-S+26)%26;
                        else if (isupper(c))   Tab[i]='A'+(c-'A'-S+26)%26;
                        }
   }
// ****************************************************************************************
void Trans(TypTab LigneE,TypTab LigneS,int T)
        {
        int param,nbcar,i,c;
        i=0;c=0;
        nbcar=strlen(LigneE); //nbre de caractÉres//

        for (param=0;param<nbcar;param++)
                {
                if ( c+i >= nbcar)  { c=0 ; i++ ; };
                LigneS[c+i]=LigneE[param] ; c=c+T;
                }
        }
// ****************************************************************************************
/* Prog. Princ. */

int main()
{

        TypTab LigneE,LigneS;
        int i,T,S;
 
 

        cin.getline(LigneE,Long-1,'\n');
 decode(LigneE,S,T);
        while (LigneE[0]!='@')
           {
    int i,nbcar;
                 nbcar=strlen(LigneE);
                 for (i=0;i<=nbcar;i++) {LigneS[i]=LigneE[i];}
 

                 Substitute(LigneE,S);
                        Trans(LigneE,LigneS,T);
                        cout << LigneS << endl;
                        cin.getline(LigneE,Long-1,'\n');
                        }

        cout << LigneE << endl;

}
 

TABLEUR

Cellule.h

// Definition de la structure Cellule et de la classe Tableau.
// V2.0

/* Definition des types */

typedef char *Texte;
typedef char TypTab[80];

// *** TypMaillon pour creer L'arbre ***

typedef struct TypMaillon
{
 int Op;
 double Val;
 TypMaillon *Droit;
 TypMaillon *Gauche;
} TypMaillon;

typedef TypMaillon *TypPtrMaillon;

// *** TypListe Pour les dependances ***

typedef struct TypListe
{
 int L;
 int C;
 TypListe * CSuiv;

} TypListe;

typedef TypListe *TypPtrListe;

// *** Definition de la structure Cellule ***/

typedef struct TypCellule
{
 
 int Ligne;
 int Colonne;
 Texte Expression;
 double Valeur;
 
 TypPtrListe C_Dep;  // = Cellules qui dependent de cette cellule
 TypPtrListe C_EFF_Dep; // = Cellules pour les modif.
 
 TypCellule *CSH;
 TypCellule *CSV;
 
 
} TypCellule ;

/* Definition du type pointeur sur cellule */

typedef TypCellule * TypPtrCellule;

/* Definition de la classe tableau qui va gerer les cellules */

class Tableau
{
 public:
 // Constructeur
 Tableau();

 // Destructeur
 ~Tableau();
 
 // Observateur

 double Val_Cellule(int L,int C);
 void Afficher(int L,int C);
 void Voir_Dep(int L,int C);
 void Voir_Dep2();
 void Consulter(int L,int C);
 void Dem_Sauver(bool &sort);
 void Sauver(TypTab Nom_fich);
 double TrouveNombre(Texte T,int &i);
 void Charger(TypTab Nom_fich);
 
 // Modificateurs
 
 void Aj_Cellule(int L,int C,Texte Ex);
 void Sup_Cellule(int L,int C);

 private:
 TypPtrCellule Pre_Cellule;
 
 TypPtrCellule PtrCellule(int L,int C);
 void Affecter_Donnees(TypPtrCellule Cellule,int L,int C,Texte Ex,int Type);
 double Calcul_Valeur(TypPtrCellule Cellule,Texte Ex,bool Dep);
 void ReCalc(TypPtrCellule Cellule);

 void Enlever_Dep(TypPtrCellule Cellule);
 void Aj_Dep(TypPtrCellule Cellule,int L,int C,int T);
 void Sup_Dep(TypPtrCellule Cellule,int L,int C,int T);
 
 
 // procedure pour l'arbre

 bool IsOperateur(char C,int &Op);
 void CreerMaillon(TypPtrCellule Cellule,TypPtrMaillon M,Texte Ex,bool Dep);
 double Val_Maillon(TypPtrMaillon M);
 
};
 

arbre.C

// Definition de l'arbre et calcul

#include "Cellule.h"
#include<iostream.h>
#include<math.h>
#include<ctype.h>

double Tableau::TrouveNombre(Texte T,int &i)
{
 TypTab Tab;
 int j=0;
 
 do { Tab[j]=T[i+j]; j++; }
 while ( isdigit(T[i+j]) || T[i+j]=='.' );
 
 Tab[j]='\0';
 i=i+j; // i devient la pos. de l'operateur
 
 return atof(Tab);
}

bool Tableau::IsOperateur(char C,int &Op)
{
 const Texte Operateurs="*/+-";
 Op=0;
 for (int i=0;i<4;i++)
 { if (C==Operateurs[i]) { Op=1+i; return 1;} }
 
 return 0;
}

 
void Tableau::CreerMaillon(TypPtrCellule Cellule,TypPtrMaillon M,Texte Ex,bool Dep)
{
 TypPtrCellule PC;
 int Op,L,C;
 double V;
 Texte E1,E2;
 E1=new char[80];
 E2=new char[80];
 L=0;C=0;
 
 int i,j,Nbp;
 int l=strlen(Ex);
 
 // Test si l'expression est un nombre.
 
 if ( isdigit(Ex[0])||(Ex[0]=='-') )
  { i=0; V=TrouveNombre(Ex,i); Op=0; }

 // Test si l'expression est une cellule.
 
 else if (Ex[0]=='L')
  {
  i=1;L=int(TrouveNombre(Ex,i));
  i++;C=int(TrouveNombre(Ex,i));
  Op=0; V=Val_Cellule(L,C);
 
  // Dependance des cellules si Dep=True
  if (Dep==true)
   {
   PC=PtrCellule(L,C);
   if (PC==NULL) { Aj_Cellule(L,C,"0"); PC=PtrCellule(L,C); }
 
   Aj_Dep(PC,Cellule->Ligne,Cellule->Colonne,1);
   Aj_Dep(Cellule,L,C,2);
   }
  }
 
 // Test si l'expression est du type: Ex=(Ex1oEx2).
 
 else if ( Ex[0]=='(' )
  {
  i=0;Nbp=0;V=0;
 
  // Recherche de E1,E2 et de l'operateur.
  do
   {
    i++; E1[i-1]=Ex[i];
    if ( Ex[i]=='(' ) Nbp++;
    if ( Ex[i]==')' ) Nbp--;
   }
  while ( Nbp!=0||IsOperateur(Ex[i],Op)==false||i==1 );
 
  E1[i-1]='\0';
  for (j=i+1;j<l-1;j++) { E2[j-i-1]=Ex[j]; }
  E2[l-i-2]='\0';
 
  // Creation des maillons pour E1 et E2
 
  M->Gauche=new TypMaillon;
  M->Droit=new TypMaillon;
  CreerMaillon(Cellule,M->Gauche,E1,Dep);
  CreerMaillon(Cellule,M->Droit,E2,Dep);
  }
 
 // Affectation des valeurs au maillon.
 M->Op=Op; M->Val=V;
}

double Tableau::Val_Maillon(TypPtrMaillon M)
{
 double VG,VD,Val;
 
 if (M->Op==0) { Val=M->Val; }
 else
  {
  VG=Val_Maillon(M->Gauche);
  VD=Val_Maillon(M->Droit);
  switch(M->Op)
   {
   case 1: Val=VG*VD; break;
   case 2: Val=VG/VD; break;
   case 3: Val=VG+VD; break;
   case 4: Val=VG-VD; break;
   default: Val=M->Val; break;
   }
  // Ramasse Miette
  delete M->Gauche; delete M->Droit;
  }
 return Val;
}

double Tableau::Calcul_Valeur(TypPtrCellule Cellule,Texte Ex,bool Dep)
{
// Definir les variables
 double Val;
 TypPtrMaillon Arbre=new TypMaillon;
// Creer Arbre
 CreerMaillon(Cellule,Arbre,Ex,Dep);
// Interpreteur (si necessaire)
 Val=Val_Maillon(Arbre);
// detruire arbre (<=> delete maillon 1 de l'arbre)
 delete Arbre;
 
 return Val;
}
 

Tableau.C

// Definition du module Tableau

#include "Cellule.h"
#include<iostream.h>
#include<fstream.h>
#include<ctype.h>
#include<math.h>

/* Constructeur */

Tableau::Tableau()
{
 Pre_Cellule=new TypCellule;
 Affecter_Donnees(Pre_Cellule,1,1,"0",1);
}

/* Destructeur */

Tableau::~Tableau()
{
 TypPtrCellule CM,C,PC;
 CM=Pre_Cellule;
 while (CM!=NULL)
  {
  C=CM->CSH;
  while (C!=NULL)
   {
   PC=C;
   C=C->CSH;
   delete PC;
   }
  PC=CM;
  CM=CM->CSV;
  delete PC;
  }
 Pre_Cellule=new TypCellule;
 Affecter_Donnees(Pre_Cellule,1,1,"0",1);
// cout << "Tableau efface." << endl;
}

/* Observateurs */

double Tableau::Val_Cellule(int L,int C)
{
 TypPtrCellule CT=PtrCellule(L,C);
 if (CT==NULL) return 0;
 else return CT->Valeur;
}

void Tableau::Consulter(int L,int C)
{
 TypPtrCellule P=PtrCellule(L,C);
 cout << "L" << L << "C" << C << "\t=";
 if (P==NULL) cout << "0" << endl;
 else cout << P->Expression << endl << "\t=" << P->Valeur << endl;
}
 
void Tableau::Afficher(int L,int C)
{
 const int Nb_L=10;
 const int Nb_C=9;
 int i,j;
 cout << endl;
 for (i=0;i<Nb_C;i++) cout <<"\t" <<C+i;
 cout << endl;
 
 for (j=0;j<Nb_L;j++)
  {
 
  cout << L+j << "\t";
  for (i=0;i<Nb_C;i++)
   {
   cout << Val_Cellule(L+j,C+i);
   if (PtrCellule(L+j,C+i)!=NULL) cout << ">";
   cout << "\t";
   }
  cout << endl;
  }
}

/*************************************************/

/* Modificateurs */

void Tableau::Aj_Cellule(int L,int C,Texte Ex)
{
//cout << "Ajouter la Cellule L" <<L<<"C"<<C<<"."<<endl;
TypPtrCellule C_Temp=PtrCellule(L,C); // on pointe sur la cellule(L,C)
if (C_Temp!=NULL) // Test si la cellule existe
 { // si oui on modifie la cellule
 Enlever_Dep(C_Temp); // on supprime la dependance par rapport
    // aux autres Cellules
 Affecter_Donnees(C_Temp,L,C,Ex,0);
 }
else
 { // si non on ajoute la cellule
 TypPtrCellule PC,Cellule;
 PC=PtrCellule(L,1); // PC pointe sur la cellule mere
 
 if (PC==NULL) // Test si la cellule mere existe,
  {  // si elle n'existe pas, on la cree.
  PC=Pre_Cellule;
  while ( (PC->CSV!=NULL)&&((PC->CSV)->Ligne<L) )
   { PC=PC->CSV;} // recherche de l'emplacement
     // de la cellule mere
  Cellule=new TypCellule;
  Affecter_Donnees(Cellule,L,1,"0",1);
  Cellule->CSV=PC->CSV;
  PC->CSV=Cellule;

  PC=Cellule; // PC pointe sur la cellule mere
  }
 
 if (C==1) // Test si la cellule a creer est une cellule mere
  { // si oui on lui affecte les donnees
  Affecter_Donnees(PC,L,C,Ex,0);
  }
 else
  { // si non on cree la cellule
 
  while ( (PC->CSH!=NULL)&&((PC->CSH)->Colonne<C) )
   { PC=PC->CSH;} // recherche de l'emplacement
     // de la cellule

  Cellule=new TypCellule;
  Affecter_Donnees(Cellule,L,C,Ex,1);
  Cellule->CSH=PC->CSH;
  PC->CSH=Cellule;

  }
 }
}
 

void Tableau::Sup_Cellule(int L,int C)
{
TypPtrCellule PC,PC2,C_Temp;
PC=PtrCellule(L,C);
// cout << "Suppression"<<endl;
if (PC==NULL) // Test si la cellule existe
 { cout << "Cellule inexistante. Suppression impossible." << endl; }
else
 { // si la cellule existe alors:
 Enlever_Dep(PC);
 if ( (PC->C_Dep!=NULL)||( (C==1)&&( (L==1)||(PC->CSH!=NULL) ) ) )
 // Test si d'autres cellules dependent de cette cellule
 // ou si cette cellule est une cellule mere qui a des cellules filles
 // ou si c'est la Pre_Cellule
  { // Si oui alors modifier seulement le contenu
  Affecter_Donnees(PC,L,C,"0",0);
  }
 else
  { // sinon supprimer la cellule
  PC=Pre_Cellule;
  while ( ((PC->CSV)->Ligne!=L)&&(L!=1) ) PC=PC->CSV;
  // Recherche de la cellule mere precedente
  if (C==1) // Test se c'est une cellule mere
   {  // si oui alors supprimer la cellule mere
   C_Temp=PC->CSV;  // Cellule a supprimer
   PC->CSV=C_Temp->CSV; // Raccord
   delete C_Temp;  // Suppression
   }
  else
   { // si non supprimer la cellule fille
 
   if (L!=1) PC=PC->CSV; // Cellule mere de la cellule a supprimer
   PC2=PC;

   // Recherche de la cellule precedente
   while ( (PC->CSH)->Colonne!=C ) PC=PC->CSH;
 
   C_Temp=PC->CSH;  // Cellule a supprimer
   PC->CSH=C_Temp->CSH; // Raccord
   delete C_Temp;  // Suppression

   // Test si l'on doit supprimer la cellule mere
   if ( strcmp(PC2->Expression,"0")==0 )
    { Sup_Cellule(L,1); }
   }
  }
// cout << "L"<<L<<"C"<<C<<"=0."<<endl;
 }
}

void Tableau::Dem_Sauver(bool &sort)
{
 TypTab Nom_fich,quest;
 sort=0;
 cout << "Nom du fichier: ";
 cin >> Nom_fich;
 
 // Test si le fich existe
 
 ifstream Fich(Nom_fich);
 if ( !Fich.fail() )
  {
  do {
   cout << "Ce fichier existe deja. Voulez-vous le remplacer ? ";
   cin >> quest;
   if ( strcmp(quest,"NON")==0 || strcmp(quest,"non")==0 )
    { sort=1; }
   else if ( strcmp(quest,"OUI")==0 || strcmp(quest,"oui")==0 )
    { Sauver(Nom_fich); sort=1; }
   } while (sort==0);
  }
 else if (sort==0) Sauver(Nom_fich);
}
void Tableau::Sauver(TypTab Nom_fich)
{
 TypPtrCellule CM,C,PC;
 CM=Pre_Cellule;
 
 // Declaration
 ofstream Fich(Nom_fich);
 
 if (!Fich) cout << "Enregistrement impossible" << endl;
 else
 {
  while (CM!=NULL)
  {
  C=CM;
  while (C!=NULL)
   {
   Fich << C->Ligne << ' ';
   Fich << C->Colonne << ' ';
   Fich << C->Expression << endl;
   C=C->CSH;
   }
  CM=CM->CSV;
  }
 cout << "Tableau sauve." << endl;
 }
}
void Tableau::Charger(TypTab Nom_fich)

{
TypTab Li,Co,Tampon;
Texte Expression = new TypTab;
int L,C,i,j;
i=0;

ifstream Fich(Nom_fich);
if ( Fich.fail() ) cout << "Lecture impossible."<< endl;
else
 while(!Fich.eof())
 {
 cin.sync();
 Fich.getline(Tampon,80);
 while(Tampon[i]!=' ')
  {Li[i]=Tampon[i];
  i++;
  }
 Li[i]='\0';
 L=atof(Li);
 i++;
 j=i;
 while(Tampon[i]!=' ')
  {Co[i-j]=Tampon[i];
  i++;
  }
 Co[i-j]='\0';
 C=atof(Co);
 i++;
 j=i;
 while(Tampon[i]!=' ' && Tampon[i]!='\0')
  {Expression[i-j]=Tampon[i];
  i++;
  }
 Expression[i-j]='\0';
 Aj_Cellule(L,C,Expression);
 Expression=new TypTab;
 i=0;
 }
}

// PRIVATE

TypPtrCellule Tableau::PtrCellule(int L,int C)
{

 TypPtrCellule C_Temp;
 C_Temp=Pre_Cellule; // on pointe sur la premiere cellule
 while ( (C_Temp!=NULL)&&(C_Temp->Ligne<L) ) // Recherche verticale
  { C_Temp=C_Temp->CSV;}
 if ( (C_Temp==NULL)||(C_Temp->Ligne>L) ) return NULL;
 
 while ( (C_Temp!=NULL)&&(C_Temp->Colonne<C) ) // Recherche horizontale
  { C_Temp=C_Temp->CSH;}
 if ( (C_Temp==NULL)||(C_Temp->Colonne>C) ) return NULL;

 return C_Temp;
}

void Tableau::Affecter_Donnees(TypPtrCellule Cellule,int L,int C,Texte Ex,int Type)
{
 if (Type==1)
  {
  Cellule->CSV=NULL;
  Cellule->CSH=NULL;
  Cellule->C_Dep=NULL;
  Cellule->C_EFF_Dep=NULL;
  }

 Cellule->Ligne=L;
 Cellule->Colonne=C;
 Cellule->Expression=Ex;
 Cellule->Valeur=Calcul_Valeur(Cellule,Ex,true);
 
 ReCalc(Cellule);
}

void Tableau::ReCalc(TypPtrCellule Cellule)
{
 TypPtrListe PC=Cellule->C_Dep;
 TypPtrCellule C;
 if (PC!=NULL)
 {
//  cout << "Calcul des cellules liees pour L";
//  cout << Cellule->Ligne<< "C" << Cellule->Colonne << endl;
  while (PC!=NULL)
  {
   C=PtrCellule(PC->L,PC->C);
   C->Valeur=Calcul_Valeur(C,C->Expression,false);
   cout << "\t==> L" << PC->L <<"C"<<PC->C;
   cout << "=" << C->Valeur <<endl;
   ReCalc(C);
   PC=PC->CSuiv;
  }
//  cout << "FIN" << endl;
 }
}
 

void Tableau::Aj_Dep(TypPtrCellule Cellule,int L,int C,int T)
{
 TypPtrListe PC=new TypListe;
 PC->L=L; PC->C=C;
 switch(T)
 {
 case 1: PC->CSuiv=Cellule->C_Dep; Cellule->C_Dep=PC; break;
 case 2: PC->CSuiv=Cellule->C_EFF_Dep; Cellule->C_EFF_Dep=PC; break;
 }
}

void Tableau::Sup_Dep(TypPtrCellule Cellule,int L,int C,int T)
{
 TypPtrListe PC,Temp;
 switch(T)
 {
 case 1: PC=Cellule->C_Dep; break;
 case 2: PC=Cellule->C_EFF_Dep; break;
 }
 if ( (PC->L==L)&&(PC->C==C) )  // cas ou la cellule est en tete
  { Temp=PC->CSuiv; delete PC;
  switch(T)
   {
   case 1: Cellule->C_Dep=Temp; break;
   case 2: Cellule->C_EFF_Dep=Temp; break;
   }
  }
 else
  {
  while( !( (PC->CSuiv->L==L)&&(PC->CSuiv->C==C) ) )
   { PC=PC->CSuiv; } // Recherche de la c prec
  Temp=PC->CSuiv;
  PC->CSuiv=Temp->CSuiv;
  delete Temp;
  }
}

void Tableau::Voir_Dep(int L,int C)
{
 TypPtrCellule CTEMP=PtrCellule(L,C);
 if (CTEMP==NULL) cout << "La Cellule n'a pas de dep.\n";
 else
 {
  TypPtrListe PC=CTEMP->C_Dep;
  cout << "C_Dep= ";
  while (PC!=NULL)
  { cout << "L" << PC->L << "C" << PC->C << " "; PC=PC->CSuiv; }
  PC=CTEMP->C_EFF_Dep;
  cout << endl << "C_EFF_Dep= " ;
  while (PC!=NULL)
  { cout << "L" << PC->L << "C" << PC->C << " "; PC=PC->CSuiv; }
  cout << endl;
 }
}

void Tableau::Voir_Dep2()
{
 TypPtrListe PC;
 TypPtrCellule C,CM;
 CM=Pre_Cellule;
 while (CM!=NULL)
  {
  C=CM;
  while (C!=NULL)
   {
   cout << "L" << C->Ligne << "C" << C->Colonne << "\t";
   PC=C->C_Dep;
   cout << "C_Dep= ";
   while (PC!=NULL)
   { cout << "L" << PC->L << "C" << PC->C << " "; PC=PC->CSuiv; }

   PC=C->C_EFF_Dep;
   cout << endl << "\tC_EFF_Dep= " ;
   while (PC!=NULL)
   { cout << "L" << PC->L << "C" << PC->C << " "; PC=PC->CSuiv; }
   cout << endl;
   C=C->CSH;
   }
  CM=CM->CSV;
  }
}
void Tableau::Enlever_Dep(TypPtrCellule Cellule)
{
 TypPtrListe P,PC=Cellule->C_EFF_Dep;
 TypPtrCellule C; // Cellule a effacer de la liste
 while (PC!=NULL)
  {
  C=PtrCellule(PC->L,PC->C);
  if (C!=NULL)
   {
   Sup_Dep(C,Cellule->Ligne,Cellule->Colonne,1);
 
   // Suppression de la cellule si elle est vide
   if ( (C->C_Dep==NULL)&&(strcmp(C->Expression,"0")==0) )
    {
    Sup_Cellule(C->Ligne,C->Colonne);
    }
 
   P=PC;
   PC=PC->CSuiv;
   delete P;
   }
  }
 
 
 Cellule->C_EFF_Dep=NULL;
}

Projet.C

/* Projet
   Programme principal
*/
 
 

#include "Cellule.h"
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream.h>
#include <math.h>

const int Long=100;

bool Caractere_Precedent(TypTab expres);
int Traitement_expression(TypTab expres);

int Longueur_de_chaine(TypTab Tab)
{
        int i;i=0;
        while (Tab[i]!='\0') {i++;}
        return i-1;
}
/**************************************************************/

bool TestC (int i,TypTab expres)
 {
 if (i==0) return 0;
 while ( (i-1>=0) && isdigit(expres[i-1])  )
  { i--; }
 
 if ((i-1)< 0)  return 0;
 else { if (expres[i-1]=='L')  return 1; else return 0; }
 }
 

/**************************************************************/

bool TestPoint (int i,TypTab expres)
 {
 if (i==0) return 0;
 if (!isdigit(expres[i-1])) return 0;
 while ( (i-1>=0) && isdigit(expres[i-1])  )
  { i--; }
 
 if ( expres[i]!='.')  return 1; else  return 0;
 
 }
 
/********* Test si ce qui precede un chiffre convient *********/

bool Testnun (int i, TypTab tab)
{
 if ( tab[i-1]==')' )  return 0;
 else return 1;
}

/*********** Enleve les espaces dans l expression *************/
 

void espace_eraser(TypTab ex,TypTab ex2)
 {
 int N=Longueur_de_chaine(ex);
 int j=0,i;

 for (i=0;i<=N+1;i++)
  {
  if ( ex[i]!=' ' && ex[i]!='\t')
   { ex2[j]=ex[i]; j++; }
  }
 }

/************************ Cherche i et j  en partant de L
  Si l expression commencant par l n est pas de la forme licj i et j reste a 0 */

 

void TEST_L_C( int  position_L , TypTab tableau,bool z)

{
 int q;
 int i,j;
 z=1;
 i=0;j=0;
 
 q=position_L+1;
 while (isdigit(tableau[q]) && (i<65001))   { i=i*10+int(tableau[q])-'0';q++;}
 if (tableau[q]=='C' )
  {
  q++;
  while (isdigit(tableau[q]) && (j<65001))  {j=j*10+int(tableau[q]) -'0';q++;}
  }

if (i==0 || j==0) z=0;
}

double TrouveNombre(Texte T,int &i)
{
 TypTab Tab;
 int j=0;
 
 do { Tab[j]=T[i+j]; j++; }
 while ( isdigit(T[i+j]) || T[i+j]=='.' );
 
 Tab[j]='\0';
 i=i+j; // i devient la pos. de l'operateur
 
 return atof(Tab);
}

/* INTERPRETEUR DE COMMANDE */

void Interpreteur(TypTab Commande,int&i,int&j,int&Nb_Com,TypTab ex)

/*  Cette procedure  a pour resultat Nb_Com,i,j,expression

 si la commande est du type LiCj=expression   : si expression=0 alors Nb_Com=2
       sinon Nb_Com=1
 
 si la commande est du type LiCj?  Nb_Com=3
 si la commande est REINIT   Nb_Com=4
 si la commande est SAUVER   Nb_Com=5
 si la commande est OUVRIR ou CHARGER  Nb_Com=6
 si la commande est FERMER   Nb_Com=7
 si la commande est AFFICHER   Nb_Com=8
 
*/

{
 TypTab Com;
 espace_eraser(Commande,Com);
 int N=Longueur_de_chaine(Com);
 int pos,k;bool erreur;
 i=0;j=0;Nb_Com=0;erreur=0;
 
 if ( strcmp(Com,"REINIT")==0 || strcmp(Com,"reinit")==0 ) Nb_Com=4;
 else if ( strcmp(Com,"SAUVER")==0 || strcmp(Com,"sauver")==0 ) Nb_Com=5;
 else if ( strcmp(Com,"OUVRIR")==0 || strcmp(Com,"ouvrir")==0 ) Nb_Com=6;
 else if ( strcmp(Com,"FERMER")==0 || strcmp(Com,"fermer")==0 ) Nb_Com=7;
 else if ( strcmp(Com,"AFFICHER")==0 || strcmp(Com,"afficher")==0 ) Nb_Com=8;
 else if ( strcmp(Com,"CHARGER")==0 || strcmp(Com,"charger")==0 ) Nb_Com=6;
 else if (Com[0]='L')
  {
  pos=1;i=int(TrouveNombre(Com,pos));
  if (Com[pos]=='C')
  {
   pos++;j=int(TrouveNombre(Com,pos));
   if (Com[pos]=='?') Nb_Com=3;
   else if (Com[pos]=='=')
    {
    for (k=pos+1;k<=N+1;k++) ex[k-pos-1]=Com[k];
    if (ex[0]=='\0') Nb_Com=2;
    else
     {
     if ( (Caractere_Precedent(ex)==1)&&(Traitement_expression(ex)==1) ) Nb_Com=1;
     else Nb_Com=0;
     }
    }
   else Nb_Com=0;
  }
  else Nb_Com=0;
 }
}

/******* TEST SI UN CARACTERE APPARTIENT A "LC1234567890-+=/*()." *********/

bool TestCaract(char C)

{
char *caract="LC1234567890-+/*().";
int Long=Longueur_de_chaine(caract);
int i=0;

for (i=0;i<Long+1;i++)
 {
 if (C==caract[i]) return 1;
 }
return 0;

}

/********** TESTE SI UN CARACTERE EST UN OPERATEUR ou L ou C ou . *********/

bool Test(char C)
{
char *caract="-+/*LC.";
int Long=Longueur_de_chaine(caract);
int i=0;

for (i=0;i<Long+1;i++)
 {
 if (C==caract[i]) return 1;
 }
return 0;

}
/******** TESTE SI UN CARACTERE EST UN OPERATEUR *******/

bool TestOperateur(char C)

{
char *caract="-+=/*";
int Long=Longueur_de_chaine(caract);
int i=0;

for (i=0;i<Long+1;i++)
 {
 if (C==caract[i]) return 1;
 }
return 0;

}

/***** TESTE SI UNE CHAINE EST BIEN FORMEE DES CARACTERES "LC1234567890-+=/*()." ********/

int Traitement_expression(TypTab expres)

{
int N,i;
N=Longueur_de_chaine(expres);

for (i=0;i<N+1;i++)
 {
 if (TestCaract(expres[i])==0) return 0;
 }
return 1;
}
/******* REGARDE POUR CHAQUE CARACTERE SI LE CARACTERE LE PRECEDENT CONVIENT ****************
********          ET COMTE LE NOMBRE DE PARENTESE OUVERTE ET FERMEE          ****************/

bool Caractere_Precedent(TypTab expres)

{int N,i;bool vraie,z;
vraie=0;
int o=0;
int f=0;
N=Longueur_de_chaine(expres);
z=1;
i=0;
int l=0;
int c=0;
while ( z==1 && i<N+1)
 {
 if ((expres[i])=='(')
     {
     o++;
  if  ((i!=0)  && !TestOperateur(expres[i-1])  && (expres[i-1]!='('))
  z=0;
  }
 if ((expres[i])==')')
     {
     f++;
  if  ( (i==0)  || (!isdigit(expres[i-1])) && (expres[i-1]!=')') )
  z=0;
  }
 if (TestOperateur(expres[i]) )
  {
  if  (((!isdigit(expres[i-1]))&&(expres[i-1]!=')'))&&(i!=0)  )
  z=0;
  }
 if ((expres[i])=='L')
    {
    l++;
  TEST_L_C( i , expres, vraie);
  if  ((i!=0)  && !TestOperateur(expres[i-1])  && (expres[i-1]!='(') && (vraie==0))
  z=0;
  }
 
 if( isdigit(expres[i]) && i==N && !Testnun(i,expres))  { z=Testnun(N,expres) ; }
 
 if (expres[i]=='C')
  {
  c++;
  z=TestC(i,expres);}
  if (expres[i]=='.') {z=TestPoint(i,expres) ;}
  i++;
 }

if (o!=f || c!=l) z=0;
if (TestOperateur(expres[N])) z=0;
return z;
}

/**********************************************************
************** PROGAMME PRINCIPAL *************************
**********************************************************/

int main()
{
 Tableau T;
 bool vide=1,modifie=0,sort;

 int Nb_Com,L,C;
 TypTab Commande,quest;
 Texte Ex=new TypTab;
 cout << endl;
 cout << "Tableur Vf." << endl;
 cout << "Projet realise par FIAT,LEFEVRE et PEREIRA" << endl;
 cout << endl;
 do
 {
  cout << "> ";
  cin.sync();
  cin.getline(Commande,Long-1,'\n');
   Interpreteur(Commande,L,C,Nb_Com,Ex);
  cin.sync();
 
  switch(Nb_Com)
  {
  case 1: // Ajouter
   T.Aj_Cellule(L,C,Ex);
   Ex=new TypTab;
   vide=0;modifie=1;
   break;
 
  case 2: // Effacer
   T.Sup_Cellule(L,C);
   vide=0;modifie=1;
   break;
 
  case 3: // Consulter
   T.Consulter(L,C);
   break;

  case 4: // Reinitialiser
   if (!vide)
    {
    sort=1;
    do
     {
     cout << "Desirez-vous enregister les changements ? ";
     cin >> quest;
     if ( strcmp(quest,"OUI")==0 || strcmp(quest,"oui")==0 )
      {
      T.Dem_Sauver(sort);
      vide=0; modifie=0;
      }
     else if ( strcmp(quest,"NON")==0 || strcmp(quest,"non")==0 )
      { sort=1; }
     } while (sort==0);
    T.~Tableau();
    cout << "Tableau efface." << endl;
    }
 
   else cout << "Tableau deja vide." << endl;
   vide=1;modifie=1;
   break;
 
  case 5: // Sauver
   if ( (!vide)&&modifie) { T.Dem_Sauver(sort);vide=0; modifie=0; }
   else if (vide) cout << "Tableau vide." << endl;
   else if (!modifie) cout << "Tableau non modifie." << endl;
   break;
 
  case 6: // Ouvrir ou charger
   T.~Tableau();
   TypTab fichier;
   cout << "nom du fichier?" <<  endl;
   cin.sync();
   cin.getline(fichier,Long-1,'\n');
   T.Charger(fichier);
   vide=0;modifie=1;
   break;
 
  case 7: // Fermer
   if ( (!vide)&&modifie)
    {
    sort=1;
    do
     {
     cout << "Desirez-vous enregister les changements ? ";
     cin >> quest;
     if ( strcmp(quest,"OUI")==0 || strcmp(quest,"oui")==0 )
      { T.Dem_Sauver(sort); vide=0; modifie=0; }
     else if ( strcmp(quest,"NON")==0 || strcmp(quest,"non")==0 )
      { sort=1; }
     } while (sort==0);
    }
   break;
 
  case 8: // Afficher
   T.Afficher(1,1);
   break;
 
  case 0:
   cout << "Erreur de commande." << endl;
   break;
  }
 }
 while (Nb_Com!=7);
}

makefile

Tableur : Projet.o Cellule.o arbre.o
 aCC Projet.o Cellule.o arbre.o -o Tableur
 
arbre.o : arbre.C Cellule.h
 aCC -c arbre.C -o arbre.o

Cellule.o : Tableau.C Cellule.h
 aCC -c Tableau.C -o Cellule.o

Projet.o : Projet.C Cellule.h
 aCC -c Projet.C -o Projet.o
 

FIN TABLEUR



Methode de NEWTON RAPSON
Programme de codage
Programme de DECODAGE
TABLEUR