C++, calculator class is an abstract class

CSDN Q & A 2022-06-24 10:03:34 阅读数:19

c++calculatorclassabstractclass

requirement :
(1) It is known that Calculator Class is an abstract class , Contains two protected Of double Type variable x And y;
(2)Add Class and Mul Class from Calculator Class public derivation , Separate use result() Function to add and multiply ;
According to the running results and main Function to complete the program .
Please note that No 2 The output form when the operands are negative .
example 1( Only the first one 1 Behavior input ):
2.2 3.33
2.2+3.33=5.53
3.33*2.2=7.326

example 2( Only the first one 1 Behavior input ):
-2.2 -3.3
-2.2-3.3=-5.5
-3.3*(-2.2)=7.26

Please note that ,main() function ( Or function call ) Must be written as follows :
int main()
{
Calculator *pc;
double x,y;
cin>>x>>y;
Add a1(x,y);
Mul m1(x,y);
pc=&a1;
pc->result();
pc=&m1;
pc->result();
return 0;
}

版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/175/202206171559429021.html