Vous êtes sur la page 1sur 6

TP 1 Robot

#include <iostream>
#include <string>
using namespace std;
class Robot
{
private:

string m_nom;
int m_x;
int m_y;
string m_direction;

public:
Robot(string nom)
{
m_nom=nom;
m_x=0;
m_y=0;
m_direction="OUEST";
Robot(string nom, int x, int y, string direction)
{
m_nom=nom;
m_x=x;
m_y=y;
m_direction=direction;
}
void avance()
{
if (m_direction=="NORD")
{
m_y++;
}
else if (m_direction=="EST")
{
m_x++;
}
else if (m_direction=="SUD")
{
m_y--;
}
else if (m_direction=="OUEST")
{
m_x--;
}

}
void droite()
{
if (m_direction=="NORD")
{
m_direction=="EST";
}
else if (m_direction=="EST")
{
m_direction=="SUD";
}
else if (m_direction=="SUD")
{
m_direction=="OUES";
}
}
void afficher()
{
cout<<"le nom:"<<m_nom<<endl;
cout<<"la position x,y:"<<m_x<<m_y<<endl;
cout<<"la direction:"<<m_direction<<endl;

}
};
int main()
{
Robot R1("R1");
R1.avance();
R1.afficher();
Robot R2("R2",0,1,"NORD");
R2.afficher();
}

TP 2 MobilePhone (Héritage)
Class Mère (MobilePhones)
1. MobilePhones.h
#ifndef DEF_MOBILEPHONES
#define DEF_MOBILEPHONES
#include <iostream>
#include <string>

using namespace std;


class MobilePhones
{
protected:
string m_nom;
double m_prix;
public:
MobilePhones();
MobilePhones(string nom,double prix);
void afficher();
void changerprix(double prix);
};
#endif
2. MobilePhones.cpp

#include "MobilePhones.h"
using namespace std;
MobilePhones::MobilePhones()
{
m_nom="S2";
m_prix=1000;
}
MobilePhones::MobilePhones(string nom,double prix)
{
m_nom=nom;
m_prix=prix;
}
void MobilePhones::changerprix(double prix)
{
m_prix=prix;
}
void MobilePhones::afficher()
{
cout<<"le nom " <<m_nom<<endl;
cout<<"le prix " <<m_prix<<endl;
}
Class Fille (MobilePhonesSolde)
1. MobilePhonesSolde.h
#ifndef DEF_MOBILEPHONESOLDE
#define DEF_MOBILEPHONESOLDE
#include <iostream>
#include <string>
#include "MobilePhones.h" ( te3 class mére )

using namespace std;

class MobilePhonesSolde:public MobilePhone


{
private:
double m_diminution;
public:
MobilePhonesSolde();
MobilePhonesSolde(double diminution);
void changerDiminution() ;
void afficher();
};
#endif
2. MobilePhonesSolde.cpp
#include "MobilePhonesSolde.h"
using namespace std;

MobilePhonesSolde::MobilePhonesSolde():MobilePhones(),m_diminution(
0.8)
{
}
MobilePhonesSolde::MobilePhonesSolde(double
diminution):MobilePhones(),m_diminution(diminution) 

{
}
void MobilePhonesSold::changerDiminution() ;
{
double prix_n
prix_n=m_prix – m_prix * diminution;
changerprix(prix_n)
}
void MobilePhonesSold::afficher()
{
MobilePhones::afficher(); (‫ تعيط الفونكسيون من كالس مار‬، ‫)باه ماتكتبش بزاف‬
cout<<"le pourcentage " <<m_diminution<<endl;
}

Main.cpp: ‫هنا نديرو لي زوبجي‬


#include <iostream>
#include <string>
#include "MobilePhones.h"
#include "MobilePhonesSold.h"
using namespace std;
int main()
{
MobilePhones A;
MobilePhonesSold B(0.8) ;
A.afficher();
B.afficher();
return 0;
}