实验六

实验内容 1
chip

#include 
using namespace std;
class Cores
{
    private:
        int m,n;
    public:
        Cores(int ,int );
        int getm(){return m;}
        int getn(){return n;}
        int addition();
};
Cores::Cores(int a,int b):m(a),n(b){}
int Cores::addition()
{
    return m+n;
}
class CoreA:public Cores
{
    public:
        CoreA(int ,int );
        int subtractoin();
};
CoreA::CoreA(int a,int b):Cores(a,b){}
int CoreA::subtractoin()
{
    return getm()-getn();
}
class CoreB:public Cores
{
    public:
        CoreB(int ,int );
        int multiplication();
};
CoreB::CoreB(int a,int b):Cores(a,b){}
int CoreB::multiplication()
{
    return getm()*getn();
}
class CoreC:public Cores
{
    public:
        CoreC(int ,int );
        int division();
};
CoreC::CoreC(int a,int b):Cores(a,b){}
int CoreC::division()
{
    return getm()/getn();
}
int main()
{
    Cores base(3,2);
    CoreA A(5,2);
    CoreB B(7,2);
    CoreC C(9,2);
    cout<

实验六_第1张图片

实验内容 2
vehicle

#include 
using namespace std;
class vehicle
{
public:
    vehicle(int ,int );
    ~vehicle();
    void run();
    void stop();
private:
    int maxspeed;
    int weight;
};
vehicle::vehicle(int a,int b):maxspeed(a),weight(b)
{
    cout<<"vehicle is being constructed...   "<

实验六_第2张图片

实验内容 3
iFraction

iFraction.h

#ifndef IFRACTION_H_INCLUDED
#define IFRACTION_H_INCLUDED
#include "Fraction.h"
class iFraction:public Fraction
{
private:
    int integer;//记录带分数系数, 同时表示带分数的正负
    unsigned int itop;//记录带分数分母
    unsigned int ibottom;//记录带分数分子
public:
    iFraction(int ,int );
    iFraction(int ,unsigned int ,unsigned int );
    void ishow();
};

#endif // IFRACTION_H_INCLUDED

iFraction.cpp

#include
#include "iFraction.h"
using namespace std;
iFraction::iFraction(int b,int c):Fraction(b,c)
{
    integer=gettop()/getbottom();
    itop=abs(gettop()-integer*getbottom());
    ibottom=getbottom();
}
iFraction::iFraction(int a,unsigned int b,unsigned int c):integer(a),itop(b),ibottom(c)
{
    int pltop=a*ibottom+itop;
    Fraction(pltop,ibottom);
}
int idigit(int p)
{
    int i=0;
    while(p!=0)
    {
        p/=10;
        i++;
    }
    return i;
}
void icouof(int m,string toc)
{
    for(int i=0;i

main

#include 
#include"Fraction.h"
#include"iFraction.h"
using namespace std;
int main()
{
    Fraction a(5,-2);
    Fraction b(-1,-2);
    Fraction f(1,2);
    Fraction c;
    Fraction g;
    g=a*b;
    g.show();
    g=a/b;
    g.show();
    c=a-b;
    compare(a,b);
    compare(b,f);
    c.show();
    c.trshow();
    double m;
    m=c.tranf_d();
    cout<>m>>n;
        Fraction a(m,n);
        cout<<"the fraction you set is "<>m>>n;
        Fraction b(m,n);
        cout<<"the fraction you set is "<>m>>n>>p;
        iFraction asd(m,n,p);
        cout<<"the fraction you set is "<

实验六_第3张图片

实验六_第4张图片

你可能感兴趣的:(实验六)