Cours10
13 pages
Français

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus
13 pages
Français
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus

Description

Programmation Orienté Objet en C++  Ricard julienjricard@liris.cnrs.fr04.72.44.83.95http://liris.cnrs.fr/julien.ricard/Organisation de la matinéPointeur ThisCorrecton TP Arbre – Pointeur thisEntrées  ­ SortiesTP Entrée Sortie : Cr éation d’un image…Les 7 s éances prochaines :PROJET CPPProgrammation Orienté Objet en C++ 2Pointeur ThisPointeur This :Dans  ...

Sujets

Informations

Publié par
Nombre de lectures 224
Langue Français

Extrait

Programmation Orienté Objet  en C++   Ricard  julien jricard@liris.cnrs.fr 04.72.44.83.95 http://liris.cnrs.fr/julien.ricard/ Organisation de la  matiné Pointeur This Correcton TP Arbre – Pointeur this Entrées  ­ Sorties TP Entrée Sortie : Cr éation d’un image… Les 7 s éances prochaines : PROJET CPP Programmation Orienté Objet en C++ 2 Pointeur  This Pointeur This : Dans  l’écriture  des  fonctions  membres,  il  est  possible  d’acc éder  à  l’adresse  de    la  variable  classe, par l’intermédiaire du mot cl é « this ». Objet : Attributs :  int a; main() Méthodes Membres : 0bjet* A=new Objet(); Constructeur  A­>a=12; Descructeur A­>affichage(); void affichage(); } Autre méthodes { this­>affichage(); if(this==NULL)…. } Programmation Orienté Objet en C++ 3 Corretion TP Arbre ­ Pointeur  This class Arbre { public : Arbre(int v=0, Arbre* fg=NULL, Arbre* fd=NULL); ~Arbre(); Arbre* ajout(int v);  int maximum(); Arbre* supprimer_max(); Arbre* supression(int v); void parcours_infixe(); int tri_parcours_infixe(int* tabT, int id=0); void Aff(int i=0); private : Arbre* FG; Arbre* FD; int val; }; Programmation Orienté Objet en C++ 4 Mai n Arbre* A=NULL; for(i=0;iajout(rand()%30); A­>Aff();  A­>parcours_infixe();    int* tab= new int[N]; A­>tri_parcours_infixe(tab); for(i=0;isupression(tab[i]); A­>Aff(); }    int *tab= new int [N]; for(i=0;iajout(e); else FD=FD­>ajout(e); return this; } Programmation Orienté Objet en C++ 7 Affichag e void Arbre::Aff(int i){ if(this==NULL) cout << "{}" ; else { cout <<"{"  << val <<","; FG­>Aff(i+1); cout << "," ; FD­>Aff(i+1); cout << "}"; } if(i==0) cout<< endl; } Programmation Orienté Objet en C++ 8 SArbre* Arbre::supression(int e){uppressio if( this==NULL) return NULL;n if(e==val) if((FG==NULL)&&(FD==NULL)) delete this; return NULL; if(FG==NULL) Arbre* tmp=FD; FG=NULL; FD=NULL; delete this; return tmp; if(FD==NULL) Arbre* tmp=FG; return tmp; val=FD­>maximum(); FD=FD­>supprimer_max(); return this; else  if( valsupression(e); if( val>e)  FD=FD­>supression(e); return this; Programmation Orienté Objet en C++ 9 } Entrée  Sortie Entrée sortie standart  Iostream regroupe istream et ostream Classe ostream Sortie standart : cout  et surcharge l’op érateur <<  Autre fonctions:  cout.put(char c);  cout.write(char* tabC, int n);  cout.flush(); Programmation Orienté Objet en C++ 10
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents