1
#includeusing namespace std;class chip{ protected: int m; int n; double result; public: chip(int a,int b,int c=0):m(a),n(b),result(c){} void addition(){ cout< <<"+"< <<"="; result=m+n; cout< <
2
#includeusing namespace std;class vehicle{ protected: int maxspeed; int weight; public: vehicle(int a,int b):maxspeed(a),weight(b){ } void run(){ cout<<"run"<
运行失败。。不知道为什么
3
fraction.h
#ifndef FRACTION_H#define FRACTION_Hclass fraction{public: fraction(int a, int b); fraction(int a); fraction(); ~fraction(); fraction operator+(const fraction &f1); fraction operator-(const fraction &f1); fraction operator*(const fraction &f1); fraction operator/(const fraction &f1); void compare(fraction &f1); void input(); void output();protected: int top; int bottom;};#endif
fraction.cpp
#include"fraction.h"#include#include using namespace std;Fraction Fraction::operator+(const Fraction &f1){ return Fraction(top*f1.bottom+f1.top*bottom,f1.bottom*bottom);}Fraction Fraction::operator-(const Fraction &f1){ return Fraction(top*f1.bottom-f1.top*bottom,bottom*f1.bottom);}Fraction Fraction::operator*(const Fraction &f1){ return Fraction(top*f1.top,bottom*f1.bottom); }Fraction Fraction::operator/(const Fraction &f1){ return Fraction(top*f1.bottom,bottom*f1.top);}void Fraction::output(){ int t,x,y; if(abs(top)>abs(bottom)) t=abs(bottom); else t=abs(top); for(int i=1;i
后面不会了。。