Ask Computer Engineering Expert

1. Your implementation of "class Triangle" must be based on the class outlined in "triangle.py" on the course website. That file contains a stub for each method (member function); each stub contains the following line:
pass # REPLACE
For each method, you will delete that line and replace it with one or more lines of Python source code to complete the method.
2. You may not alter "class Triangle" in any other way: you may not alter any line of the file except those lines which contain "pass" statements. This implies that you may not add new methods to the class, nor may you delete existing methods from the class.
3. The constructor (method "__init__") will accept three lengths as parameters. If those three lengths are all numeric values, the constructor will save them as the lengths of the three sides of the triangle. Otherwise, the lengths of the three sides of the triangle will all be set to be zero.
4. The constructor will validate the three sides. A triangle is defined to be valid when the lengths of all three sides are greater than zero and the sum of the lengths of the shortest two sides is greater than the length of the third side.
5. The representation of an object of type "Triangle" will be a string containing the length of each side. That string will be in the form "( xx.x, xx.x, xx.x )", where the parentheses and spaces are required. Each "xx.x" represents the length of one side; each length will be displayed with exactly one digit to the right of the decimal point. For ex: ( 17.2, 3.8, 15.0 ).
6. The method "sides" will return a tuple containing the lengths of the three sides.
7. The method "angles" will return a tuple containing the degree measure of the three interior angles, if the triangle is valid. Otherwise, it will return a tuple containing three instances of None.
8. The method "perimeter" will return the perimeter, if the triangle is valid. Otherwise, it will return zero.
9. The method "area" will return the area, if the triangle is valid. Otherwise, it will return zero.
10. The method "scale" will multiply each of the sides by the given factor, if the triangle is valid and the factor is greater than zero. Otherwise, it will not alter the three sides.
11. None of the methods in "class Triangle" will use function "print". That is, they will not display messages to the user, even if an error is detected.
Please note that you may wish to use function "print" to display various items as you are developing your implementation of the class. However, all invocations of function "print" must be removed from the final version of your class (or at least turned into comments).
Specifications for the Test Program
1. You will develop a program to serve as a test bed for "class Triangle". That is, the only purpose of the program is to demonstrate that each method of "class Triangle" is implemented correctly.
The source code for your test bed will be contained in the file named "proj09-test.py". That file will import "triangle.py".
2. Your test bed will not perform any input operations. Instead, all test cases will be embedded in the program itself.
3. The output produced by your test bed will be appropriately labeled so that the reader can understand the purpose and result of each test case without examining the source code.
Specifications for the Application Program
1. You will develop an application program which uses "class Triangle" to solve the problem described below.
The source code for your application program will be contained in the file named "proj09-app.py". That file will import "triangle.py".
2. The program will attempt to access the file named "proj09-input.txt". If that input file cannot be opened, the program will display an appropriate message and halt.
3. The input file will contain zero or more lines, where each line contains at most one triangle.
A triangle will appear as a string in the form " ( xx, xx, xx ) ", where "xx" represents the length of a side. The double quotes will not be present, the parentheses are required, and the whitespace is optional.
4. The program will read each line of the input file and display it. The display will be on one line, will begin with "Line NN:" (where NN is the current line number) and will contain the exact contents of the line. Line numbers will begin with 1.
5. If a line contains a valid triangle, the program will display the triangle as a string, and then display its perimeter and area. If a line does not contain a valid triangle, the program will display an appropriate message.
6. When the program has processed all of the lines in the input file, it will display the following:
a. The total number of lines processed.
b. The total number of valid triangles processed.
c. The average perimeter for all valid triangles processed.
d. The average area for all valid triangles processed.
e. The valid triangle with the largest perimeter (the triangle itself, its perimeter and area).
f. The valid triangle with the largest area (the triangle itself, its perimeter and area).
Assignment Notes
1. As noted under "Specifications for Class Triangle", the only lines in "triangle.py" which you may alter are the lines containing "pass # REPLACE". Each of those lines should be deleted, and you should substitute one or more lines to complete the functionality of the class.
2. Please note that method "angles" returns a tuple containing the three interior angles, where the angles are measured in degrees.
3. The following definitions may be useful:
a. A scalene triangle has no sides whose lengths are equal.
b. An isosceles triangle has at least two sides whose lengths are equal.
c. An equilateral triangle has three sides whose lengths are equal.
4. Heron's formula can be used to compute the area of a triangle:
Let A, B and C be the lengths of the three sides of a triangle, and let S be one-half the perimeter of the triangle. Compute:
T = S (S-A) (S-B) (S-C)
Then, the area of the triangle is equal to the square root of T.
5. You would be wise to develop your implementation of "class Triangle" and your test program incrementally and in parallel. That is, implement one class method at a time and then test that method by adding statements to your test program.
Clearly, the first class method which must be implemented and tested is the constructor ("__init__"). However, you might choose to first implement the constructor without worrying about erroneous parameters (error handling could be added later).
Perhaps the second class method to implement and test is "__str__" so that you have a way to display the value of an object of type "Triangle" using function "print".
Then, you might be wise to implement and test a relatively simple method, such as "perimeter".
After implementing and testing those three methods, you would continue to implement and test one method at a time until you have completed the class.
Be sure to insert and test any necessary error handling at the appropriate time. For ex, it makes no sense to add error handling to method "perimeter" until the constructor detects invalid parameters. 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M987743

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As