/* * Design and implement an ADT that represents a triangle. * The data for the
ID: 3674989 • Letter: #
Question
/* * Design and implement an ADT that represents a triangle. * The data for the ADT should include the three sides of the triangle but could also include the triangle’s three angles. * This data should be in the private section of the class that implements the ADT. * Include at least two initialization operations: one that provides default values for the ADT’s data, and another that sets this data to client-supplied values. * These operations are the class’s constructors. * The ADT also should include operations that look at the values of the ADT’s data; * - change the values of the ADT’s data; * - compute the triangle’s area; * - and determine whether the triangle is a right triangle, an equilateral triangle, or an isosceles triangle.
* The class should support the following types via templates: * int * Float * Double
Explanation / Answer
using shapetype=char *;
class traingle
{
protected:
double x1, y1; /* coordinates of the corners */
double x2, y2;
double x3, y3;
public:
shapetype type1; /* type of shape (T_TRIANGLE) */
float area;
triangle( float x1,float y1,float x2,float y2, float x3, float y3)
{
triangle.getshape([x1,x2,x3],[y1,y2,y3]);}//constructor
~triangle(),//destructor
}
void triangle::getshape (int *a, int *b)
{
int *l;
shapetype type1;'
shapetype type2;
for (int i=1,i=3,i++)
{
(i!=3)?(l[i]= (a[i+1]-a[i])^2+(b[i+1]-b[i])^2)||(l[i]=(a[1]-a[3])^2 +(b[1]-b[3])^2);
}
if ((l[1]==l[2])||(l[1]==l[3])
{
(l[2]=l[3])? type1=="Equilateral"|| type1="Isosceles";
}
else if (l[2]=l[3])
{
type1= "Isosceles"
}
(2*max(l)>sum(l))?type2="obtuse angled"||
(2*max(l)=sum(l)?type2="rightangled")||type2="acute angled";
type=[type1,type2]
area=
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.