博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++实验六继承生
阅读量:4967 次
发布时间:2019-06-12

本文共 4054 字,大约阅读时间需要 13 分钟。

//chip

#ifndef CHIP_H#define CHIP_H#include
using namespace std;class chip{ public: chip(int m,int n):m(m),n(n){} void add(){ cout<< m <<"+"<
<<"= "<
<
//chipA.h #include"chip.h"class chipA:public chip{    public :        chipA(int m,int n):chip(m,n){}        void subtract()        {            cout<
<<"-"<
<<"= "<
<

  chipB.h

#include"chip.h"class chipB:public chip{    public:        chipB(int m,int n):chip(m,n){}         void multiply()       {        cout<
<<"*"<
<<"= "<
<

chipC.h

#include"chip.h"class chipC:public chip{    public:        chipC(int m,int n):chip(m,n){}         void divide()       {           double a=m;           double b=n;        cout<
<<"/"<
<<"= "<< a/b<

main.cpp

#include 
#include"chip.h"#include"chipA.h"#include"chipB.h"#include"chipC.h"using namespace std;int main(){ cout<<"enter two integers"<
>m>>n; chip init(m,n); cout<<"the function of A"<

 

 

vehicle.h

#include
#ifndef VEHICLE_H#define VEHICLE_Husing namespace std;class vehicle{ public: vehicle(int w,int ms):weight(w),maxspeed(ms){ cout<<"constructing vehicle...."<

bicycle.h

#include"vehicle.h"#ifndef BICYCLE_H#define BICYCLE_Hclass bicycle:virtual public vehicle{    public:        bicycle(int w,int ms,int h):vehicle(weight,maxspeed),height(h){            cout<<"constructing bicycle..."<

motorcar.h

#include"vehicle.h"#ifndef MOTORCAR_H#define MOTORCAR_Hclass motorcar:virtual public vehicle{    public:        motorcar(int w,int ms,int sn):vehicle(weight,maxspeed),seatnum(sn){            cout<<"constructing motorcar..."<

motorcycle.h

 

#include 
#include"vehicle.h"#include"bicycle.h"#include"motorcar.h"#ifndef MOTORCYCLE_H#define MOTORCYCLE_Hclass motorcycle:public bicycle,public motorcar{ public: motorcycle(int w,int ms,int h ,int sn):vehicle(w,ms),bicycle(w,ms,h),motorcar(w,ms,sn){ cout<<"constructing motorcycle...."<

 

 

 

 

#include 
#include"vehicle.h"#include"bicycle.h"#include"motorcar.h"#include"motorcycle.h" using namespace std;int main(){ motorcycle car(100,200,1.5,5); car.run(); car.stop(); car.display(); return 0;}

 

 

Fraction.h

#ifndef FRACTION_H_INCLUDED#define FRACTION_H_INCLUDED#include
using namespace std; class Fraction{ public: Fraction(int t=0,int b=1):top(t),bottom(b){}; void output() { cout<
<<"/"<
<

iFraction.h

#ifndef IFRACTION_H_INCLUDED#define IFRACTION_H_INCLUDED#include"Fraction.h"class iFraction:public Fraction{    public:        iFraction(int t,int b):Fraction(t,b)        {            cout<<" consructing iFraction ....."<

Fraction.cpp

#include"Fraction.h"#include 
using namespace std;Fraction Fraction::operator+(const Fraction &f1) const{ return Fraction(bottom*f1.bottom,top*f1.bottom+f1.top*bottom) ;}Fraction Fraction::operator-(const Fraction &f1) const{ return Fraction(bottom*f1.bottom,top*f1.bottom-f1.top*bottom) ;} Fraction Fraction::operator*(const Fraction &f1) const{ return Fraction(bottom*f1.bottom,top*f1.top) ;} Fraction Fraction::operator/(const Fraction &f1) const{ return Fraction(bottom*f1.top,top*f1.bottom) ;}void Fraction::compare (const Fraction &f1){ double x; double y; x=double(top) /double (bottom) ; y=double (f1.top)/double (f1.bottom); if(x>y) cout<
<<"/"<
<<">"<
<<"/"<

main

#include 
#include"iFraction.h"#include"Fraction.h"using namespace std;int main(){ int t,y; cin>>t>>y; Fraction a; Fraction b(3,4); Fraction c(5); Fraction d; Fraction f1,f2,f3,f4; cout<<"input a fraction named d ="<

 

转载于:https://www.cnblogs.com/rohahaablog/p/9125687.html

你可能感兴趣的文章
linux 下 apache启动、停止、重启命令
查看>>
jsidk 上传图片转移到另一个项目遇到的问题
查看>>
学习进度2
查看>>
onbeforeunload与onunload事件
查看>>
通过jenkins自动部署war包到tomcat时遇到的一些问题
查看>>
LeetCode 47. Permutations II
查看>>
Win7承载网络配置——让你的手机无线上网吧
查看>>
随笔?
查看>>
文件上传功能
查看>>
字典示例
查看>>
数据库基本知识(六)-查询
查看>>
Windows server 2012清除并重建SID
查看>>
数据结构-编程实现一个双向链表节点的删除
查看>>
【Leetcode】169. Majority Element
查看>>
tomcat集群实例重复执行
查看>>
电源设计注意事项
查看>>
Latex 3: 解决LaTeX编译卡顿问题
查看>>
DLL劫持注入
查看>>
那些年我们一起清除过的浮动
查看>>
简单的forms验证
查看>>