实验6

Posted artistqun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验6相关的知识,希望对你有一定的参考价值。

1

#include<iostream>
using namespace std;
class chip{
    protected:
        int m;
        int n;
        double result;
    public:
        chip(int a,int b,int c=0):m(a),n(b),result(c){}
        void addition(){
            cout<<m<<"+"<<n<<"=";
            result=m+n;
            cout<<result<<endl;
        }
};
class chipA:public chip{
    public:
        chipA(int a,int b,int c=0):chip(a,b,c){}
        void subraction(){
            cout<<m<<"-"<<n<<"=";
            result=m-n;
            cout<<result<<endl;
        }
};
class chipB:public chip{
    public:
        chipB(int a,int b,int c=0):chip(a,b,c){}
        void mutilp(){
            cout<<m<<"*"<<n<<"="; 
            result=m*n;
            cout<<result<<endl; 
        }

};
class chipC:public chip{
    public:
        chipC(int a,int b,int c=0):chip(a,b,c){}
        void division(){
            cout<<m<<"/"<<n<<"=";
            result=(double)m/(double)n;
            cout<<result<<endl;
        }

};
int main(){
    chipA chip1(1,2);
    chip1.addition();
    chip1.subraction();
    chipB chip2(3,4);
    chip2.mutilp();
    chipC chip3(5,6);
    chip3.division();
    return 0; 
    
}

技术分享图片

2

#include<iostream>
using namespace std;
class vehicle{
    protected:
        int maxspeed;
        int weight;
    public:
        vehicle(int a,int b):maxspeed(a),weight(b){ }
        void run(){
            cout<<"run"<<endl;
        }
        void stop(){
            cout<<"stop"<<endl;
        }
        ~vehicle(){}
};
class bicycle:virtual public vehicle{
    protected:
        int height;
    public:
        bicycle(int a,int b,int c):vehicle(a,b),height(c){}
        void run(){
            cout<<"run"<<endl<<"height:"<<height<<endl;
        }
        void stop(){
            cout<<"stop"<<endl;
        ~bicycle(){}
};
class motorcar:virtual public vehicle{
    protected:
        int seatnum;
    public:
        motorcar(int a,int b,int c):vehicle(a,b),seatnum(c){}
        void run(){
            cout<<"run"<<endl<<"seatnum:"<<seatnum<<endl;
        }
        void stop(){
            cout<<"stop"<<endl;
        ~motorcar(){}
}; 
class motorcycle:public bicycle,public motorcar{
    public:
        motorcycle(int a,int b,int c,int d):vehicle(a,b),bicycle(a,b,c),motorcar(a,b,d){}
        void run(){
            cout<<"run"<<endl;
            cout<<"maxspeed:"<<maxspeed<<endl;
            cout<<"height:"<<height<<endl;
            cout<<"seatnum:"<<seatnum<<endl;
        }
        void stop(){
            cout<<"stop"<<endl;
        ~motorcycle(){}
};

int main(){
vehicle a(100,10);
a.vehicle::run();
a.vehicle::stop();
bicycle b(100,10,10);
b.bicycle::run();
b.bicycle::stop();
motorcar c(100,10,10);
c.motorcar::run();
c.motorcar::stop();
motorcycle d(100,10,10,10);
d.motorcycle::run();
d.motorcycle::stop
    return 0;
}

 运行失败。。不知道为什么

3

fraction.h

#ifndef FRACTION_H
#define FRACTION_H
class fraction
{
public:
    fraction(int a, int b);
    fraction(int a);
    fraction();
    ~fraction();
    fraction operator+(const fraction &f1);
    fraction operator-(const fraction &f1);
    fraction operator*(const fraction &f1);
    fraction operator/(const fraction &f1);
    void compare(fraction &f1);
    void input();
    void output();

protected:
    int top;
    int bottom;
};
#endif

 fraction.cpp

#include"fraction.h"
#include<iostream>
#include<cmath>
using namespace std;
Fraction Fraction::operator+(const Fraction &f1){
    return Fraction(top*f1.bottom+f1.top*bottom,f1.bottom*bottom);
}
Fraction Fraction::operator-(const Fraction &f1){
    return Fraction(top*f1.bottom-f1.top*bottom,bottom*f1.bottom);
}
Fraction Fraction::operator*(const Fraction &f1){
    return Fraction(top*f1.top,bottom*f1.bottom);  
}
Fraction Fraction::operator/(const Fraction &f1){
    return Fraction(top*f1.bottom,bottom*f1.top);
}

void Fraction::output(){
    int t,x,y;
    if(abs(top)>abs(bottom))
        t=abs(bottom);
    else
        t=abs(top);
    for(int i=1;i<t;i++){
        if(top%i==0&&bottom%i==0){
            top/=i;
            bottom/=i;
            i=1;
        }
    }
    if(bottom<0){
        top*=-1;
        bottom*=-1;
    }
    cout<<top<<"/"<<bottom<<endl; 
}

后面不会了。。

以上是关于实验6的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段6——CSS选择器

20155201 李卓雯 《网络对抗技术》实验一 逆向及Bof基础

缓冲区溢出漏洞实验 20199321

使用 React 实验性中继片段:缺少属性 '"$fragmentRefs"'

找到我的自定义代码片段 Xcode 6?

[NTUSTISC pwn LAB 6]rop&Return to plt实验