/* MULTI2t.CPP - oikea moniperint„ */ #include #include class cMatkustamo{ int paikkoja; public: cMatkustamo(int p=1) { printf("cMatkustamo: r\n"); paikkoja = p; } void tulosta(int n=0) { printf(" Istuinpaikkoja: %d",paikkoja); if (n) printf("\n"); } ~cMatkustamo() { printf("cMatkustamo: h\n"); } }; class cMoottori{ int tilavuus; double teho; public: cMoottori(int t=0,double hp=0) { printf("cMoottori: r\n"); tilavuus=t; teho=hp; } void tulosta(int n=0) { printf(" Moottori: %d cm2 %lg hv",tilavuus,teho); if (n) printf("\n"); } ~cMoottori() { printf("cMoottori: h\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) { printf("cKulkuneuvo: r\n"); strcpy(nimi,s); } void tulosta(int n=0) { printf("Kulkuneuvo: %s",nimi); cMatkustamo::tulosta(0); cMoottori::tulosta(n); } ~cKulkuneuvo() { printf("cKulkuneuvo: h\n"); } }; int main(void) { cKulkuneuvo mopo("Mopo",1,50,1.5); mopo.tulosta(1); return 0; }