zoukankan      html  css  js  c++  java
  • 实验6

    #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;
    }
    

  • 相关阅读:
    ASP.NET上传文件的三种基本方法
    实例分析 equals 和 ==
    如何保证Web Service的安全
    Winform动态显示图片,数据流方式
    C# 文件保存到数据库中或者从数据库中读取文件
    简说Session
    NotifyIcon的简单使用
    c# Invoke和BeginInvoke 区别
    DataGridView 的 CurrentCellDirtyStateChanged事件用法
    十种发送邮件的方式
  • 原文地址:https://www.cnblogs.com/-Alone/p/9136078.html
Copyright © 2011-2022 走看看