Advertisement
amine99

Untitled

Sep 2nd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Vehicule {
  5.     protected: //protected bech tnjm taccedi lel les methode mta3 l classe mere fil classe fille sinon te5dem bel get w set ama haka ashel
  6.         int annee_achat;
  7.         double prix_courant, prix_achat;
  8.     public:
  9.         void afficher() {
  10.             cout << annee_achat << " " << prix_achat << " " << prix_courant << " ";
  11.         }
  12.         void calculePrix() {
  13.             prix_courant = (1 - ((2015 - annee_achat) * 0.01)) * prix_achat;
  14.         }
  15.         Vehicule(int annee_achat, double prix_achat) {
  16.             this->annee_achat = annee_achat;
  17.             this->prix_achat = prix_achat;
  18.             this->prix_courant = prix_courant;
  19.         }
  20.         ~Vehicule() {};
  21. };
  22.  
  23. class Camion : public Vehicule {
  24.     private:
  25.         int volume;
  26.     public:
  27.         void afficher() {
  28.             cout << "Camion : ";
  29.             Vehicule::afficher();
  30.             cout << volume << endl;
  31.         }
  32.         void calculePrix() {
  33.             prix_courant = (1 - (0.1 * volume / 1000)) * prix_achat;
  34.         }
  35.         Camion(int annee_achat, double prix_achat, int volume): Vehicule(annee_achat, prix_achat) {
  36.             this->volume = volume;
  37.         }
  38.         ~Camion() {};
  39. };
  40.  
  41. class Voiture : public Vehicule {
  42.     private:
  43.         int nombre_porte;
  44.         double puissance, kilometrage;
  45.     public:
  46.         void afficher() {
  47.             cout << "Voitrue : ";
  48.             Vehicule::afficher();
  49.             cout << nombre_porte << endl;
  50.         }
  51.         double calculePrix() {
  52.             prix_courant = (1 - ((2015 - annee_achat) * 0.01) + 0.05 * kilometrage / 100000) * prix_achat;
  53.         }
  54.         Voiture(int annee_achat, double prix_achat, int nombre_porte, double puissance, double kilometrage): Vehicule(annee_achat, prix_achat) {
  55.             this->nombre_porte = nombre_porte;
  56.             this->puissance = puissance;
  57.             this->kilometrage = kilometrage;
  58.         }
  59.         ~Voiture() {};
  60. };
  61.  
  62. int main() {
  63.     Vehicule* v = new Vehicule(2015,1500);
  64.     Voiture v1(2016,950,4,4,100), v2(2017,50,2,2,500);
  65.     Camion c1(2015,100,100), c2(2016,50,50);
  66.     v->calculePrix();
  67.     v1.calculePrix();
  68.     v2.calculePrix();
  69.     c1.calculePrix();
  70.     c2.calculePrix();
  71.     v->afficher();
  72.     cout << endl;
  73.     v1.afficher();
  74.     v2.afficher();
  75.     c1.afficher();
  76.     c2.afficher();
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement