/* MULTI3.CPP - oikea moniperint„ */ #include #include class cMatkustamo{ int paikkoja; public: cMatkustamo(int p=1) { paikkoja = p; printf("R: cMatkustamo\n");} void tulosta(int n=0) const { printf(" Istuinpaikkoja: %d",paikkoja); if (n) printf("\n"); } ~cMatkustamo() { printf("H: cMatkustamo\n"); } }; class cMoottori{ int tilavuus; double teho; public: cMoottori(int t=0,double hp=0) { tilavuus=t; teho=hp; printf("R: cMoottori\n");} void tulosta(int n=0) const { printf(" Moottori: %d cm2 %lg hv",tilavuus,teho); if (n) printf("\n"); } ~cMoottori() { printf("H: cMoottori\n"); } }; class cKulkuneuvo:public cMoottori, public cMatkustamo { char nimi[20]; public: cKulkuneuvo(char *s="???",int p=1,int t=0, double hp=0) :cMatkustamo(p),cMoottori(t,hp) { strcpy(nimi,s); printf("R: cKulkuneuvo\n");} void tulosta(int n=0) const { printf("Kulkuneuvo: %s",nimi); cMatkustamo::tulosta(0); cMoottori::tulosta(n); } ~cKulkuneuvo() { printf("H: cKulkuneuvo\n"); } }; int main(void) { cKulkuneuvo mopo("Mopo",1,50,1.5); mopo.tulosta(1); return 0; }