Question
Fix this code, using the list of names provided. (NOTE: NOT ALL NAMES ARE NECESARY IN THE CODE) x(nothing) public private Triangle void double double
Fix this code, using the list of names provided. (NOTE: NOT ALL NAMES ARE NECESARY IN THE CODE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
Code to fix (Its a Class):
#ifndef TRIANGLE_H #define TRIANGLE_H #include
class Triangle { private: double a; double b; double c;
public: Triangle(double = 1.0, double = 1.0, double = 1.0); void set(double a1, double b1, double c1); double area(); double perimeter(); void print();
};
#endif
#include
#include "Triangle.h"
Triangle::Triangle(double a1, double b1, double c1) { set(a1, b1, c1);
}
void Triangle::set(double a1, double b1, double c1) { if (a1 > 0.0) a = a1; else a1 = 1.0;
if (b1 > 0.0) b = b1; else b1 = 1.0;
if (c1 > 0.0) c = c1; else c1 = 1.0; }
double Triangle::area() { double s, Ar;
s = (a + b + c) / 2.0; Ar = sqrt(s * (s - a) * (s - b) * (s - c));
return Ar; }
double Triangle::perimeter() { return a+b+c;
}
void Triangle::print() {
cout << "Side 1:\t" << a << " Side 2:\t" << b << " Side 3:\t" << c;
}
#include
#include "Triangle.h"
int main(){
Triangle t1; double a1 = 5.5, b1 = 2.3, c1 = 4.2;
cout << "Area of the triangle: " << t1.area();
cout << " ";
cout << "Perimeter of the triangle: " << t1.perimeter();
cout << " ";
t1.set(a1, b1, c1);
system("pause"); return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started