Génie logiciel : Justification de texte
Hors ligneBinfranck Le 10/06/2008 Ă  17:05 Profil de Binfranck Configuration de Binfranck

Bonjour à tous,

Nous avons un Travail Pratique de Genie Logiciel, notre tache consiste à faire un programme permettant à un utilisateur de justifier son texte saisi, alors au moment de l'exécution, rien ne se passe pourtant on a déjà gaspillé bcp de temps dans la conception et la verification des erreurs., le programme a été fait dans C++... nous sommes tellement decus de facon que nous venons encore une fois auprès de vous pour solliciter la solution :

voici alors notre programme nous voulons savoir si vous pouvez aussi y dénicher quelques erreurs :

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
ifstream fichier_source;
ofstream fichier_temp,fichier_justif;
int True=0; int False=-1;
class justification_de_texte
{
   public:

      int tester_chemin();
      void reformatage_texte();
      void ecriture_de_la_ligne(int lngeur, int i, int drap);
      int recherche_commande();
      void affichage_texte();
      int test_texte();
      void fichier_justifie_texte();

   private:

      char _mots[100];
      char _chemindef[40];
      int _nombr_aj;
      int _nombr_dj;
};


void justification_de_texte::affichage_texte()
{
     ifstream fichierjust("C:\\TP Genie\\justification.txt");
     int lngeur=0;
     int i=0,esp=0,total_esp=0,p=0,temp_ent=0;
if(!fichierjust)
{
cout<<"fichier inexistant";
}
else
{
    char mot[100];
    cout<<endl<<" ";
    do {
        fichierjust>>mot;
        temp_ent=lngeur+strlen(mot)+i;
        if(temp_ent)
        {
        total_esp=80-lngeur+1;
        esp=total_esp/i;
        p=i-1;
        for(int k=0;k<i;k++)
        {
                if(k==0)
                        { cout<<_mots[k];total_esp--;continue;}
                        if(k!=p)
                        { for(int t=0;t<esp;t++)
                         cout<<" ";
                          total_esp--;}
        else
                    {
                          for(int t=0;t<total_esp;t++)
                          {cout<<" ";}
                       cout<<_mots[k];
                       }
                       }
                cout<<endl<<" ";
        if(temp_ent<80)
        {strcpy(_mots,mot);
        lngeur=strlen(mot);}
        else
            {i=0;lngeur=0;}
            cout<<" ";
            }
      else
          {strcpy(_mots,mot);
          lngeur+=strlen(mot);
          i++;
          }
      }  while(!fichierjust.eof());
      
      }
      }

int justification_de_texte::tester_chemin()
{

  char nom_fichier[100];
  cout<<"Tapez le nom du fichier sans l'extension : ";
  cin>>nom_fichier;
  cout<<endl;
  strcpy(_chemindef,"C:\\TP Genie\\");
  strcat(_chemindef,nom_fichier);
  strcat(_chemindef,".txt");

   fichier_source.open(_chemindef);
   if(fichier_source)
       return(0);
   else
      return(-1);
}      

void justification_de_texte::ecriture_de_la_ligne(int lngeur, int i, int drap)
{
  
  int p=0,total_esp=0,temp_ent=0, reste=0, esp=0;

  
  total_esp=80-lngeur+1;
  
  esp=(total_esp)/i;
  reste=total_esp%i;
  cout<<"total_esp :"<<total_esp<<" lngeur: "<<lngeur<<" esp : "<<esp<<" i: "<<i<<" reste "<<reste<<endl;
  p=i-1;
  if(drap==1)
  {
    for(int k=0;k<i;k++)
    {

       fichier_justif<<_mots[k]<<" ";
    }
    fichier_justif<<endl;
    return;
  }

  for(int k=0;k<i;k++)
  {
  
   if (k==0)
      {fichier_justif<<_mots[k]; continue; }
   if(k!=p)
   {
      
      for(int t=0;t<esp;t++)
      {
         fichier_justif<<" ";          
         total_esp--;
      }
      fichier_justif.put(_mots[k]);
    }
    else    
    {
      
       for(int t=0;t<total_esp;t++)
         {
            fichier_justif<<" ";
         }
        
         fichier_justif<<_mots[k];
    }
  }
  fichier_justif<<endl;
}

int justification_de_texte::test_texte()
{
   int i=0,j=0;
   char mot_temp[4];
   char mot[30];
  
   if(tester_chemin()!=0)
   {
     cout<<"Chemin du incorrect"<<endl;
     return(-1);
     exit(-1);
   }
  
   fichier_temp.open("C:\\TP Genie\\textejustifie.txt");
   if(!fichier_temp)
   {
    
    cout<<"Impossible de cr‚er le fichier tempon"<<endl;
    return(-1);
    exit(-1);
   }

   do
   {
     fichier_source>>mot;    
     fichier_temp<<mot<<' ';
     if(strlen(mot)>3)
     {                          
        strncpy(mot_temp,mot,3);
       if((strcmp(mot_temp,".aj")==0)||(strcmp(mot,".AJ")==0))          
         _nombr_aj++;
       if((strcmp(mot_temp,".dj")==0)||(strcmp(mot,".DJ")==0))
          _nombr_dj++;
            
      
     }
     i++;
     if( _nombr_aj>_nombr_dj)
     {
       cout<<" "<<endl;
       cout<<"Fin d'une justification sans debut"<<endl;
       cout<<"Erreur survenue au "<<i<<"e mot"<<endl;
       return(-1);
       exit(-1);
     }
   }while(!fichier_source.eof());
   if(_nombr_dj>_nombr_aj)
   {
      cout<<" "<<endl;
      cout<<"Debut de la justification sans fin"<<endl;
       cout<<"Erreur survenue au "<<i<<"e mot"<<endl;
      return(-1);
      exit(-1);
   }
   else
   fichier_temp<<" ";
   return(0);

}


void justification_de_texte::reformatage_texte()
{
  char mot[100];
  ifstream fichier_tempon;  
  int i=0, j=0, lngeur=0,temp_ent=0, compteur=0;
  int drap=0;
  
  reformatage_texte();
  fichier_tempon.open("C:\\TP Genie\\textejustifie.txt");
  
  if(!fichier_tempon)
  {
     cout<<"Impssible d ouvrir le fichier. "<<endl;
     return;
     exit(-1);
  }
  fichier_justif.open("C:\\TP Genie\\textejustifie.txt");
  
  if(!fichier_justif)
  {
     cout<<"Erreur,le fichier de sortie nomme textejustifie.txt n a pas ete cree "<<endl;
     return;
     exit(-1);                            
  }
  
  do
  {
    fichier_tempon>>mot;

    if(strcmp(mot,".xy")==0)
    {
    
       if(i>0)
          {
          drap=0;
          ecriture_de_la_ligne(lngeur,i,drap);
          lngeur=0;i=0; drap=0;
          }
       else
          fichier_justif<<endl;
      
    }
    else
    {
       if((strcmp(mot,".lb")==0)||(strcmp(mot,".LB")==0))
       {
        
          drap=1;
          ecriture_de_la_ligne(lngeur,i,drap);
          drap=0;
          fichier_justif<<endl;      
          lngeur=0;
          i=0;
        }
       else
       {
         if((strcmp(mot,".dj")==0)||(strcmp(mot,".aj")==0))
         {
            compteur++;
           if(strcmp(mot,".aj")==0)
           {
              
              drap=1;
              ecriture_de_la_ligne(lngeur,i,drap);
              drap=0;
              lngeur=0;
              compteur=0;
              i=0;
             return;              
          
           }      

          if(i>=1)
          {
            
            
            fichier_justif<<_mots[100]<<endl;
            i=0;lngeur=0;
           }
          else
          {
           fichier_justif<<endl; lngeur=0;
           }
        }
        else
        {
          
           temp_ent=lngeur+strlen(mot)+i;      
           if(compteur==0)
           {
                          
               fichier_justif<<mot<<" ";
                  cout<<mot;
                  fichier_temp<<mot;

                if(strcmp(mot,".aj")==0)
                   { continue;};

                 lngeur+=strlen(mot)+1;
                 if (lngeur>80)
                    {fichier_justif<<endl<<mot<<" ";lngeur=0;}
                  else
                    {fichier_justif<<mot<<" ";}
            
              }
              if(temp_ent<=80)
              {
                strcpy(_mots,mot);
                lngeur=lngeur+strlen(mot);
                i++;
               }
               else
               {
              
                  ecriture_de_la_ligne(lngeur,i,drap);
                  fichier_justif<<" ";
                  if(temp_ent>80)
                  {
                      strcpy(_mots,mot);
                      i=1;
                      lngeur=strlen(mot);
                   }
                   else
                   {
                      
                      i=0;
                      lngeur=0;
                    }
                }
      
           }
       }
    }

  }while (!fichier_source.eof());

}






int justification_de_texte::recherche_commande()
{
  if((_nombr_aj==0) && (_nombr_dj==0))
     return(-1);
  else
    return(0);
}

void justification_de_texte::fichier_justifie_texte()
{
  _nombr_aj=0;
  _nombr_dj=0;
}

int main()
{
  justification_de_texte projet_texte;  
  ofstream nouveau;
  char mon_choix;
  int i=0;

int True = 0;
int False = -1;
  cout<<"--------------------------------------------------------\n"<<"|";
  cout<<""<<" \n        TRAVAIL PRATIQUE DE GENIE"                  <<"|";  
  cout<<"|"<<"\n\n       JUSTIFICATION DE TEXTE\n"                 << "|";

  cout<<" "<<" Travail presente par:Denis Cishugi Mirindi Denis \n" <<"|";
  cout<<" "<<"                            Cibalonza Fishi        \n"<<"|";
  cout<<" "<<"                         Franck Ndsushabandi Baguma\n"<<"|";
  cout<<" "<<"\n-------------------------------------------------\n"<<"|";
  cout<<" "<<"\n                                              \n"   <<"|";
  cout<<" "<<  "              MENU GENERAL                        " <<"|";
  cout<<" "<<" Choisissez un choix parmi ceux ci-dessous\n " <<"|";
  cout<<" "<<" 1. Quitter pour saisir mon texte a justifier\n   "   <<"|";
  cout<<" "<<" 2. justifier mon texte deja saisi\n   "              <<"|";
  cout<<" "<<"\n---------------------------------------------------\n""|";
  cout<<" "<<"\n Saisissez le chiffre de votre choix : ";                            
  cin>>mon_choix;

  switch(mon_choix)
  {
    case '1':
    {
        cout<<"\n saisissez votre texte a justifier puis l enregistrer le dans C:\\TP Genie\\ \n";
    }exit(-1);
    case '2':
    {
  
      if (projet_texte.test_texte()==0)
      {
         cout<<"Le texte ne contient pas d'erreurs"<<endl;
         if(projet_texte.recherche_commande()==0)
         {
              cout<<" "<<endl;                  
             projet_texte.reformatage_texte();
             projet_texte.affichage_texte();
            
         }
         else
           cout<<endl<<"Vous n'avez placé aucune commande du texte a justifier"<<endl;
      }
      else
      {
          cout<<" "<<endl;
          cout<<"Votre fichier a des erreurs"<<endl;        
      }
    }
    exit(-1);

    default:
    {
       cout<<endl<<"Votre choix n'est pas pris en compte."<<endl;
    }exit(-1);
  }
  cin>>mon_choix;
}
--

Research for Planet_HSOFT

Hors ligneKdecherf Le 19/06/2008 Ă  23:39 Profil de Kdecherf Configuration de Kdecherf

Merci d'utiliser des services comme http://pastebin.com pour coller des fichiers sources ...
Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels