<< "ê?è?a±?£o";
?????????????? cin >> a;
?????????????? s.setA(a);
?????????????? cout << "???y?a£o" << s.area() << endl;
?????????????? cout << "?ü3¤?a£o" << s.side() << endl;
?????????????? calculate();
?????????????? break;
?????? case 3:
?????????????? break;
?????? default:
?????????????? cout << "?TD§ê?è?" << endl;
?????????????? calculate();
?????????????? break;
?????? }
}
给出整体代码:
#include <iostream>
using namespace std;
/**
* 矩形
*/
class Rectangle {
protected:
int a; // a边
int b; // b边
public:
/**
* 求面积
*/
int area() {
return a * b;
}
/**
* 求边长
*/
virtual int side()=0;
};
/**
* 正方形
*/
class Square: public Rectangle {
public:
/**
* 设置边
*/
void setA(int a) {
this->a = a;
this->b = a;
}
/**
* 求边长
*/
virtual int side() {
return 4 * a;
}
};
/**
* 长方形
*/
class Oblong: public Rectangle {
public:
/**
* 设置a边
*/
void setA(int a) {
this->a = a;
}
/**
* 设置b边
*/
void setB(int b) {
this->b = b;
}
/**
* 求边长
*/
virtual int side() {
return 2 * a * b;
}
};
/**
* 计算
*/
inline void calculate() {
int chioce; // 选项
int a; // a边
int b; // b边
Oblong o; // 长方形
Square s; // 正方形
cout << endl;
cout << "选择矩形类型:" << endl;
cout << "1-长方形" << endl;
cout << "2-正方形" << endl;
cout << "3-退出" << endl;
cin >> chioce;
switch (chioce) {
case 1:
cout << "输入a边:";
cin >> a;
cout << "输入b边:";
cin >> b;
o.setA(a);
o.setB(b);
cout << "面积为:" << o.area() << endl;
cout << "周长为:" << o.side() << endl;
calculate();
break;
case 2:
cout << "输入a边:";
cin >> a;
s.setA(a);
cout << "面积为:" << s.area() << endl;
cout << "周长为:" << s.side() << endl;
calculate();
break;
case 3:
break;
default:
cout << "无效输入" << endl;
calculate();
break;
}
}
/**
|