码迷,mamicode.com
首页 > 其他好文 > 详细

实验6

时间:2018-06-05 19:55:53      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:out   bic   veh   技术分享   max   分享图片   namespace   技术   http   

#include<iostream>
using namespace std;
class Add{
    public:
        Add(int x,int y):x(x),y(y){
        cout<<x+y<<endl;
    }
    private:
        int x,y;
};
class A:public Add{
    public:
        A(int x,int y):Add(x,y),x(x),y(y){}
        void jian(){cout<<x-y<<endl;}
    private:
        int x,y;
};
class B:public Add{
    public:
        B(int x,int y):Add(x,y),x(x),y(y){}
        void cheng(){cout<<x*y<<endl;}
    private:
        int x,y;
};
class C:public Add{
    public:
        C(int x,int y):Add(x,y),x(x),y(y){}
        void chu(){cout<<x/y<<endl;}
    private:
        int x,y;
};
int main()
{
    A a(2,3);
    a.jian();
    B b(5,4);
    b.cheng();
    C c(4,4);
    c.chu();
    return 0;
}

技术分享图片

#include<iostream>
using namespace std;
class vehicle{
    public:
        vehicle(int x,int y):maxspeed(x),weight(y){}
        void run(){cout<<"0"<<endl;}
        void stop(){cout<<"1"<<endl;}
    private:
        int maxspeed,weight;
};
class bicycle:public vehicle{
    public:
        bicycle(int x,int y,int z):vehicle(x,y),height(z){}
        void run(){cout<<"0"<<endl;}
        void stop(){cout<<"1"<<endl;}
    private:
        int height;
};
class motorcar:public vehicle{
    public:
        motorcar(int x,int y,int h):vehicle(x,y),seatnum(h){}
        void run(){cout<<"0"<<endl;}
        void stop(){cout<<"1"<<endl;}
    private:
        int seatnum;
};
class motorcycle:public vehicle,public bicycle,public motorcar{
    public:
        motorcycle(int x,int y,int z,int h):vehicle(x,y),bicycle(x,y,z),motorcar(x,y,h){}
        void run(){cout<<"0"<<endl;}
        void stop(){cout<<"1"<<endl;}
};
int main()
{
    vehicle a(4,5);
    a.run();
    a.stop();
    bicycle b(3,3,2);
    b.run();
    b.stop();
    motorcar c(2,2,3);
    c.run();
    c.stop();
    motorcycle d(1,1,2,2);
    d.run();
    d.stop();
    return 0;
}

技术分享图片

实验6

标签:out   bic   veh   技术分享   max   分享图片   namespace   技术   http   

原文地址:https://www.cnblogs.com/-Alone/p/9136078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!