Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application for a right triangle class with separate files for specifi

ID: 3750934 • Letter: C

Question

Create an application for a right triangle class with separate files for specification, implementation, and client code. UML Diagram for Header (RightTriangle.h) RightTriangle - opposite : double - adjacent : double + RightTriangle( ) : + RightTriangle( double, double ) : + setOpposite( double ) : bool + setAdjacent( double ) : bool + getOpposite( ) : double + getAdjacent( ) : double + calcHypotenuse( ) : double

Default Constructor: Initialize the private member variables with a value of 1.0. Overloaded Constructor: This function should have two parameters variables for adjacent and opposite. Call the mutator functions and pass the parameter variables as arguments. Mutator functions: Each mutator function should have a Boolean flag to indicate if the parameter variable is valid. If the parameter variable is 1 or greater, then assign this value to the private member variable; otherwise, assign 1.0 to the private member variable and return false. Accessor functions: Return the value stored in the private member variables. Calculating the hypotenuse:

Client Code Instructions (Source.cpp): Define two helper functions, one for input and one for output. In the main function, demonstrate the use of the right triangle class using an array of size three. Use for loops to call getInput and displayInfo functions. void getInput( RightTriangle & ): This function should accept a RightTriangle object passed by reference. Ask the user for the values of adjacent and opposite, and pass these values as arguments to the parameter variable’s mutator functions. If the value provided by the user is invalid, then prompt the user to re-enter the value. Hint: You may use do while loops to achieve this. void displayInfo( RightTriangle & ): This function should accept a RightTriangle object passed by reference. Display the values for adjacent, opposite, and hypotenuse.

..oo AT&T 10:00 AM 100% Exam: Right-Triangle Ca… - 1 of 2 Create an application for a right triangle class with separate files for client code implementation, UML Diagram for Header (RightTriangle.h) RightTriangle opposite : double adjacent double + Right Triangle) +RightTriangle double, double): + setOpposite( double ): bool +setAdjacent double): hool getOpposite): double getAdjacent): double +calcHypotenuse) : double Implementation Code Instructions (RightTriangle.epp): Default Constructor: Initialize the private member variables with a value of 1.0. This function should have two parameters variables for adjacent and opposite. Call the mutator functions and pass the parameter variables as arguments. Mutator functions Each mutator function should have a Boolcan flag to indicate if the parameter variable is valid. If the parameter variable is or greater, then assign this value to the private memher variable; otherwise, assign 1.0 to the private member variable and return false Accessor functions: Return the value stored in the private member variables Calculating the hypotenuse: hypotenuseAdjacent Opposite2 Exam 1

Explanation / Answer

RightTriangle.h file

#ifndef RightTriangle_h_INCLUDED
#define RightTriangle_h_INCLUDED

#include<math.h>
class RightTriangle {
private:
double opposite;
double adjacent;
public:
RightTriangle();
RightTriangle(double, double);
bool setOpposite(double);
bool setAdjacent(double);
double getOpposite();
double getAdjacent();
double calcHypotenuse();
};

#endif


RightTriangle.cpp file

#include "RightTriangle.h"
RightTriangle::RightTriangle() {
setOpposite(1);
setAdjacent(1);
}

RightTriangle::RightTriangle(double adj, double opp) {
setAdjacent(adj);
setOpposite(opp);
}

bool
RightTriangle::setOpposite(double opp) {
if(opp>=1) {
    opposite = opp;
    return true;
}
else {
    opposite = 1;
    return false;
}
}

bool
RightTriangle::setAdjacent(double adj) {
if(adj>=1) {
    adjacent = adj;
    return true;
}
else {
    adjacent = 1;
    return false;
}
}

double
RightTriangle::getOpposite() {
return opposite;
}

double
RightTriangle::getAdjacent() {
return adjacent;
}

double
RightTriangle::calcHypotenuse() {
double a = getAdjacent();
double o = getOpposite();
return pow(a*a+o*o, 0.5);
}

Source.cpp file

#include "RightTriangle.h"
#include<iostream>
//using namespace std;

void getInput(RightTriangle & rt) {
double flag = false;
do {
    std::cout<<"Enter adjacent and opposite values ";
    double a, o;
    std::cin>>a>>o;
    flag = false;
    if(!rt.setAdjacent(a) || !rt.setOpposite(o)) flag = true;
}while(flag);
}

void displayInfo(RightTriangle & rt) {
std::cout<<"Adjacent : "<<rt.getAdjacent()<<" ";
std::cout<<"Opposite : "<<rt.getOpposite()<<" ";
std::cout<<"Hypotenuse : "<<rt.calcHypotenuse()<<" ";
}

int main() {
RightTriangle x;
getInput(x);
displayInfo(x);
return 0;
}

Compile using "g++ RightTriangle.cpp Source.cpp -o out" without quotes

Then run ./out to run the program.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote