Vous êtes sur la page 1sur 5

Cmammifre.

h
#pragma once
#include <iostream>
using namespace std;
class Cmammifre
{
int m_poids;
int m_age;
int m_typem;
public:

};

Cmammifre();
Cmammifre(int, int, int);
Cmammifre(const Cmammifre &);
~Cmammifre();
friend ostream & operator<<(ostream& os, Cmammifre & );
friend istream & operator>>(istream & is, Cmammifre & M);
virtual char* Type();

Cmammifre.cpp
#include "Cmammifre.h"
Cmammifre::Cmammifre()
{
m_age = 0;
m_typem = 0;
m_poids = 0;
}
Cmammifre::Cmammifre(int age,int type,int poids)
{
m_age = age;
m_typem = type;
m_poids = poids;
}
Cmammifre::Cmammifre(const Cmammifre &M)
{
m_age = M.m_age;
m_typem = M.m_typem;
m_poids = M.m_poids;
}
ostream &operator <<(ostream&os, Cmammifre &M)
{
cout << " Le poids du mammifre est : " << endl;
os << M.m_poids << endl;
cout << "Le type du mammifre est carnivore si 1, herbivore si 2 : " << endl;
os << M.m_typem << endl;
cout << " L'ge du mammifre est : " << endl;
os << M.m_age << endl;
return os;
}
istream &operator >>(istream&is, Cmammifre &M)
{
cout << " Rentrez le poids du mammifre : " << endl;
is >> M.m_poids;

cout << "Rentrez le type du mammifre, 1 = Carnivore ou 2 = Herbivore : " << endl;
is >> M.m_typem;
cout << "Rentrez l'age du mammifre : " << endl;
is >> M.m_age;
return is;
}
Cmammifre::~Cmammifre()
{
}
char * Cmammifre::Type()
{
return "Je suis un mammifre";
}

CChevre.h
#pragma once
#include "Cmammifre.h"
class CChevre :
public Cmammifre
{
int m_litresc;
public:

};

CChevre(int, int, int, int);


CChevre(const CChevre & C);
char * TYPE();
friend ostream & operator<<(ostream& os, CChevre &);
friend istream & operator>>(istream & is, CChevre &);
CChevre();
~CChevre();

CChevre.cpp
#include "Chevre.h"
CChevre::CChevre() : Cmammifre()
{
m_litresc = 0;
}
CChevre::CChevre(int poids, int age, int typem, int litresc) : Cmammifre(poids,age,typem)
{
m_litresc = litresc;
}
CChevre::CChevre(const CChevre & H) : Cmammifre(Cmammifre(H))
{
m_litresc = H.m_litresc;
}
char * CChevre::TYPE()
{
return "Type : Chvre" ;
}
ostream & operator<<(ostream & os, CChevre &H)
{

Cmammifre *M3 = &H;


os << *M3;
cout << "Le nombres de litres produit par la vache chaque jour est : " << endl;
os << H.m_litresc;
return os;
}
istream & operator>>(istream & is, CChevre &H)
{
Cmammifre *M3 = &H;
is >> *M3;
cout << "Rentrez le nombres de litres produit par la vache chaque jour : ";
is >> H.m_litresc;
return is;
}
CChevre::~CChevre()
{
}

CChien.h
#pragma once
#include "Cmammifre.h"
class CChien :
public Cmammifre
{
int m_typec;
public:

};

CChien();
CChien(int, int, int, int);
CChien(const CChien & C);
char * TYPE();
~CChien();
friend ostream & operator<<(ostream& os, CChien &);
friend istream & operator>>(istream & is, CChien &);

CChien.cpp
#include "Chien.h"
CChien::CChien() : Cmammifre()
{
m_typec = 0;
}
CChien::CChien(int poids, int age, int typem, int typec) : Cmammifre(poids,age,typem)
{
m_typec = typec;
}
CChien::CChien(const CChien &C) : Cmammifre(Cmammifre(C))
{
m_typec = C.m_typec;
}
ostream & operator<<(ostream & os, CChien &C)
{
Cmammifre *M2 = &C;

endl;

os << *M2;
cout << " Le type de chien est : Si 1 = husky, si 2 = chiwawa, si 3 = bouledogue : " <<
os << C.m_typec;
return os;

}
istream & operator>>(istream & is, CChien &C)
{
Cmammifre *M2 = &C;
is >> *M2;
cout << "Rentrez le type de chien (1 = husky, 2= chiwawa, 3 = bouledogue : " << endl;
is >> C.m_typec;
return is;
}
char * CChien::TYPE()
{
return "Type = Chien";
}
CChien::~CChien()
{
}

CVache.h

#pragma once
#include "Cmammifre.h"
class CVache :
public Cmammifre
{
int m_litres;
public:
CVache();
CVache(int , int , int , int);
CVache(const CVache &);
~CVache();
friend ostream & operator<<(ostream& os, CVache &);
friend istream & operator>>(istream & is, CVache &);
char* TYPE();
};

CVache.cpp
#include "Vache.h"
CVache::CVache() : Cmammifre()
{
m_litres = 0;
}
CVache::CVache(int poids, int age, int typem, int litres) : Cmammifre(poids, age, typem)
{
m_litres = litres;
}
CVache::CVache(const CVache &V) : Cmammifre(Cmammifre(V))
{
m_litres = V.m_litres;
}

CVache::~CVache()
{
}
char * CVache::TYPE()
{
return "Type = Vache";
}
ostream & operator<<(ostream & os, CVache &V)
{
Cmammifre *M1 = &V;
os << *M1;
cout << "Le nombres de litres produit par la vache chaque jour est : " << endl;
os << V.m_litres;
return os;
}
istream & operator>>(istream & is, CVache &V)
{
Cmammifre *M1 = &V;
is >> *M1;
cout << "Rentrez le nombres de litres produit par la vache chaque jour : ";
is >> V.m_litres;
return is;
}

Test.cpp
#include "Cmammifre.h"
#include "Chevre.h"
#include "Vache.h"
#include "Chien.h"
void main()
{
CVache C1;
CChevre C2;
CChien C3;
Cmammifre *P1;
Cmammifre *P2;
Cmammifre *P3;
P1 = &C1;
P2 = &C2;
P3 = &C3;
cout << (*P1).Type() << endl;
cout << (*P1).Type() << endl;
cout << (*P1).Type() << endl;
}

Vous aimerez peut-être aussi