Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

For the following c statement what is the corresponding

For the following C statement, what is the corresponding RISC-V assembly code? Assume that the variables f, g, h, and i are given and could be considered integers as declared in a C program. Use a minimal number of assem ...

Question suppose that you are searching an unsorted array

Question : Suppose that you are searching an unsorted array of objects that might contain duplicates. Devise an algorithm that returns a list of the indices of all objects in the array that match a given object. If the d ...

Question lessons learned from the mirai botnet attack of

Question: Lessons learned from the Mirai Botnet attack of 2016 • Why was it so much more effective than previous BotNet designs? • What kind of mitigations would you recommend for protection? These two points must be ans ...

Question the project presentation should demonstrate

Question: The project presentation should demonstrate knowledge in the chosen area. The presentation should be formatted as follows: 12-point font using Times New Roman Use APA style correctly throughout the presentation ...

Please elaborate your understanding about how rfid and nfc

Please elaborate your understanding about how RFID and NFC work. What are the current security considerations and challenges?

I really do not know where to begin with this

I really do not know where to begin with this asignement. Activity Description A key aspect to planning is having an understanding of some of the layers involved in networks. This assignment examines a few of these layer ...

Ambrose has indifference curves with the equation x2 k -

Ambrose has indifference curves with the equation x2 = k - 4(x^0.5) ... Where the larger "k" is, the higher the indifference curve. If good 1 is drawn on the horizontal axis, and good 2 on the vertical... What is the SLO ...

Say that a processor addresses bytes with 64 bits addresses

Say that a processor addresses bytes with 64 bits addresses, has 8 byte words, and 1024 cache entries that are each 8 words long. a) How would the bits of the address be used to indicate the set, line, word and byte? b) ...

How do you find the minimum sample size when population

How do you find the minimum sample size when population standard deviation is anywhere between 14 to 24, and the half-width B desired could be anywhere between 2 to 7?

In c languageread a double number as 2 digits after the

In C language: Read a double number as 2 digits after the decimal point. The number should have at least 6 digits BEFORE the decimal point. Extract all digits at even positions. Print them in reverse order. Extract all d ...

  • 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