Question

In: Computer Science

Computer Science Design and implement an ADT that represents a triangle. The data for the ADT...

Computer Science

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. The 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.

Code must be written in C++ thanks.

Solutions

Expert Solution

#include <iostream>
#include <cmath>
using namespace std;
class triangle{
private:
int sideA; //height
int sideB; //base
int sideC; //hypo
public:
triangle(){ //default constructor
sideA=0;
sideB=0;
sideC=0;
}
triangle(int A, int B, int C){ //parameterize
sideA=A;
sideB=B;
sideC=C;
}
//mutator
void setSideA(int A){
sideA=A;
}
void setSideB(int B){
sideB=B;
}
void setSideC(int C){
sideC=C;
}
//accessors
int getSideA(){
return sideA;
}
int getSideB(){
return sideB;
}
int getSideC(){
return sideC;
}
//get type of triangle
void getTriangleType(){
int sideAA,sideBB,sideCC;
sideAA=sideA*sideA;
sideBB=sideB*sideB;
sideCC=sideC*sideC;
if(sideA==sideB && sideB==sideC && sideC==sideA){
cout<<"Triangle is Equilateral "<<endl;
}
else if(sideA==sideB || sideB==sideC || sideC==sideA){
cout<<"Triangle is Isosceles "<<endl;
}
else if(sideAA==sideBB+sideCC || sideBB==sideCC +sideAA || sideCC== sideAA+sideBB){
cout<<"Triangle is Right Angled "<<endl;
}
else{
cout<<"Triangle is either of type "<<endl;
}

}
float getArea(){
float S;
float area;
S= (sideA+sideB+sideC)/2; //perimeter
area= sqrt(S*(S-sideA)* (S-sideB)* (S-sideC)); //area
return area;
}
};

int main()
{
triangle t1(25,25,9);
triangle t2(3,4,5);
triangle t3(2,2,2);
cout<<"Triangle T1 Area: "<<t1.getArea()<<endl;
cout<<"Triangle T2 Area: "<<t2.getArea()<<endl;
cout<<"Triangle T3 Area: "<<t3.getArea()<<endl;
cout<<endl;
t1.getTriangleType();
t2.getTriangleType();
t3.getTriangleType();
return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP


Related Solutions

In C++, Design and implement an ADT that represents a triangle. The data for the ADT...
In C++, 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...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS:...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS: Not allowed to use ANY built-in Python data structures and their methods. You must solve by importing the DynamicArray class and using class methods to write solution. Also not allowed to directly access any variables of the DynamicArray class (like self.size, self.capacity and self.data in part 1). All work must be done by only using class methods. Below is the Bag ADT starter code...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
Overview: implement the ADT List in Java. This program is meant to the ADT List from...
Overview: implement the ADT List in Java. This program is meant to the ADT List from the ground up In the lecture, we learned how to implement an ADT like the ArrayList you have used in Project 1. With this project, you have the chance to implement an ADT called MyList, which is a simplified replacement for the full-blown ArrayList. Requirements You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will...
I'm in a computer science course and I have an assignment that asks me to implement...
I'm in a computer science course and I have an assignment that asks me to implement a CPU scheduler in Java. Here are some details for the task: The program should ask for the number of processes. Then the program will ask for burst and arrival times for each process. Using that information, the program should schedule the processes using the following scheduling algorithms: First Come First Serve (FCFS) Shortest Jobs First (SJF) Shortest Remaining Time First (SRTF) The output...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
In a single design, implement 3 wave generators by means of operational amplifiers: wave square, triangle...
In a single design, implement 3 wave generators by means of operational amplifiers: wave square, triangle wave, sine wave. IMPORTANT The wave generating equipment has to be activated by means of an external AC source, that being activated by a switch, allows the activation of the system. SIMULATION is required in the MULTISIM Software. Attach screenshot of the entire circuit and the waves. and also the calculations. Prepare the calculations of each case, which support the output signal obtained by...
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
Describe different types of data structures in Computer Science with examples.
Describe different types of data structures in Computer Science with examples.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT