Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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)

  1. x(nothing)
  1. public
  1. private
  1. Triangle
  1. void
  1. double
  1. double a, b, c
  1. double a, double b, double c
  1. double a1, double b1, double c1
  1. double = 1.0, double = 1.0, double = 1.0
  1. a, b, c
  1. a1, b1, c1
  1. a + b + c
  1. a1 + b1 + c1
  1. a
  1. b
  1. c
  1. a1
  1. b1
  1. c1
  1. area
  1. perimeter
  1. set
  1. print
  1. t1.area
  1. t1.perimeter
  1. t1.set
  1. t1.print

Code to fix (Its a Class):

#ifndef TRIANGLE_H #define TRIANGLE_H #include using namespace::std;

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 using namespace::std;

#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 using namespace::std;

#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

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students explore these related Databases questions

Question

Describe several aggregation operators.

Answered: 3 weeks ago