SlideShare a Scribd company logo
1 of 36
Download to read offline
TP1:Carré Magique
Implementation C++

Mohamed Boudchiche
        M.R.I.


   27 décembre 2012
main.cpp
                   Solution.h
                 Solution.cpp




Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                              Solution.h
                            Solution.cpp




main.cpp




           Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                                Solution.h
                              Solution.cpp




main.cpp
Solution.h




             Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                              Solution.h
                            Solution.cpp




main.cpp
Solution.h
Solution.cpp




           Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




#include <cstdlib>
#include <iostream>
#include "Solution.h"
using namespace std ;
int main(int argc, char *argv[])
{
  int premier[]={1,2,3,4,5,6,7,8,9} ;
  int dernier[]={9,8,7,6,5,4,3,2,1} ;
  solution first(premier) ;
  solution last(dernier) ;
  solution curent ;
  int iteration=1 ;
  for(curent=first ;curent<=last ;curent++)
  {
       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                           Solution.h
                         Solution.cpp




      if(curent.isMagic()) curent.print() ;
      iteration++ ;
    }
    cout«"Nombre iteration : "«k«endl ;
    system("PAUSE") ;
    return 0 ;
    }
}




        Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                   Solution.h
                 Solution.cpp




Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




class solution
{
  private :
     int permt[9] ;




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                          Solution.h
                        Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;
     void print() const ;




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;
     void print() const ;
     bool isMagic() const ;




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;
     void print() const ;
     bool isMagic() const ;
     bool operator<=(const solution&) ;



      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
  private :
     int permt[9] ;
  public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;
     void print() const ;
     bool isMagic() const ;
     bool operator<=(const solution&) ;
     solution& operator++(int) ;


      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
main.cpp
                         Solution.h
                       Solution.cpp




class solution
{
   private :
     int permt[9] ;
   public :
     solution() ;
     solution(int []) ;
     solution( const solution&) ;
     solution& operator=(const solution&) ;
     void print() const ;
     bool isMagic() const ;
     bool operator<=(const solution&) ;
     solution& operator++(int) ;
};

      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




solution : :solution()
{
}




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




solution : :solution()
{
}
solution : :solution(int a[9])
{
  for(int i=0 ;i<9 ;i++)
     permt[i]=a[i] ;
}




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




solution : :solution()
{
}
solution : :solution(int a[9])
{
  for(int i=0 ;i<9 ;i++)
     permt[i]=a[i] ;
}
solution : :solution(const solution& b)
{
  for(int i=0 ;i<9 ;i++)
     permt[i]=b.permt[i] ;
}

      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




solution& solution : :operator=(const solution& b)
{
  for(int i=0 ;i<9 ;i++)
     permt[i]=b.permt[i] ;
  return *this ;
}




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




bool solution : :operator<=(const solution& last)
{
  int k=0 ;
  for(int i=0 ;i<9 ;i++)
  {
     if(permt[i]<last.permt[i]) return true ;
     if(permt[i]=last.permt[i]) k++ ;
  }
  if(k==9-1)return true ;
  else return false ;
}



      Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                       operator=(const solution& b)
                           main.cpp
                                       operator<=(const solution& last)
                          Solution.h
                                       solution& solution : :operator++(int n)
                        Solution.cpp
                                       bool solution : :isMagic() const
                                       void solution : :print() const




solution& solution : :operator++(int n)
{
  solution& copy = *this ;
  for (int a = 9 - 2 ; a >= 0 ; –a)
     if (copy.permt[a] < copy.permt[a + 1])
     for(int b = 9 - 1 ;b>=0 ; –b)
       if (copy.permt[b] > copy.permt[a])
       {
          int t = copy.permt[a] ;
          copy.permt[a] = copy.permt[b] ;
          copy.permt[b] = t ;
          for (++a, b = 9 - 1 ; a < b ; ++a, –b)
            {
               t = copy.permt[a] ;
       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                        operator=(const solution& b)
                            main.cpp
                                        operator<=(const solution& last)
                           Solution.h
                                        solution& solution : :operator++(int n)
                         Solution.cpp
                                        bool solution : :isMagic() const
                                        void solution : :print() const




                      copy.permt[a] = copy.permt[b] ;
                      copy.permt[b] = t ;
                 }
                 return copy ;
         }
    return *this ;
}




        Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                       operator=(const solution& b)
                           main.cpp
                                       operator<=(const solution& last)
                          Solution.h
                                       solution& solution : :operator++(int n)
                        Solution.cpp
                                       bool solution : :isMagic() const
                                       void solution : :print() const



bool solution : :isMagic() const
{
  int som = 15 ;//(9*(9*9 +1))/2 ;
  int S ;




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                       operator=(const solution& b)
                           main.cpp
                                       operator<=(const solution& last)
                          Solution.h
                                       solution& solution : :operator++(int n)
                        Solution.cpp
                                       bool solution : :isMagic() const
                                       void solution : :print() const



bool solution : :isMagic() const
{
  int som = 15 ;//(9*(9*9 +1))/2 ;
  int S ;
  //–––-> Ligne
  for(int j=0 ;j<3 ;j++){
     S=0 ;
     for(int i=0 ;i<3 ;i++) S+=permt[i+j*3] ;
     if(som !=S) return false ;
  }




       Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                    operator=(const solution& b)
                        main.cpp
                                    operator<=(const solution& last)
                       Solution.h
                                    solution& solution : :operator++(int n)
                     Solution.cpp
                                    bool solution : :isMagic() const
                                    void solution : :print() const



bool solution : :isMagic() const
{
  int som = 15 ;//(9*(9*9 +1))/2 ;
  int S ;
  //–––-> Ligne
  for(int j=0 ;j<3 ;j++){
     S=0 ;
     for(int i=0 ;i<3 ;i++) S+=permt[i+j*3] ;
     if(som !=S) return false ;
  }
  //–––-> Colone
  for(int j=0 ;j<3 ;j++){
     S=0 ;
     for(int i=0 ;i<3 ;i++)S+=permt[j+i*3] ;
     if(som !=S) return false ;
  }    Etudiant: Mohamed Boudchiche TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                operator=(const solution& b)
                    main.cpp
                                operator<=(const solution& last)
                   Solution.h
                                solution& solution : :operator++(int n)
                 Solution.cpp
                                bool solution : :isMagic() const
                                void solution : :print() const




Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                    operator=(const solution& b)
                        main.cpp
                                    operator<=(const solution& last)
                       Solution.h
                                    solution& solution : :operator++(int n)
                     Solution.cpp
                                    bool solution : :isMagic() const
                                    void solution : :print() const




//–––-> Diagonale
S=0 ;
for(int i=0 ;i<3 ;i++)S+=permt[i+i*3] ;
if(som !=S) return false ;




    Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                        operator=(const solution& b)
                            main.cpp
                                        operator<=(const solution& last)
                           Solution.h
                                        solution& solution : :operator++(int n)
                         Solution.cpp
                                        bool solution : :isMagic() const
                                        void solution : :print() const




    //–––-> Diagonale
    S=0 ;
    for(int i=0 ;i<3 ;i++)S+=permt[i+i*3] ;
    if(som !=S) return false ;
    //–––-> AntiDiagonale
    S=0 ;
    for(int i=0 ;i<3 ;i++)S+=permt[3-1-i+i*3] ;
    if(som !=S) return false ;
    return true ;
}




        Etudiant: Mohamed Boudchiche    TP1:Carré Magique
solution() ; solution(int a[9]) ; solution(const solution& b)
                                      operator=(const solution& b)
                          main.cpp
                                      operator<=(const solution& last)
                         Solution.h
                                      solution& solution : :operator++(int n)
                       Solution.cpp
                                      bool solution : :isMagic() const
                                      void solution : :print() const




void solution : :print() const
{
  for(int i=0 ;i<3 ;i++)
  {
     cout « "+–-+–-+–-+"« endl ;
     for(int j=0 ;j<3 ;j++)
       cout « "| "« permt[j+i*3] « " " ;
     cout « "+–-+–-+–-+"« endl « endl ;
  }
}




      Etudiant: Mohamed Boudchiche    TP1:Carré Magique

More Related Content

Viewers also liked

Viewers also liked (6)

DNS
DNSDNS
DNS
 
part of speech tagger for ARABIC TEXT
part of speech tagger for ARABIC TEXTpart of speech tagger for ARABIC TEXT
part of speech tagger for ARABIC TEXT
 
Introduction à MATLAB
Introduction à MATLABIntroduction à MATLAB
Introduction à MATLAB
 
Développement Sous Android
Développement Sous AndroidDéveloppement Sous Android
Développement Sous Android
 
Cours rn 2006
Cours rn 2006Cours rn 2006
Cours rn 2006
 
présentation soutenance PFE.ppt
présentation soutenance PFE.pptprésentation soutenance PFE.ppt
présentation soutenance PFE.ppt
 

Recently uploaded

les_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkles_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkRefRama
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaireTxaruka
 
L'expression du but : fiche et exercices niveau C1 FLE
L'expression du but : fiche et exercices  niveau C1 FLEL'expression du but : fiche et exercices  niveau C1 FLE
L'expression du but : fiche et exercices niveau C1 FLElebaobabbleu
 
La mondialisation avantages et inconvénients
La mondialisation avantages et inconvénientsLa mondialisation avantages et inconvénients
La mondialisation avantages et inconvénientsJaouadMhirach
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfAmgdoulHatim
 
L application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxL application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxhamzagame
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film françaisTxaruka
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfachrafbrahimi1
 
Formation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptxFormation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptxrajaakiass01
 
Les roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptxLes roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptxShinyaHilalYamanaka
 
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetFormation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetJeanYvesMoine
 
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...Universidad Complutense de Madrid
 
Cours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesCours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesMohammedAmineHatoch
 
658708519-Power-Point-Management-Interculturel.pdf
658708519-Power-Point-Management-Interculturel.pdf658708519-Power-Point-Management-Interculturel.pdf
658708519-Power-Point-Management-Interculturel.pdfMariaClaraAlves46
 
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdf
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdfSTRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdf
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdfGamal Mansour
 
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKRAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKNassimaMdh
 
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxikospam0
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...Nguyen Thanh Tu Collection
 
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxIntégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxabdououanighd
 

Recently uploaded (20)

les_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkles_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhk
 
Echos libraries Burkina Faso newsletter 2024
Echos libraries Burkina Faso newsletter 2024Echos libraries Burkina Faso newsletter 2024
Echos libraries Burkina Faso newsletter 2024
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaire
 
L'expression du but : fiche et exercices niveau C1 FLE
L'expression du but : fiche et exercices  niveau C1 FLEL'expression du but : fiche et exercices  niveau C1 FLE
L'expression du but : fiche et exercices niveau C1 FLE
 
La mondialisation avantages et inconvénients
La mondialisation avantages et inconvénientsLa mondialisation avantages et inconvénients
La mondialisation avantages et inconvénients
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdf
 
L application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxL application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptx
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film français
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdf
 
Formation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptxFormation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptx
 
Les roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptxLes roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptx
 
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetFormation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
 
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
 
Cours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesCours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiques
 
658708519-Power-Point-Management-Interculturel.pdf
658708519-Power-Point-Management-Interculturel.pdf658708519-Power-Point-Management-Interculturel.pdf
658708519-Power-Point-Management-Interculturel.pdf
 
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdf
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdfSTRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdf
STRATEGIE_D’APPRENTISSAGE flee_DU_FLE.pdf
 
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKRAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
 
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
 
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxIntégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
 

Carré Magique Cpp

  • 1. TP1:Carré Magique Implementation C++ Mohamed Boudchiche M.R.I. 27 décembre 2012
  • 2. main.cpp Solution.h Solution.cpp Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 3. main.cpp Solution.h Solution.cpp main.cpp Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 4. main.cpp Solution.h Solution.cpp main.cpp Solution.h Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 5. main.cpp Solution.h Solution.cpp main.cpp Solution.h Solution.cpp Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 6. main.cpp Solution.h Solution.cpp #include <cstdlib> #include <iostream> #include "Solution.h" using namespace std ; int main(int argc, char *argv[]) { int premier[]={1,2,3,4,5,6,7,8,9} ; int dernier[]={9,8,7,6,5,4,3,2,1} ; solution first(premier) ; solution last(dernier) ; solution curent ; int iteration=1 ; for(curent=first ;curent<=last ;curent++) { Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 7. main.cpp Solution.h Solution.cpp if(curent.isMagic()) curent.print() ; iteration++ ; } cout«"Nombre iteration : "«k«endl ; system("PAUSE") ; return 0 ; } } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 8. main.cpp Solution.h Solution.cpp Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 9. main.cpp Solution.h Solution.cpp class solution Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 10. main.cpp Solution.h Solution.cpp class solution { Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 11. main.cpp Solution.h Solution.cpp class solution { private : Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 12. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 13. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 14. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 15. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 16. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 17. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 18. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; void print() const ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 19. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; void print() const ; bool isMagic() const ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 20. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; void print() const ; bool isMagic() const ; bool operator<=(const solution&) ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 21. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; void print() const ; bool isMagic() const ; bool operator<=(const solution&) ; solution& operator++(int) ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 22. main.cpp Solution.h Solution.cpp class solution { private : int permt[9] ; public : solution() ; solution(int []) ; solution( const solution&) ; solution& operator=(const solution&) ; void print() const ; bool isMagic() const ; bool operator<=(const solution&) ; solution& operator++(int) ; }; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 23. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const solution : :solution() { } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 24. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const solution : :solution() { } solution : :solution(int a[9]) { for(int i=0 ;i<9 ;i++) permt[i]=a[i] ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 25. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const solution : :solution() { } solution : :solution(int a[9]) { for(int i=0 ;i<9 ;i++) permt[i]=a[i] ; } solution : :solution(const solution& b) { for(int i=0 ;i<9 ;i++) permt[i]=b.permt[i] ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 26. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const solution& solution : :operator=(const solution& b) { for(int i=0 ;i<9 ;i++) permt[i]=b.permt[i] ; return *this ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 27. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const bool solution : :operator<=(const solution& last) { int k=0 ; for(int i=0 ;i<9 ;i++) { if(permt[i]<last.permt[i]) return true ; if(permt[i]=last.permt[i]) k++ ; } if(k==9-1)return true ; else return false ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 28. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const solution& solution : :operator++(int n) { solution& copy = *this ; for (int a = 9 - 2 ; a >= 0 ; –a) if (copy.permt[a] < copy.permt[a + 1]) for(int b = 9 - 1 ;b>=0 ; –b) if (copy.permt[b] > copy.permt[a]) { int t = copy.permt[a] ; copy.permt[a] = copy.permt[b] ; copy.permt[b] = t ; for (++a, b = 9 - 1 ; a < b ; ++a, –b) { t = copy.permt[a] ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 29. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const copy.permt[a] = copy.permt[b] ; copy.permt[b] = t ; } return copy ; } return *this ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 30. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const bool solution : :isMagic() const { int som = 15 ;//(9*(9*9 +1))/2 ; int S ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 31. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const bool solution : :isMagic() const { int som = 15 ;//(9*(9*9 +1))/2 ; int S ; //–––-> Ligne for(int j=0 ;j<3 ;j++){ S=0 ; for(int i=0 ;i<3 ;i++) S+=permt[i+j*3] ; if(som !=S) return false ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 32. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const bool solution : :isMagic() const { int som = 15 ;//(9*(9*9 +1))/2 ; int S ; //–––-> Ligne for(int j=0 ;j<3 ;j++){ S=0 ; for(int i=0 ;i<3 ;i++) S+=permt[i+j*3] ; if(som !=S) return false ; } //–––-> Colone for(int j=0 ;j<3 ;j++){ S=0 ; for(int i=0 ;i<3 ;i++)S+=permt[j+i*3] ; if(som !=S) return false ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 33. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 34. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const //–––-> Diagonale S=0 ; for(int i=0 ;i<3 ;i++)S+=permt[i+i*3] ; if(som !=S) return false ; Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 35. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const //–––-> Diagonale S=0 ; for(int i=0 ;i<3 ;i++)S+=permt[i+i*3] ; if(som !=S) return false ; //–––-> AntiDiagonale S=0 ; for(int i=0 ;i<3 ;i++)S+=permt[3-1-i+i*3] ; if(som !=S) return false ; return true ; } Etudiant: Mohamed Boudchiche TP1:Carré Magique
  • 36. solution() ; solution(int a[9]) ; solution(const solution& b) operator=(const solution& b) main.cpp operator<=(const solution& last) Solution.h solution& solution : :operator++(int n) Solution.cpp bool solution : :isMagic() const void solution : :print() const void solution : :print() const { for(int i=0 ;i<3 ;i++) { cout « "+–-+–-+–-+"« endl ; for(int j=0 ;j<3 ;j++) cout « "| "« permt[j+i*3] « " " ; cout « "+–-+–-+–-+"« endl « endl ; } } Etudiant: Mohamed Boudchiche TP1:Carré Magique