Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <iostream>
- #include "Carte.h"
- //constructeur par default
- Carte::Carte(){
- nom[0] = 0;
- serie = NULL;
- numero = 0;
- caraScore.setNom("");
- caraScore.setScore(0);
- }
- //constructeur d'initilisation
- Carte::Carte(const char* n,const char* nomS,const int num,const CaracteristiqueScore cs){
- setNom(n);
- serie = NULL;
- setSerie(nomS);
- setNumero(num);
- setCaracteristiqueScore(cs);
- }
- Carte::Carte(const char* n,const char* nomS,const int num,const char* cNom,const int cScore){
- setNom(n);
- serie = NULL;
- setSerie(nomS);
- setNumero(num);
- caraScore.setNom(cNom);
- caraScore.setScore(cScore);
- }
- //constructeur de copy
- Carte::Carte(const Carte& c){
- setNom(c.nom);
- serie = NULL;
- setSerie(c.serie);
- setNumero(c.numero);
- setCaracteristiqueScore(c.caraScore);
- }
- //destructeur
- Carte::~Carte(){
- // s << "apprele de desctructeur pour " << nom << endll;
- if(serie != NULL)
- delete serie;
- }
- //Surgarche des opérateur
- Carte& Carte::operator=(const Carte& c){
- setNom(c.nom);
- serie = NULL;
- setSerie(c.serie);
- setNumero(c.numero);
- setCaracteristiqueScore(c.caraScore);
- return (*this);
- }
- Carte Carte::operator+(int add){
- Carte c(*this);
- c.caraScore.setScore(c.caraScore.getScore()+add);
- return c;
- }
- Carte Carte::operator-(int less){
- Carte c(*this);
- c.caraScore.setScore(c.caraScore.getScore()-less);
- return c;
- }
- int Carte::operator-(Carte c){
- int result = 0;
- Carte carte(*this);
- if(carte.caraScore.getNom() != c.caraScore.getNom() ) return -1;
- return carte.caraScore.getScore() - c.caraScore.getScore();
- }
- std::ostream& operator<<(std::ostream& s,const Carte& c){
- /* s << "Nom : " << c.getNom(); << endll;
- s << "Serie : " << c.getSerie() << endll;
- s << "Numero : " << c.getNumero() << endll;
- s << "Caracteristique : " << c.caraScore.getNom() << endll;
- s << "Score : " << c.caraScore.getScore() << endll;
- */
- c.affiche(s);
- return s;
- }
- bool Carte::operator<(const Carte c){
- Carte carte(*this);
- if(strcmp(carte.caraScore.getNom(),c.caraScore.getNom()) != 0 ) return false;
- if(carte.caraScore.getScore() < c.caraScore.getScore() ) return true;
- return false;
- }
- bool Carte::operator>(const Carte c){
- Carte carte(*this);
- if(strcmp(carte.caraScore.getNom(),c.caraScore.getNom()) != 0 ) return false;
- if(carte.caraScore.getScore() > c.caraScore.getScore() ) return true;
- return false;
- }
- Carte Carte::operator++(){//préfixé
- (*this).caraScore.setScore((*this).caraScore.getScore() + 5);
- return (*this);
- }
- Carte Carte::operator++(int){//postfixé
- Carte c(*this);
- (*this).caraScore.setScore(c.caraScore.getScore() + 5);
- return c;
- }
- //getter - setter
- void Carte::setNom(const char* n){
- if(n){
- strcpy(nom,n);
- }else{
- strcpy(nom,"");
- }
- }
- const char* Carte::getNom() const{
- return nom;
- }
- void Carte::setSerie(const char* s){
- if(serie) delete serie;
- if(s){
- serie = new char[strlen(s)+1];
- strcpy(serie,s);
- }else{
- serie = NULL;
- }
- }
- char* Carte::getSerie() const{
- return serie;
- }
- void Carte::setNumero(int n){
- numero = n;
- }
- int Carte::getNumero() const{
- return numero;
- }
- void Carte::setCaracteristiqueScore(const CaracteristiqueScore cs){
- caraScore.setNom(cs.getNom());
- caraScore.setScore(cs.getScore());
- }
- CaracteristiqueScore Carte::getCaracteristiqueScore()const {
- return caraScore;
- }
- //methode
- void Carte::affiche(std::ostream& s) const {
- s << "Nom : " << nom << std::endl;
- if(serie == NULL){
- s << "serie : Inconnue " << std::endl;
- }else{
- s << "Serie : " << serie << std::endl;
- }
- s << "Numero : " << numero << std::endl;
- caraScore.affiche();
- }
Advertisement
Add Comment
Please, Sign In to add comment