Question
C# 1. Modify class called Rational for performing arithmetic with fractions. /// Use integer variables to represent the private instance variables of the class: ///
C#
1. Modify class called Rational for performing arithmetic with fractions. /// Use integer variables to represent the private instance variables of the class: /// the _numerator and /// the _denominator. /// Provide a constructor that enables an object of this class to be initialized when its declared. /// The constructor should store the fraction in reduce forms. /// The fraction 2/4 is equivalent to and would be stored in the object as 1 in the _numerator and 2 in the _denominator. /// Provide a parameterless constructor with default values in case no initializers are provided. /// Provide public methods that perform each of the following operations: /// (all calculations results should be stored in a reduced form) /// 1. Properties /// 1.1. Numerator /// 1.1.1. get property will retrieve the value of the _numerator. /// 1.1.2. set property will set the reduced _numerator based on the _denominator. /// 1.2. Denomerator /// 1.2.1. get property will retrieve the value of the _denominator. /// 1.2.2. set property will set the reduced _denominator based on the _numerator. /// 1.3. Also, if the _numerator is 0, the _denominator will be 1. /// 2. A parameterless constructor with default values(0 in the _numerator, and 1 in the _denominator). /// 3. A constructor with two arguments, numerator and denominator, that initialize the _numerator and _denominator fields in reduced forms. /// 4. Create the following methods: /// 4.1. The ToString() override method would return the string representation of the reduced fraction (e.g. 1/2). /// 4.2. Add this Rational number and another Rational number, returning a new instance of Rational number. /// 4.2.1. Rational Add(Rational other) /// 4.3. Subtract this Rational number and another Rational number, returning a new instance of Rational number. /// 4.4. Multiply this Rational number and another Rational number, returning a new instance of Rational number. /// 4.5. Divide this Rational number and another Rational number, returning a new instance of Rational number. /// 4.6. The ToDouble() method returns the rational number in floating-point (double) format. /// 4.7. Make sure you have reused as much logic as possible.
public class Rational { // write your codes here }
2.
/// Modify class named IntegerSet. /// Each IntegerSet object can hold integers in the range from 0 to 100. /// The set is represented by an array of bools. /// Array element a[i] (private field) is true if integer i is in the set. /// Array element a[j] is false if integer is not in the set. /// The parameterless constructor initializes the array to the empty set (i.e., a set whose array representation contains all false values). /// Provide the following methods: /// a) Method ToString returns a string containing a set as a list of numbers separated by spaces.Include only those elements that are present in the set.Use an empty string () to represent an empty set. /// b) Method Union creates a third set thats the set theoretic union of two existing sets(i.e.element of the third sets array is set to true if that element is true in either or both of the existing setsotherwise, the element of the third set is set to false). /// c) Method Intersection creates a third set which is the set-theoretic intersection of two existing sets(i.e.an element of the third sets array is set to false if that element is false in either or both of the existing setsotherwise, the element of the third set is set to true). /// d) Method InsertElement inserts a new integer k into a set(by setting a[k] to true). /// e) Method DeleteElement deletes integer m(by setting a[m] to false). /// f) Method IsEqualTo determines whether two sets are equal. ///
public class IntegerSet { // write your codes here }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started