Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
collection Hetero
//Title of this code //g++ 4.9.2 #include<string> #include <iostream> #include<vector> using namespace std; class vehicule { protected: int prix; int vitesse ; string modele; string constructeur ; public: vehicule(int,int,string,string); virtual ~vehicule(){}; virtual void print(); friend ostream& operator<<(ostream&,const vehicule&); }; vehicule::vehicule(int p,int v,string c,string m){prix=p; vitesse=v;constructeur=c; modele=m;} ostream& operator<<(ostream& out,const vehicule& veh) { out <<" Le type du vehicule est inderterminé et possede les caracteristiques suivantes: \n"<<"Constructeur: "<<veh.constructeur<<endl <<"Modele: "<<veh.modele<<endl<<"Vitesse: "<<veh.vitesse<<"Km/h"<<endl<<"Prix: "<<veh.prix<<"$"<<endl; return out ; } void vehicule::print() { cout<<*this; } class voiture:public vehicule{ public: voiture(int,int,string,string); void print(); }; voiture::voiture(int p,int v,string c,string m): vehicule(p,v,c,m){ } void voiture::print(){ cout <<"Les informations sur la voiture sont: \n"<<"Constructeur: "<<this->constructeur<<endl <<"Modele: "<<this->modele<<endl<<"Vitesse: "<<this->vitesse<<"Km/h"<<endl<<"Prix: "<<this->prix<<"$"<<endl; } class moto: public vehicule{ public: moto(int,int,string,string); void print(); }; moto::moto(int p,int v,string c,string m): vehicule(p,v,c,m){ } void moto::print(){ cout <<"Les informations sur la moto sont: \n"<<"Constructeur: "<<this->constructeur<<endl <<"Modele: "<<this->modele<<endl<<"Vitesse: "<<this->vitesse<<"Km/h"<<endl<<"Prix: "<<this->prix<<"$"<<endl; } void show(vehicule*V){ V->print(); } int main() { vector<vehicule*>collection; voiture v1(15374,420,"Citroen","Citroen Berlingo") ; voiture v2(16425,500,"Citroen","Citroen C-zero"); voiture v3(20555,700,"Caparo","Caparo T1"); voiture v4(5000,250,"Chevrolet","Chevrolet Camaro"); moto m1(1574,420,"Honda","Honda CRF50F") ; moto m2(1642,500,"Honda","Honda CR250"); moto m3(2055,700,"Kawasaki","Kawasaki KX450F"); moto m4(500,250,"KTM","KTM SX65"); collection.push_back(&v1); collection.push_back(&v2); collection.push_back(&v3); collection.push_back(&v4); collection.push_back(&m1); collection.push_back(&m2); collection.push_back(&m3); collection.push_back(&m4); for(int i=0;i<collection.size();i++){ show(collection[i]); cout<<endl; } }
run
|
edit
|
history
|
help
0
RuntimeError
Some-stuff
combine c++ string with dynamically allocated c array of chars through overloaded add operator
CAE C++ Day 3 tests
Intersected Rectangles
c++ car racing game
VecHotel
LRUCache
New wall
HeapDoubLinArr