Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExceptExpo
//g++ 7.4.0 //////////////////////////////////////////////////////////////////////////// //ExceptExpo: exception handling while overloading exponentiation operator //this code is created by Rezaul Hoque on July 03,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <string> #include <cmath> class noNeg{}; class noZero{}; class Expo{ int x,y; public: Expo(int b,int c){ if(b==0||c==0){ try { throw noZero(); } catch(noZero z){ std::cout<<"Number can't be zero. \n"; } } if(c<0||b<0){ try { throw noNeg(); } catch(noNeg z){ std::cout<<"Number can't be negative. \n"; } } x=b; y=c; } ~Expo(){} Expo operator&&(const int&); int getId(){return x;} int getTel(){return y;} void disp(){ if(x<0||y<0) std::cout<<"Sorry, unable to process!"; else std::cout<<x<<"/"<<y; } }; Expo Expo::operator&&(const int& n){ return Expo(pow(x,n),pow(y,n)); } int main() { Expo e(-3,4); e.disp(); std::cout<<"\n"; Expo po=e&&2; po.disp(); return 0; }
run
|
edit
|
history
|
help
0
test yield
role of copy constructor
search_n algorithm
CIDP2k19
decomposition
Gauss 4x4
HelloWorldExample
Callback
HashRK
pac update