Microsoft Visual C#
Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 11E

a. Write a FractionDemo program that instantiates several Fraction objects and demonstrates that their methods work correctly. Create a Fraction class with fields that hold a whole number, a numerator, and a denominator. In addition:

• Create properties for each field. The set access or for the denominator should not allow a 0 value; the value defaults to 1.

• Add three constructors. One takes three parameters for a whole number, numerator, and denominator. Another accepts two parameters for the numerator and denominator; when this constructor is used, the whole number value is 0. The last constructor is parameterless; it sets the whole number and numerator to 0 and the denominator to 1. (After construction, Fractions do not have to be reduced to proper form. For example, even though 3/9 could be reduced to 1/3, your constructors do not have to perform this task.)

• Add a Reduce() method that reduces a Fraction if it is in improper form. For example, 2/4 should be reduced to 1/2.

• Add an operator+() method that adds two Fractions. To add two fractions, first eliminate any whole number part of the value. For example, 2 1/4 becomes 9/4 and 1 3/5 becomes 8/5. Find a common denominator and convert the fractions to it. For example, when adding 9/4 and 8/5, you can convert them to 45/20 and 32/20. Then you can add the numerators, giving 77/20. Finally, call the Reduce() method to reduce the result, restoring any whole number value so the fractional part of the number is less than 1. For example, 77/20 becomes 3 17/20.

• Include a function that returns a string that contains a Fraction in the usual display format—the whole number, a space, the numerator, a slash (D, and a denominator. When the whole number is 0, just the Fraction part of the value should be displayed (for example, 1/2 instead of 0 1/2). If the numerator is 0, just the whole number should be displayed (for example, 2 instead of 2 0/3).

b. Add an operator*() method to the Fraction class created in Exercise 11a so that it correctly multiplies two Fractions. The result should be in proper, reduced format. Demonstrate that the method works correctly in a program named FractionDemo2.

c. Write a program named FractionDem03 that includes an array of four Fractions. Prompt the user for values for each. Display every possible combination of addition results and every possible combination of multiplication results for each Fraction pair (that is, each type will have 16 results).

Blurred answer
Students have asked these similar questions
Program this
2 part question I am using eclipse! Create a class Circle, which - has a field radius (double) It should have appropriate accessor and mutator.   If the Circle instance is created without parameter, the radius should be set to 1.0. Otherwise the radius should be set to the specified value.   The Circle class should have a class level (not instance level) field called Pi. Since Pi is a known constant (3.14159), this field should be a constant. This variable can be accessed directly by outside objects.   This Circle class should have a getArea() method and getPerimeter() method. You need to decide their return value and access level.   Note: Area = Pi * radius * radius Perimeter = 2 * Pi * Radius   part 2 Create a subclass of Circle class ColoredCircle by implementing the ColoredShape interface. It should have a field color of type enum ShapeColor. ColoredShape.java ShapeColor.java  ColoredCircle should have two constructors. One will takes one parameters radius and set the color to…
Create a class Course to describe a course according to the following requirements: A course has three attributes: courseName, courseCode, fees. Create a constructor without parameters to initialize all the instance variables to default values (0 for numbers and "" for a string). Create a constructor to initialize all the attributes to specific values. Add all setter and getter methods Create a tester class with the main method. The tester class must be named using your first and last In this class performs the following: Create a course object c1 using the default constructor. Create a course object c2 with the following information: courseName =” object oriented programing”, courseCode = “CS230” , fees = a value from your choice. Change the course fees of c2 to your age. Print the course information of c2 using getter methods   I attached Typical run of the program
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License