1 //main.cpp#include"rect.h"#include<iostream>using namespace std;rect::rect(double x,double y){ height = x; longs = y; cout<<"rect"<<endl; }rect::~rect(){ cout<<"~rect"<<endl;} double rect::calc(){ cout<<"rect->calc()"<<endl; return height*longs;}2 //shape.h#ifndef SHAPE_H#define SHAPE_Hclass shape{ public: shape(); ~shape(); virtual double calc(); };#endif3//shape.cpp#include"shape.h"#include<iostream>using namespace std;shape::shape(){ cout<<"shape"<<endl;}shape::~shape(){ cout<<"~shape"<<endl;} double shape::calc(){ cout<<"shape->calc()"<<endl; } 4//circle.h#ifndef CIRCLE_H#define CIRCLE_H#include"shape.h"class circle:public shape{ public: circle(double r); ~circle(); double calc(); protected: double m_dR; }; #endif5//circle.cpp#include"circle.h"#include<iostream>using namespace std;double circle::calc(){ cout<<"circle->calc()"<<endl; return 3.14*m_dR*m_dR;}circle::circle(double r){ m_dR = r; cout<<"circle"<<endl;}circle::~circle(){ cout<<"~circle"<<endl;}6/rect.h#ifndef RECT_H#define RECT_H#include"shape.h"class rect:public shape{ public: rect(double x,double y); ~rect(); double calc(); protected: double height; double longs;}; #endif7//rect.cpp#include"rect.h"#include<iostream>using namespace std;rect::rect(double x,double y){ height = x; longs = y; cout<<"rect"<<endl; }rect::~rect(){ cout<<"~rect"<<endl;} double rect::calc(){ cout<<"rect->calc()"<<endl; return height*longs;}
添加回答
举报
0/150
提交
取消