Zaibon

Untitled

Oct 5th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include "Carte.h"
  5.  
  6.  
  7. //constructeur par default
  8. Carte::Carte(){
  9.     nom[0] = 0;
  10.     serie = NULL;
  11.     numero = 0;
  12.     caraScore.setNom("");
  13.     caraScore.setScore(0);
  14. }
  15. //constructeur d'initilisation
  16. Carte::Carte(const char* n,const char* nomS,const int num,const CaracteristiqueScore cs){
  17.     setNom(n);
  18.     serie = NULL;
  19.     setSerie(nomS);
  20.     setNumero(num);
  21.     setCaracteristiqueScore(cs);
  22. }
  23. //constructeur de copy
  24. Carte::Carte(const Carte& c){
  25.     setNom(c.nom);
  26.     serie = NULL;
  27.     setSerie(c.serie);
  28.     setNumero(c.numero);
  29.     setCaracteristiqueScore(c.caraScore);
  30. }
  31.  
  32. //destructeur
  33. Carte::~Carte(){
  34. //  cout << "apprele de desctructeur pour " << nom << endl;
  35.     if(serie != NULL)
  36.         delete serie;
  37. }
  38.  
  39.  
  40. //getter - setter
  41. void Carte::setNom(const char* n){
  42.     if(n){
  43.         strcpy(nom,n);
  44.     }else{
  45.         strcpy(nom,"");
  46.     }
  47. }
  48. const char* Carte::getNom() const{
  49.     return nom;
  50. }
  51.  
  52. void Carte::setSerie(const char* s){
  53.     if(serie) delete serie;
  54.     if(s){
  55.         serie = new char[strlen(s)+1];
  56.         strcpy(serie,s);
  57.     }else{
  58.         serie = NULL;
  59.     }
  60. }
  61. char* Carte::getSerie() const{
  62.     return serie;
  63. }
  64.  
  65. void Carte::setNumero(int n){
  66.     numero = n;
  67. }
  68. int Carte::getNumero() const{
  69.     return numero;
  70. }
  71.  
  72. void Carte::setCaracteristiqueScore(const CaracteristiqueScore cs){
  73.     caraScore.setNom(cs.getNom());
  74.     caraScore.setScore(cs.getScore());
  75. }
  76.  
  77. CaracteristiqueScore Carte::getCaracteristiqueScore()const {
  78.     return caraScore;
  79. }
  80.  
  81. //methode
  82. void Carte::affiche() const {
  83.     std::cout << "Nom : " << nom << std::endl;
  84.     if(serie == NULL){
  85.         std::cout << "serie : Inconnue " << std::endl;
  86.     }else{
  87.         std::cout << "Serie : " << serie << std:: endl;
  88.     }
  89.     std::cout << "Numero : " << numero << std::endl;
  90.     caraScore.affiche();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment