Im working on a program that is a rectangle class, and it has three files and runs fine but i need to implement an if-else-throw in the set function and try-catch in main to print when input is invalid.
Ive looked into if else throw and dont understand how to use it exactly in my program
Can anyone help by demonstrating how a if-else-throw/try-catch works because i can not grasp the concept of it. Thank you and and all help is greatly appreciated.
main cpp
#include <iostream>
#include "Rectangle.h"
usingnamespace std;
int main ()
{
//unit rectangle
Rectangle unitRectangle;
//rectangle initialized with length =2.0 &
//width = 5.0
Rectangle myRectangle(2.0,5.0);
cout <<"Displaying the statistics of unit rectangle :"<<endl;
unitRectangle.displayStatistics ();
cout <<endl<<"Now displaying the statistics of myRectangle :"<<endl;
myRectangle.displayStatistics ();
/* Variables to take user input */
double num1,num2;
cout <<endl;
cout <<"Enter the length and width of a rectangle followed by space:";
cin>>num1 >> num2;
myRectangle.setLength(num1);
myRectangle.setWidth (num2);
cout <<endl <<"Now displaying the statistics of the new Rectangle with ";
cout <<"Users input "<<num1<<" and "<<num2<<": "<<endl;
myRectangle.displayStatistics ();
cout <<endl;
return 0;
}