//chip
#ifndef CHIP_H#define CHIP_H#includeusing 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#includeusing 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"#includeusing 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 ="<