实验六

#include<iostream>
using namespace std;
 
class Base1{
    public:
        Base1(int a,int b)
        {
            cout<<a+b<<endl;
        }
};
     
class A:public Base1{
    public:
        A(int c,int d):Base1(c,d)
        {
            cout<<c-d<<endl;
        }
};
     
class B:public Base1{
    public:
        B(int e,int f):Base1(e,f)
        {
            cout<<e*f<<endl;
        }
};
     
class C:public Base1{
    public:
        C(int g,int h):Base1(g,h)
        {
            cout<<g/h<<endl;
        }
};
 
int main()
{
    int x,y;
    cin>>x>>y;
    A(x,y);
    B(x,y);
    C(x,y);
    return 0;
}

#include<iostream>
using namespace std;
class vehicle{
    private:
        int maxspeed, weight;
    public:
        vehicle(int m,int w):maxspeed(m),weight(w){
        cout<<maxspeed<<endl;
        cout<<weight<<endl;
        };
        void run()
        {
            cout<<"run"<<endl;
        }
        void stop()
        {
            cout<<"stop"<<endl;
        }
};
class bicycle:virtual public vehicle{
public:
    bicycle(int m,int w,int h):vehicle(m,w),height(h){
    cout<<height<<endl;
    }
    ~bicycle(){}
private:
    int height;
};
class motorcar:virtual public vehicle{
    public:
        motorcar(int m,int w,int s):vehicle(m,w),seatnum(s){
        cout<<"seatnum"<<endl;
        }
        ~motorcar(){}
    private:
        int seatnum;
};
class motorcycle: public bicycle,public motorcar{
    public:
        motorcycle(int m,int w,int h,int s):vehicle(m,w),bicycle(m,w,h),motorcar(m,w,s){}
        ~motorcycle(){}
};
int main()
{
    int h,s,m,w;
    motorcycle a(10,20,30,40);
    a.run();
    a.stop();
    return 0;
}

class Fraction {
public:
    Fraction();           
    Fraction(int x, int y);
    Fraction(int x);      
    void show();          
    void add(Fraction f1);
    void sub(Fraction f1);
    void mul(Fraction f1);
    void div(Fraction f1);
    Fraction operator+(const Fraction &f1)const;//分数相加
    Fraction operator-(const Fraction &f1)const;//分数相减
    Fraction operator*(const Fraction &f1)const;//分数相乘
    Fraction operator/(const Fraction &f1)const;//分数相除
    void compare(Fraction f1, Fraction f2);
private:
    int top; int bottom;  
};
 
 
#include <iostream>
#include"Fraction.h"
#include"iFraction.h"
using namespace std;
int main() {
Fraction a;
    Fraction b(3,4);
    Fraction c(5);
    Fraction d;
    d=b+c;
    d.output();
    d=b-c;
    d.output();
    d=b*c;
    d.output();
    d=b/c;
    d.output();    
    d.compare(b,c);     
    iFraction u(5,3);
    u.convertF();           
    return 0; 
}

不是很会

 

转载于:https://www.cnblogs.com/szb3115/p/9152362.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值