Design and implement a class to compute the area of a triangle using the values of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Design and implement a class to compute the area of a triangle using the values of their sides. The design of class (named Triangle) should include: 1) Three private members sidel, side2, and side3, which present sides of a triangle. 2) One private member area to preserve the computed area of triangle. 3) A default constructor (i.e., Triangle()) to initialize sides of triangle and area of triangle as zero. 4) A parameter constructor (i.e., Triangle (double, double, double)) to initialize the values of sides for corresponding triangle and initialize area of triangle as zero. 5) A set method (i.e. setSides (double, double, double)) to enter the new values for the sides. 6) A method (i.e. computeArea()) to compute the area of triangle. 7) A get method (i.e. getArea()) to display the area. Hint-1. Area of Triangle can be computed through the following Heron's Formula: Area = sqrt(s* (s-a)*(s-b)*(s-c)), where s=(a+b+c)/2. Hint-2. You need to include <cmath> library to use the sqrt() function and include <iomanip> library to use setprecision and fixed manipulators to change the precision value and printing format. According to the requirements above, write a program to: 1) Create first Triangle object (i.e., triangLe1) with default constructor and display its area. 2) Create second Triangle object (i.e., triangle2) with parameter constructor and display its area. The values of sides are 3, 4, and 5. 3) Call the set method using first Triangle object (i.e., triangle1) and display its area. Assume that all inputs are valid, i.e., new sides can form a triangle. Expected Outputs: Example 1. Area of triangle1: 0.00 Area of triangle2: 6.00 Enter new sides for triangle1: 423 Area of triangle1: 2.90 Example 2. Area of triangle1: 0.00 Area of triangle2: 6.00 Enter new sides for triangle1: 3 3 3 Area of triangle1: 3.90 Design and implement a class to compute the area of a triangle using the values of their sides. The design of class (named Triangle) should include: 1) Three private members sidel, side2, and side3, which present sides of a triangle. 2) One private member area to preserve the computed area of triangle. 3) A default constructor (i.e., Triangle()) to initialize sides of triangle and area of triangle as zero. 4) A parameter constructor (i.e., Triangle (double, double, double)) to initialize the values of sides for corresponding triangle and initialize area of triangle as zero. 5) A set method (i.e. setSides (double, double, double)) to enter the new values for the sides. 6) A method (i.e. computeArea()) to compute the area of triangle. 7) A get method (i.e. getArea()) to display the area. Hint-1. Area of Triangle can be computed through the following Heron's Formula: Area = sqrt(s* (s-a)*(s-b)*(s-c)), where s=(a+b+c)/2. Hint-2. You need to include <cmath> library to use the sqrt() function and include <iomanip> library to use setprecision and fixed manipulators to change the precision value and printing format. According to the requirements above, write a program to: 1) Create first Triangle object (i.e., triangLe1) with default constructor and display its area. 2) Create second Triangle object (i.e., triangle2) with parameter constructor and display its area. The values of sides are 3, 4, and 5. 3) Call the set method using first Triangle object (i.e., triangle1) and display its area. Assume that all inputs are valid, i.e., new sides can form a triangle. Expected Outputs: Example 1. Area of triangle1: 0.00 Area of triangle2: 6.00 Enter new sides for triangle1: 423 Area of triangle1: 2.90 Example 2. Area of triangle1: 0.00 Area of triangle2: 6.00 Enter new sides for triangle1: 3 3 3 Area of triangle1: 3.90
Expert Answer:
Answer rating: 100% (QA)
Certainly Below is the C program implementing the described Triangle class with the specified featur... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these computer network questions
-
Infer the relevance of Elasticity of Demand and Elasticity of Supply in Economy. What is the importance of elasticity? How can different degrees of elasticity have different impact? Explain with the...
-
Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule. Create the...
-
Design a class named Triangle that extends GeometricObject. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. ...
-
Data for Video Phones, Inc., are provided in P114A. Required: Prepare the statement of cash flows for Video Phones, Inc., using the direct method. Disclose any noncash transactions in an accompanying...
-
The table below is the output of polytomous (multinomial) logistic regression of clinical classification on insulin response (IR), steady-state plasma glucose (SSPG), and relative weight (RW). The...
-
Q1. Consider the following network that represents the daily volume of data (in gigabyte) that can flow between six servers of BigData Company. What is the maximum amount of data that can flow from...
-
Match the accounting term with the corresponding definition. 1. Accumulated depreciation 2. Adjusted trial balance 3. Adjusting entry 4. Book value 5. Contra- account 6. Depreciation 7. Long-term...
-
Sears sold a lawn tractor to Cosmo Fiscante for $1,481. Fiscante paid with his personal credit card. Sears kept a valid security interest in the lawnmower but did not perfect. Fiscante had the...
-
Follow the Curve Sketching Algorithm to sketch the graph of f(x)=x 5 -x.
-
Throughout the course, you will be working on a Wealth Management Analyst Project For this project, imagine you are a new hire at a wealth management firm and tasked with determining the location of...
-
Case study: Kameda Seika: Cracking the U.S. Market (1) What are some reasons rice crackers are expected to be popular outside Japan? (2) What is Kamedas marketing plan in the US? (3) What would you...
-
what ways do invasive species disrupt native ecosystems, and can you discuss the mechanisms through which they alter nutrient cycling, predator-prey relationships, and overall community structure in...
-
what extent do human-induced alterations in land use, such as urbanization and agricultural expansion, affect ecosystem services, and how can we mitigate the adverse impacts on biodiversity and...
-
A. It's Your Career It is April, and you are about to graduate with a major in advertising and a minor in PR. You have received a job offer from a technology company in Boston as an account executive...
-
The Ouchi Approach or Theory Z emphasizes employee involvement, long-term employment, and a strong sense of organizational loyalty. It aims to enhance employee satisfaction, productivity, and...
-
Table 1 Dungeons and Dragons various monster traits. The data was obtained from the 5e D&D Monster Manual (Mearls et al., 2020). Life type Vision Limbs Main Movement Magic Food Purple worm (outgroup)...
-
Amy Farrah Fowler was just elected as Finance officer of Big Bang County and has started her first day in the office. Amy is trying to deal with the following information in the year 2020:...
-
At the beginning of its fiscal year, Lakeside Inc. leased office space to LTT Corporation under a seven-year operating lease agreement. The contract calls for quarterly rent payments of $25,000 each....
-
Write a program that displays a checkerboard in which each white and black cell is a Rectangle with a fill color black or white, as shown in Figure 14.44c. (c)
-
Write the following method that sorts an ArrayList of numbers: public static void sort(ArrayList list) Write a test program that prompts the user to enter 5 numbers, stores them in an array list, and...
-
Write a program to animate search, insertion, and deletion in a doubly linked list, as shown in Figure 24.24. The Search button searches the specified value in the list. The Delete button deletes the...
-
Discuss some of the special considerations involved in the audit of investments in group entities.
-
Joplin Ltds financial year ends on 30 June 20X1 and the companys auditor, Hagan and Partners, conducts the annual audit during July and August. Hagan and Partners has prepared auditing procedures for...
-
What is a solicitors representation letter? What effect might the failure of a solicitor to respond to a request for representation have on the auditors report?
Study smarter with the SolutionInn App