Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in the blanks to build the Triangle Class, and then to fill in the (main) program below. Select the appropriate information from the list

Fill in the blanks to build the Triangle Class, and then to fill in the (main) program below. Select the appropriate information from the list of options provided. Take into consideration that the class that is developed meets the following description:

1) The class is called Triangle and it has 3 attributes called a, b, c. These represent the length of the 3 sides of a triangle.

2) The functions of the class (methods) are (the code must comply with these descriptions): Function A) Constructor function, which receives 3 parameters that are the initial values to be stored in an object of type Triangle when the object is created. The constructor is expected to have defaults of 1.0 defined for the parameters (default parameters).

Function B) Set function, which receives as parameters the new values to be stored in an object of type Triangle. This function verifies that the values received to store in the data members are positive, and if they are not, it stores a default of 1.0 in the corresponding data member.

Function C) Perimeter function, which calculates and returns the perimeter of a triangle (remember that the perimeter is the sum of the lengths of the 3 sides of the triangle).

Function D) Area function, which calculates and returns the area of a triangle. The formula to calculate the area of a triangle when the length of the 3 sides is known is the following (it is already written in C ++):

s = (a + b + c) / 2.0;

Ar = sqrt(s * (s-a) * (s-b) * (s-c))

Function E) Print function, which prints the sides of the triangle with the following format (assuming that the lengths of the three sides are, for the purposes of this example, 1.5, 3.3, 2.1):

Side 1: 1.5

Side 2: 3.3

Side 3: 2.1

List of options:

  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 complete:

#include

using namespace std;

#include

//Complete the Class Interface

Class _________________

__________________: // member access specifier

//Prototypes of the member functions (methods)

//Constructor Function (Function A)

_________________ _______________ ( _________________ );

//Set Function (Function B)

________________ set (________________);

//Function that calculates and returns the area (Function C)

_______________ area ( _______________ );

//Function that calculates and returns the perimeter (Function D)

______________ perimeter ( ______________ );

//Function that prints the sides of the triangle (Function E)

______________ _____________ ( _______________ );

_______________: // member access specifier

// Class data members

________________ a; // Side 1

________________ b; // Side 2

________________ c; // Side 3

};

//Developing the constructor function (Function A)

___________________ ______________::____________(_________________)

{

//Calling the Set Function

set(____________);

}

//Developing the set function (Function B)

_______________ ________________::set(___________)

{

//Verify that the data that is entered and store in in the class data member that represents side 1

if(__________ > 0.0)

____________ = ___________;

else

___________ = 1.0;

//Verify that the data that is entered and store in in the class data member that represents side 2

if(__________ > 0.0)

____________ = ___________;

else

___________ = 1.0;

//Verify that the data that is entered and store in in the class data member that represents side 3

if(__________ > 0.0)

____________ = ___________;

else

___________ = 1.0;

//Developing the function that calculates and returns the area of the triangle (Function C)

______________ _______________::area( _________________)

{

double s, Ar;

//Formula of s

s = ( ___________ ) / 2.0;

//Formula of Ar (area of a triangle)

Ar = sqrt ( s*(s- _____)*(s-_____)*(s-______));

return Ar;

}

//Developing the function that calculates and returns the perimeter of the triangle (Function D)

_______________ _____________::perimeter (______________)

{

return ____________;

}

//Developing the function that prints the longitude of the sides of the triangle (Function E)

________________ ____________:: print(_______________)

{

cout << Side 1:\t << ___________

<< Side 2:\t << ______________

<< Side 3:\t << ________________;

//Complete the main function

int main()

{

Triangle t1;

double a1 = 5.5, b1 = 2.3, c1 = 4.2;

//Complete the cout adding the calling of the function that calculates the area of the triangle for object t1 (Function C)

cout << Area of the triangle =

<< __________________ ();

//Complete the cout adding the calling of the function that calculates the perimeter of the triangle for object t1 (Function D)

cout << Perimeter of the triangle =

<< ______________();

cout << ;

//Calling the function o the class that allows you to stored the values of the variables a1, b1, c1 defined before in main in the data members of the object t1 (Function B)

_______________ ( _____________);

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

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions