Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExceptionHandling2
//g++ 7.4.0 /////////////////////////////////////////////////////////////////////////////////ExceptionHandling2: C++ exception handling //this code is created by Rezaul Hoque on June 09,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> class CalCul{ int x,y; public: CalCul(int p,int q){x=p;y=q;} ~CalCul(){} int getX (){return x;} int getY(){return y;} void add(){ if(x>0 && y>0){ std::cout<<(x+y); } else {std::cout<<"Sorry, unable to finish the task!\n";} } void sub(){if (x>0 && y>0 &&x>y) std::cout<<(x-y); else { std::cout<<"Sorry, unable to finish the task!\n";} } }; class noNeg{}; class noZero{}; int main() { CalCul a(-1,0); if(a.getX()<0||a.getY()<0){ try{ throw noNeg(); } catch(noNeg n){ std::cout<<"Number can't be negative. \n"; } } if(a.getX()==0||a.getY()==0){ try { throw noZero(); } catch(noZero z){ std::cout<<"Number can't be zero. \n"; } } std::cout<<"Numbers are:\n"<<a.getX()<<"\t"<<a.getY()<<"\n"; std::cout<<"Sum: "; a.add(); std::cout<<"\n"; std::cout<<"Substraction: "; a.sub(); std::cout<<"\n"; return 0; }
run
|
edit
|
history
|
help
0
EqualIdentical
СПКИ АП КЭП 2
Tree
Make BinTree
FInd rows with maximum no of 1's
Get all anagrams from given words
PrintShape
sorting using array and pointer
ADP_campus
point to a rvalue