CMPT 200 Coding Homework
Write a class called Fraction that can store a rational number (reminder: those numbers that can be expressed in the form a/b, where a and b are integers are rational numbers). For example, a variable with a value of Â½ would be created using oneHalf = Fraction(1,2) Your class should be able to: â¢ Get the numerator - oneHalf.num() â¢ Get the denominator - oneHalf.denom() â¢ Print the value of the fraction. - print(oneHalf) would print: 1/2 â¢ Be able to: add, subtract, multiply, divide fractions (return a Fraction object with the answer). This should be done by overloading the appropriate operators rather than writing regular methods for these. â¢ Be able to compare fractions to see if they are ==, !=, <=, >=, <, > You should write a comprehensive test program to check the functioning of your class. For full marks, your Fraction class should ensure that your fractions are represented using a canonical (unique) form. In particular, your fractions should be in reduced form. Other questions to consider are 1) how is 0 represented and 2) how is a negative number represented. Handling these questions about fraction representation can be considered part of robust programming. Be sure to follow the specification given above as we will be testing your class using our own test program. You only need to submit your class definition. Greatest common divisor: To represent a fraction in reduced form, you need to calculate the greatest common divisor of the numerator and denominator. This can be done using the Euclidean algorithm. Assume that we want gcd(a,b), where a>=b>0. Then, using integer arithmetic, we can calculate the gcd using the following algorithm: m = a n = b r = m % n while (r != 0): m = n n = r r = m % n return n The value (n) returned by this method is gcd(a,b). For full marks, you need to write your own version of the gcd() function. (gcd() is available as a function in the math module, but we want you to write your own.)
Get Help With a similar task to - CMPT 200 Coding Homework
Similar orders to CMPT 200 Coding Homework
Data Structures and Algorithm
needs to follow rubric...
Python Project containing 4 tasks
2 Python files. Everything is in the pdf in detail...
The requirement is attached as "Problem Description." The work I have completed so far but needs to be put in functions is "Function" pdf....
Student Class in Record Manage Program C# assignment
Follow all instructions in the file linked. All I ask is you include everything that is being asked and if you have any questions ask them....
Tutlance Experts offer help in a wide range of topics. Here are some of our top services:
- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help
Post your project now for free and watch professional experts outbid each other in just a few minutes.