Define a class called fraction

Assignment Help Basic Computer Science
Reference no: EM13848829

Define a class called Fraction that houses a long numerator and long denominator. The constructor should accept two parameters representing the numerator and denominator respectively. If the caller passes a denominator of 0, display an error message using Console.WriteLine, wait for the user to hit ENTER, and exit the program using Environment.Exit.

Your Fraction class needs to implement the following methods:

Add. Calculates the sum of two fractions and returns the result as a Fraction.

Subtract. Calculates the difference of two fractions and returns the result as a Fraction.\

Multiply. Calculates the product of two fractions and returns the result as a Fraction.

DivideBy. Calculates the quotient of the two fractions and returns the result as a Fraction.

Reduced. Calculates the reduced version of the fraction, e.g., 5 / 10 reduced is 1 / 2 and 6 / 20 reduced is 3 / 10.

Implement each of these methods as an instance method of the Fraction class. Here are some sample uses:

Fraction f = new Fraction(1, 2); // 1/2

Fraction g = new Fraction(2, 3); // 2/3

Fraction sum = f.Add(g); // f + g

Fraction product = f.Multiply(g); // f * g

Fraction diff = f.Subtract(g); // f - g

Fraction quot = f.DivideBy(g); // f / g

Fraction reduced = sum.Reduced(); // sum reduced

This is the external interface to your class. You may have internal (private) members that help with calculating the least-common-multiple to calculate your common denominator when you need to add and subtract, etc.

Notes

Remember to change the namespace of your program to UML.Assignment3.

Helpful Hints

It's OK to have your result be an improper fraction (where the numerator ends up larger than the denominator).

Reference no: EM13848829

Questions Cloud

What is the elasticity coefficient for each price : What is the elasticity coefficient for each price
How would you vouch the rental receipts : How would you vouch/verify the following? (a) Rental Receipts (b) Assets acquired on Hire-purchase Or Cash Sales. (c) Contingent Liabilities.
Xplain why scarcity forces individuals and society : Explain why scarcity forces individuals and society to incur opportunity costs. Give specific examples. (2.5 marks for explanation and diagram plus 2.5 marks for specific examples)
How will the portfolio be prepared for sharing : Communicating with parents/families about the assessment process requires ongoing effort, support, and collaboration. How will the portfolio be prepared for sharing
Define a class called fraction : Define a class called Fraction
Distinguish between the reserves and provisions : Distinguish between the following: (a) Reserves and Provisions (b) Internal Control Questionnaire and Internal Control Evaluation.
Compute nominal gdp in canada for each year : What if both are negatively sloped? Provide the intuition behind your answer. Find the analytical and qualitative solution -
What are the tradeoffs in using multiples versus dcf analys : What are the tradeoffs in using multiples versus DCF analysis?
Explain relationship between materiality and audit risk : Explain the following in brief: (a) Relationship between materiality and audit risk (b) Relationship between Statutory Auditor and internal Auditor.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd