1 / 13

Programmation Orienté Objet en C++

Programmation Orienté Objet en C++. Ricard julien. 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. Pointeur This. Pointeur This :

thea
Télécharger la présentation

Programmation Orienté Objet en C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programmation Orienté Objet en C++ Ricard julien

  2. 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++

  3. 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; Méthodes Membres : Constructeur Descructeur void affichage(); Autre méthodes { this->affichage(); if(this==NULL)…. } main() 0bjet* A=new Objet(); A->a=12; A->affichage(); } Programmation Orienté Objet en C++

  4. 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++

  5. Main Arbre* A=NULL; for(i=0;i<N;i++) A=A->ajout(rand()%30); A->Aff(); A->parcours_infixe(); int* tab= new int[N]; A->tri_parcours_infixe(tab); for(i=0;i<N;i++){ A=A->supression(tab[i]); A->Aff(); } int *tab= new int [N]; for(i=0;i<N;i++) tab[i]=rand()%30; int* tabT=tri_tab(tab,N); Programmation Orienté Objet en C++

  6. Constructeur destructeur Arbre::Arbre(int v,Arbre* fg, Arbre* fd){ FD=fd; FG=fg; val=v; } Arbre::~Arbre(){ if(this!=NULL){ if(FD!=NULL) delete FD; if(FG!=NULL) delete FG; } } Programmation Orienté Objet en C++

  7. Ajout Arbre* Arbre::ajout(int e){ if(this==NULL){ return (new Arbre(e)); } else if(e <val) FG=FG->ajout(e); else FD=FD->ajout(e); return this; } Programmation Orienté Objet en C++

  8. Affichage 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++

  9. Suppression Arbre* Arbre::supression(int e){ if( this==NULL) return NULL; 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; FG=NULL; FD=NULL; delete this; return tmp; val=FD->maximum(); FD=FD->supprimer_max(); return this; else if( val<e) FG=FG->supression(e); if( val>e) FD=FD->supression(e); return this; } Programmation Orienté Objet en C++

  10. 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++

  11. istream • Classe istream • Entrées strandart : cin et surcharge de >> • Autre fonctions : • int cin.get(); ou cin.get(char &c); • Int cin.peek(); • Cin.get(char*ch,int n, cahr delin =‘\n’); • Cin.read(char*ch,int n, cahr delin =‘\n’); • Int cin.gcount(); • Cin.flush(); Programmation Orienté Objet en C++

  12. Les fichiers • Classe fstream regroupe ofstream et ifstream ofstream fichierSortie(’’nom_fichier.txt’’, ios::out); if(!fichierSortie) cout << ’’Problème d’ouverture ’’; fichierSortie << ’’On écrit ce que l’on veux’’; char tab[100]; fichierSortie.write(tab,100); fichierSortie.close(); ifstream fichierEntree(’’nom_fichier.txt’’, ios::out); if(! fichierEntree) cout << ’’Problème d’ouverture ’’; char tmp[1024]; fichierEntree >> tmp; char tab[100]; fichierEntree .read(tab,100); fichierEntree.close(); Programmation Orienté Objet en C++

  13. Option d’ouverture • ios::out : ouverture en écriture • ios::in : ouverture en lecture • ios::ate : possitionnement en fin de fichier • ios::app : ouverture en allongement • ios::trunc: perte de l’ancien contenu • ios::binary: binaire Programmation Orienté Objet en C++

More Related