试验6

Posted feiming

tags:

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

1.

J.h

#include<iostream>
using namespace std;
class J{
public:
J(int a,int b){
m=a;
n=b;
}
int plus(){
return m+n ;
}
int getm(){
return m;
}
int getn(){
return n;
}
private:
int m;
int n;

};
class C:public J{
public:
C(int a,int b):J(a,b){
}
int div(){
return getm()/getn();
}



};


class A:public J{
public:
A(int a,int b):J(a,b){
}
int min(){
return getm()-getn();
}

};

class B:public J{
public:
B(int a,int b):J(a,b){
}
int mul(){
return getm()*getn();
}

};

 main.cpp

#include <iostream>
#include"J.h"
using namespace std;
int main() {
C c1(6,3);
A a1(6,3);
B b1(6,3);
cout<<c1.plus()<<endl;
cout<<c1.div()<<endl;
cout<<a1.plus()<<endl;
cout<<a1.min()<<endl;
cout<<b1.plus()<<endl;
cout<<b1.mul()<<endl;
return 0;
}

技术分享图片

2.

vehicle.h

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

};
class motorcar:virtual public vehicle{
public:
motorcar(int a,int b,int d):vehicle(a,b),seatnum(d){
}
private:
int seatnum;
};
class motorcycle:public bicycle,public motorcar{
public:
motorcycle(int q,int w,int e,int r,int t,int y):vehicle(q,w),bicycle(q,w,e),motorcar(q,w,y){
}
};

main.cpp

#include<iostream>
#include"vehicle.h"
using namespace std;
int main() {
motorcycle A(1,2,3,4,5,6);
A.motorcar::run();
A.motorcar::stop();
A.bicycle::run();
A.bicycle::stop();
return 0;
}

技术分享图片

3.

Fraction.h

#include<iostream>
using namespace std;
class Fraction{
public:
Fraction(int,int);
void output();
Fraction operator+(Fraction);
Fraction operator-(Fraction);
Fraction operator*(Fraction);
Fraction operator/(Fraction);
int gettop();
int getbottom();
private:
int top;
int bottom;
};
class iFraction:public Fraction{
public:
iFraction(int x,int y);
void disply(){
cout<<top<<"/"<<bottom;
}
private:
int top;
int bottom;
};

Fraction.cpp

#include<iostream>
#include"Fraction.h"
using namespace std;
Fraction::Fraction(int t,int b):top(t),bottom(b){
}
Fraction Fraction::operator+(Fraction x)
{
return Fraction(top*x.bottom+x.top*bottom,bottom*x.bottom);
}
Fraction Fraction::operator-(Fraction x)
{
return Fraction(top*x.bottom-x.top*bottom,bottom*x.bottom);
}
Fraction Fraction::operator*(Fraction x)
{
return Fraction(top*x.top,bottom*x.bottom);
}
Fraction Fraction::operator/(Fraction x)
{
return Fraction(top*x.bottom,bottom*x.top);
}
int Fraction::gettop()
{
return top;
}
int Fraction::getbottom()
{
return bottom;
}
void Fraction::output()
{
cout<<top<<‘/‘<<bottom<<endl;
}
iFraction::iFraction(int x,int y):top(x),bottom(y),Fraction(x,y){
}

main.cpp

#include<iostream>
#include"Fraction.h"
using namespace std;
int main() {
Fraction a(1,2),c(2,4);
Fraction d=a+c;
Fraction e=a*c;
Fraction f=a-c;
Fraction g=a/c;
d.output();
e.output();
f.output();
g.output();
iFraction b(2,4);
b.disply();
return 0;
}

技术分享图片

实验总结与体会

感觉多文件结构我搞得不是特别清楚,我有些程序不用多文件可以运行,用了反而不能运行。






















































































































































































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

DL/T 5210.6-2019 电力建设施工质量验收规程 第6部分:调整试验

DL/T 5210.6-2019 电力建设施工质量验收规程 第6部分:调整试验

java 实验6 图形用户界面设计试验

黑盒测试用例设计-正交试验方法

试验检测师道路工程哪个网校老师讲的比较好?

CE的LVD指令,EMC指令都测试些什么