#include <iostream>
using namespace std;
//定义Voltage类
//定义Current类
//定义两个函数名重载的computePoweer()函数
/*Voltage和Current类应:①.包含一个私有的float类型的数据成员用于保存电压或电流值;
②.提供一个合适的构造函数用于初始化对象;③.提供公有的value()函数用于访问私有的电压或电流值。
裁判测试程序样例:*/
class Voltage{
public:
Voltage(float v0=0):v(v0){}
~Voltage(){}
float value(){
return v;
}
private:
float v;
};
class Current{
public:
Current(float i0=0):i(i0){}
~Current(){}
float value(){
return i;
}
private:
float i;
};
float computePower(Voltage a,Current b){
return a.value()*b.value();
}
float computePower(Current a,float b){
return a.value()*a.value()*b;
}
int main() {
cout << "P = UI = 3*2 = "
<< computePower(Voltage(3),Current(2)) << endl;
cout << "P = IIR = 2*2*1.5 = "
<< computePower(Current(2),1.5) << endl;
return 0;
}