#include <iostream> |
int readDividend(){ |
1)
Legal input values:Enter the dividend: 5 2) Trying to use a string as dividend: Enter the dividend: xxx |
3)
Trying to use a string as
divisor:Enter the dividend: 55 4) Trying to use 0 as divisor: Enter the dividend: 555 |
TriangleException
for exceptions that should be thrown in case the sides do not make a
triangle (if the sum of any of the two sides is not greater than the
third side). This exception class has to inherit the logic_error
exception class in <stdexcept>
and should include
member variables for all of the side values (and get-functions) . The
the inherited function what()
should return a text that
indicates that the triangle properties are violated (use the
constructor of the parent class to set the text that what() returns.NonPositiveSideException
for exceptions that
should be thrown in case a side is a non-positive value. This
exceptions class has to inherited the invalid_argument
exception class in <stdexcept>
and should include a
member variable for the erronous value (and a get-function). The
message
returned from the what() function can e.g. be "Invalid side" (use the
constructor of the parent class to set the text that what() returns.#include <iostream>
#include <cmath>
#include <stdexcept>
using namespace std;
class Triangle{
private:
double side1;
double side2;
double side3;
public:
Triangle(){side1 = side2 = side3 = 1;};
Triangle(double, double, double);
void setSide1(double);
void setSide2(double);
void setSide3(double);
double getSide1(){return side1;};
double getSide2(){return side2;};
double getSide3(){return side3;};
double getPerimeter(){
return side1 + side2 + side3;
}
double getArea(){
double s = getPerimeter() / 2;
return sqrt(s * (s - side1) * (s
- side2) * (s - side3));
}
};