Describe in detail any problems you see in the following code.
void funcOne() {
Dog *ptr = new Dog;
cout << “Presenting the result of a division: “ << funcDivide();
delete ptr;
}
int funcDivide() {
int a, b;
cin >> a >> b;
if (b == 0)
throw “Divide by Zero”;
return a / b;
}
this program contain so many error
Ist error :- here we create the object of class Dog but there is no Dog class .
2nd error :- there is no main class so from where we calling the funcOnne() method
3 error :- suppose the user enter the value of b is 0
than an exception will throw with the message Divide by zero but where we handling the exception .
so i think fundivide should call in try method and associated with catch block
also the obj of class is creating inside the main method but here we have created inside the userdefined method which is wrong
Get Answers For Free
Most questions answered within 1 hours.