Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Vehicule {
- protected: //protected bech tnjm taccedi lel les methode mta3 l classe mere fil classe fille sinon te5dem bel get w set ama haka ashel
- int annee_achat;
- double prix_courant, prix_achat;
- public:
- void afficher() {
- cout << annee_achat << " " << prix_achat << " " << prix_courant << " ";
- }
- void calculePrix() {
- prix_courant = (1 - ((2015 - annee_achat) * 0.01)) * prix_achat;
- }
- Vehicule(int annee_achat, double prix_achat) {
- this->annee_achat = annee_achat;
- this->prix_achat = prix_achat;
- this->prix_courant = prix_courant;
- }
- ~Vehicule() {};
- };
- class Camion : public Vehicule {
- private:
- int volume;
- public:
- void afficher() {
- cout << "Camion : ";
- Vehicule::afficher();
- cout << volume << endl;
- }
- void calculePrix() {
- prix_courant = (1 - (0.1 * volume / 1000)) * prix_achat;
- }
- Camion(int annee_achat, double prix_achat, int volume): Vehicule(annee_achat, prix_achat) {
- this->volume = volume;
- }
- ~Camion() {};
- };
- class Voiture : public Vehicule {
- private:
- int nombre_porte;
- double puissance, kilometrage;
- public:
- void afficher() {
- cout << "Voitrue : ";
- Vehicule::afficher();
- cout << nombre_porte << endl;
- }
- double calculePrix() {
- prix_courant = (1 - ((2015 - annee_achat) * 0.01) + 0.05 * kilometrage / 100000) * prix_achat;
- }
- Voiture(int annee_achat, double prix_achat, int nombre_porte, double puissance, double kilometrage): Vehicule(annee_achat, prix_achat) {
- this->nombre_porte = nombre_porte;
- this->puissance = puissance;
- this->kilometrage = kilometrage;
- }
- ~Voiture() {};
- };
- int main() {
- Vehicule* v = new Vehicule(2015,1500);
- Voiture v1(2016,950,4,4,100), v2(2017,50,2,2,500);
- Camion c1(2015,100,100), c2(2016,50,50);
- v->calculePrix();
- v1.calculePrix();
- v2.calculePrix();
- c1.calculePrix();
- c2.calculePrix();
- v->afficher();
- cout << endl;
- v1.afficher();
- v2.afficher();
- c1.afficher();
- c2.afficher();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement