Académique Documents
Professionnel Documents
Culture Documents
Introduction
Dans cette document je vous donne la correction de TP4.
La declaration des classes sont toujours dans des fichiers .h tandis que leurs implementations
sont dans des fichiers .cpp.
je nai fourni que limplementation que je trouve importantes parce que les autres sont tr`es
simples.
Exercice I
fichier personne.h
#ifndef PERSONNE H
#define PERSONNE H
using namespace std;
class CPersonne
{
public :
////// constructeurs/////////////////////////////////
CPersonne();
CPersonne(const string& nom, const string& prenom,
unsigned int age=0, const string& adresse=);
CPersonne();
///// set et get methodes//////////////////
private :
string m_nom;
string m_prenom;
unsigned int m_age;
string m_adresse;
};
#endif
fichier employe.h
#ifndef EMPLOYE H
#define EMPLOYE H
#include <string>
using namespace std;
class CEmploye
{
public :
////// constructeurs/////////////////////////////////
CEmploye();
CEmploye(const string& nom_employer, float salaire);
CEmploye();
///// set et get methodes//////////////////
fichier etudiant.h
#ifndef ETUDIANT H
#define ETUDIANT H
#include <string>
#include personne.h
using namespace std;
class CEtudiant: public CPersonne
{
public :
////// constructeurs/////////////////////////////////
CEtudiant();
CEtudiant(const string& nom, const string& prenom,
const string& numero, const string& specialite,
const string& nom_ecole,
unsigned int age=0, const string& adresse=);
CEtudiant();
///// set et get methodes//////////////////
fichier etudiant.cpp
#include <string>
#include etudiant.h
#include <iostream>
using namespace std;
CEtudiant::CEtudiant(): CPersonne()
{
}
CEtudiant::CEtudiant(const string& nom, const string& prenom,
const string& numero, const string& specialite,
const string& nom_ecole,
unsigned int age=0, const string& adresse=):
CPersonne(nom,prenom,age,adresse), m_numero(numero),
m_specialite(specialite), m_nom_ecole(nom_ecole)
{
}
void CEtudiant::afficher()
{
CPersonne::afficher();
cout << Numero : << m_numero << endl;
cout << Specialite : << m_specialite << endl;
fichier enseignant.h
#ifndef ENSEIGNANT H
#define ENSEIGNANT H
#include <string>
#include personne.h
#include employe.h
using namespace std;
class CEnseignant: public CPersonne, public CEmploye
{
public :
////// constructeurs/////////////////////////////////
CEnseignant();
CEnseignant(const string& nom, const string& prenom,
, const string& nom_employer, float salaire,
unsigned int enseigne_eannee, unsigned int age=0,
const string& adresse=);
CEnseignant();
///// set et get methodes//////////////////
fichier enseignant.cpp
#include enseignant.h
#include <iostream>
void CEnseignant::afficher()
{
CPersonne::afficher();
CEmploye::afficher();
cout << Enseigne annee : << m_enseigne_eannee << endl;
}
void CEnseignant::saisir()
{
CPersonne::saisir();
CEmploye::saisir();
cout << Enseigne annee : ;
cin >> m_enseigne_eannee;
}
Exercice II
fichier figure.h
#ifndef FIGURE H
#define FIGURE H
class CFigure
{
public :
CFigure();
CFigure(int x, int y);
int get_x();
int get_y();
void set_x(int x);
void set_y(int y);
void deplacer_vers(int x, int y);
virtual void dessienr()=0;
virtual float aire()=0;
virtual float perimetre()=0;
private :
int m_x;
int m_y;
};
#endif
fichier rectangle.h
#ifndef RECTANGLE H
#define RECTANGLE H
#include figure.h>
class CRectangle : public CFigure
{
public :
CRectangle();
CRectangle(int largeur, int hauteur);
CRectangle(int x, int y, int largeur, int hauteur);
int get_largeur();
int get_hauteur();
void set_largeur(int largeur);
void set_hauteur(int hauteur);
void dessienr();
float aire();
float perimetre();
private :
int m_largeur;
int m_hauteur;
};
#endif
fichier cercle.h
#ifndef CERCLE H
#define CERCLE H
#include figure.h
class CCercle : public CFigure
{
public :
CCercle();
CCercle(int radius);
CCercle(int x, int y, int radius);
int get_radius();
void set_radius(int radius);
void dessienr();
float aire();
float perimetre();
private :
int m_radius;
};
#endif
fichier carre.h
#ifndef CARRE H
#define CARRE H
#include rectangle.h
class CCarre : private CRectangle
{
public :
CCarre();
CCarre(int bord);
CCarre(int x, int y, int bord);
int get_bord();
void set_bord(int bord);
void dessienr();
float aire();
float perimetre();
};
#endif
fichier carre.cpp
#include caree.h
CCarre::CCarre(): CRectangle()
{
}
CCarre::CCarre(int bord): CRectangle(bord,bord)
{
}
CCarre::CCarre(int x, int y, int bord): CRectangle(x,y,bord,bord)
{
}
int CCarre::get_bord()
{
return get_largeur();
// return get hauteur();
}