实验6

Posted zzy4546

tags:

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

芯片

clip.h
#ifndef CLIP_H
#define CLIP_H class clip { public: clip(int m0,int n0); int add() ; private: int m,n; };//基类 class clipA:public clip { public: clipA(int m0,int n0); int min() ; private: int m,n; }; class clipB:public clip//语法格式 派生类名:继承方式 基类名 公有继承:派生类成员函数只能访问基类public和protect成员;派生类对象只能访问基类的public成员; { public: clipB(int m0,int n0); int mul(); private: int m,n; }; class clipC:public clip { public: clipC(int m0,int n0); int div(); private: int m,n; };//派生类 #endif
clip.cpp
#include<iostream> #include"clip.h" clip::clip(int m0,int n0):m(m0),n(n0){ } int clip::add() { return(m+n); } clipA::clipA(int m0,int n0):clip(m0,n0){ m=m0; n=n0; } int clipA::min() { return (m-n); } clipB::clipB(int m0,int n0):clip(m0,n0){ m=m0; n=n0; } int clipB::mul() { return(m*n); } clipC::clipC(int m0,int n0):clip(m0,n0){ m=m0; n=n0; } int clipC::div() { return(m/n); }

main.cpp

#include<iostream>
#include"clip.h"
using namespace std;
int main()
{
    clipA a(7,5);
    cout<<"m+n="<<a.add()<<endl;
    cout<<"m-n="<<a.min()<<endl;
    clipB b(8,2);
    cout<<"m+n="<<b.add()<<endl;
    cout<<"m*n="<<b.mul()<<endl;
    clipC c(10,5);
    cout<<"m+n="<<c.add()<<endl;
    cout<<"m/n="<<c.div()<<endl;
    return 0;    
}

技术分享图片

vehicle.h

#ifndef VEHICLE_H
#define VEHICLE_H
class vehicle
{
    public:
           vehicle(int m,int w);
           ~vehicle();
           void run();
           void stop();
    private:
           int maxspeed,weight;
};
class bicycle:  virtual public vehicle
{
    public: bicycle(int m,int w,int h);
            ~bicycle();
    private:
            int height;
};
class motorcar:  virtual public vehicle
{
    public:
           motorcar(int m,int w,int s);
           ~motorcar();
    private:
            int seatnum;
};
class motorcycle: virtual public vehicle,virtual public bicycle,virtual public motorcar
{
    public:
           motorcycle(int m,int w,int h,int s);
           ~motorcycle();
};
#endif

vehicle.cpp

#include<iostream>
#include"vehicle.h"
using namespace std;
vehicle::vehicle(int m,int w):maxspeed(m),weight(w){
    cout<<"maxspeed:"<<maxspeed<<endl;
    cout<<"weight:"<<weight<<endl;
}
vehicle::~vehicle(){
    cout<<"the vehicle‘s desctrutor is called..."<<endl;
}
void vehicle::stop() {
    cout<<"stop"<<endl;
}
void vehicle::run(){
    cout<<"run"<<endl;
}
bicycle::bicycle(int m,int w, int h ):vehicle(m,w) ,height(h) {
    cout<<"height:"<<height<<endl;
}
bicycle::~bicycle(){
        cout<<"the bicycle‘s desctrutor is called..."<<endl;
}
motorcar:: motorcar(int m,int w,int s):vehicle(m,w),seatnum(s){
    cout<<"seatnum:"<<seatnum<<endl;
}
motorcar::~motorcar(){
        cout<<"the mototcar‘s‘ desctrutor is called..."<<endl;
}
motorcycle::motorcycle(int m,int w,int h,int s):vehicle(m,w),bicycle(m,w, h),motorcar( m , w, s){
}
motorcycle::~motorcycle(){
        cout<<"the motorcycle‘s‘ desctrutor is called..."<<endl;
}

main.cpp

#include<iostream>
#include"vehicle.h"
using namespace std;
int main()
{
    bicycle a(20,50 ,1);
    a.stop();
    motorcar b(150,50,4);
    b.run();
    motorcycle c(100,50,1,2);
    return 0;    
}

技术分享图片

fraction.h
#ifndef Fration_H
#define Fration_H class fraction { public: fraction(); fraction(int b,int t); void output(); void improve();//将分数简化 fraction operator+(fraction &b); fraction operator-(fraction &b); fraction operator*(fraction &b); fraction operator/(fraction &b); protected: int top; int bottom; }; class ifraction :public fraction { public: ifraction(int b,int t); void show(); }; int fun1(int x,int y);//求最大公约数, #endif

fraction.cpp

#include<iostream> 
#include<cmath>
#include"fraction.h"
using namespace std;
int fun1(int x,int y)
{
    if(x%y==0)
        return y ;
    else
        fun1(x,x%y);
}
fraction::fraction(){
}
fraction::fraction(int t,int b):top(t),bottom(b){
}
void fraction::improve()
{
    int m=fun1(fabs(top),fabs(bottom));
    top=top/m;
    bottom=bottom/m;
}
void fraction::output()
{
    cout<<top<<"/"<<bottom<<endl;
}
fraction fraction::operator+(fraction &b)
{
    return fraction(top*b.bottom+b.top*bottom,bottom*b.bottom);
}
fraction fraction::operator-(fraction &b)
{
    return fraction(top*b.bottom-b.top*bottom,bottom*b.bottom);
}
fraction fraction::operator*(fraction &b)
{
    return fraction(top*b.top,bottom*b.bottom);
}
fraction fraction::operator/(fraction &b)
{
    return fraction(top*b.bottom,bottom*b.top);
}
ifraction::ifraction(int t,int b):fraction(t,b){
}
void ifraction::show()
{
    cout<<top<<"/"<<bottom<<endl;
}

main.cpp

#include<iostream>
#include"fraction.h"
using namespace std;
int main()
{   fraction p1(1,2),p2(1,3),p3,p4,p5,p6;
    p3=p1+p2;
    p4=p1-p2;
    p5=p1*p2;
    p6=p1/p2;
    cout<<"p1+p2=";
    p3.output();
    cout<<"p1-p2=";
    p4.output();
    cout<<"p1*p2="; 
    p5.output();
    cout<<"p1/p2=";
    p6.output();
    ifraction p(5,15);
    p.improve();
    p.show();
    return 0;
}

技术分享图片

 




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

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

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

缓冲区溢出漏洞实验 20199321

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

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

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