Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Fraction class with private fields that hold an int numerator and an in

ID: 3813593 • Letter: C

Question

Create a Fraction class with private fields that hold an int numerator and an int
denominator. In addition, create properties for each field with the set mutator for the denominator
being coded so as not to allow a 0 value (illegal values should be set to 1).

The Fraction class should have two constructors: the first should be a no-arg constructor
which sets the numerator to 0 and the denominator to 1 while the second should take two
arguments, one for the numerator and one for the denominator. Be sure to reduce the fraction
to its simplest form when the fraction is created.

In terms of methods, the Fraction class should have a private method Reduce() which
reduces the fraction to its simplest form (e.g., 3/6 should be reduced to 1/2). The reduction is
performed by finding the largest value that can divide evenly into both the numerator and the
denominator.


Another method that is to be included is the overridden public method for ToString()
which should return a string that represents the fraction (i.e., “3/4”). Please note that
ToString() does not print out the fraction but simply returns a string that can be printed when
a Fraction object is referenced in a WriteLine statement.


Also include a public operator*() method that multiples two Fraction objects and
returns a Fraction object. Recall to multiply fractions, multiply the numerators and multiply
the denominators and then reduce the result.


The final methods to include are public operator>() and public operator<()
methods that compare two Fraction objects and return a boolean (true/false) value.
Since fractions may have different denominators, the simplest way to compare two fractions is
to compute the floating point value for each fraction and then compare. To compute the floating
point value, divide the numerator by the denominator. For example, if the fraction was 3/4, then
double val = 3 / (double) 4; would assign 0.75 to val (notice the explicit
casting to avoid the perils of integer division: val = 3 / (double) 4; would assign 0 to val ).

Once the Fraction class is completed, write a driver program in C# (i.e. a Main() method in
another file) that demonstrates the workings of the Fraction class by creating three
Fraction objects. In addition to using the two argument constructor to assign values to one
of the fractions, involve the user by asking for a numerator and denominator and then use the
properties to assign values to another fraction. Main() should compare the fractions using both
relational operators and print out an appropriate message. Finally, Main() should multiply the
fractions together and assign the value to the third fraction. Be sure to print out the values of all
three fractions. Use a loop to allow the program to test several different fractions so you can
demonstrate that the program works for a range of input.

The basic structure of your Fraction class might look something like:
public class Fraction
{
private int numerator;
private int denominator;
// Constructor (no argument)
public Fraction()
{
// insert code here
}
// Constructor
public Fraction(int num, int den)
{
// insert code here
}
// Numerator Property
public int Numerator
{
// insert code here
}
// Denominator Property
public int Denominator
{
// insert code here
}
//Reduce method
private void Reduce()
{
// insert code here
}
// ToString method
public override string ToString()
{
// insert code here
}
// Multiply method
public static Fraction operator*(Fraction fract1, Fraction fract2)
{
// insert code here
}
// Greater Than method
public static bool operator>(Fraction fract1, Fraction fract2)
{
// insert code here
}
// Less Than method
public static bool operator<(Fraction fract1, Fraction fract2)
{
// insert code here
}
}

Explanation / Answer

the default creator to initialize the state of your category. The default
constructor can scan the info from the file “callstats_data.txt” into the
dynamic array call_DB. If call_DB becomes full, the operate ought to decision
the operate “double_size” to double the scale (capacity) of call_DB.
Remember, count and call_DB ar non-public members of your category and do
not ought to be passed to Associate in Nursing member operate of your category.
2. is_empty may be a Boolean public member operate of the category. It has no
formal parameter as a result of count may be a member of the state of the category
(private member) and doesn't ought to be passed thereto as a result of the state of
the class if renowned to any or all member functions of the category. If count == zero then
true is came back; otherwise false is returned.
3. is_full may be a Boolean public member operate of the category. it's no formal
parameters as a result of count and size ar members of the state of the category
(private members) and don't ought to be passed thereto as a result of the state of
the class if renowned to any or all member functions of the category. If count == size
then true is return; otherwise false. the scale is that the capability that is that the
total range of cells allotted to call_DB.
4. search is Associate in Nursing whole number public member operate that has just one formal
parameter, the key. secret's the mobile phone range for the record you're
search for. The array of records, call_DB and count ar members of the
state of the category and don't ought to be passed to a member operate of the
class; The operate can come the situation of key in call_DB if it's there;
otherwise -1 is came back.
5. add may be a void public member operate that inserts info for a decision
record into call_DB. Duplicates cell ranges ar ok; add can prompt the
user for the firstname, lastname, cell number, relays and decision length. You
may decision method record to re-process after you add a replacement record. add has
no formal parameters.
6. take away may be a void public member operate that deletes all records with the
cell range keep in key. If duplicate records exist with identical cell
number they have to all be deleted. “remove” has just one formal
parameter, the key.
7. double_size may be a void public member operate that doubles the capability
of call_DB. “double_size” has no formal parameters as a result of size, count
and call_DB ar all members of the state of the category, call_class. First,
size is multipled by two; second, memory is allotted victimisation “call_record
*temp=new call_record[size]; third the records in call_DB ar derived into
temp with the statement “temp[i]=call_DB[i]” employing a for loop. Forth, the
old memory for call_DB is de-allocated victimisation “delete [ ] call_DB”;
Finally, call_DB is about to purpose to the new memory pointed to by temporary worker
using “call_DB = temp”.
8. process
is a void public member operate the has no formal parameter as a result of call_DB and count ar members of the state of the category.. The operate method can calculate world wide web price of a decision (net_cost), the tax on a decision (call_tax) and therefore the total price of {the decision|the decision} (total_cost) victimisation the amount of boosters (relays) and therefore the length in minutes of the decision (call_length) for all call records keep in call_DB. Please take into account the following:
The rate on a decision (call_tax) is solely supported the amount of boosters (relays) accustomed build the decision (0&lt;= relays &lt;=5 then call_tax = 1%; 6&lt;= relays &lt;=11 then call_tax = 3%; 12&lt;= relays&lt;=20 then call_tax = 5%; 21&lt;= relays &lt;=50 then call_tax = 8%; relays &gt;50 then call_tax =12%) .
The net price of a decision is calculated by the subsequent
formula: net_cost = ( relays / fifty x zero.40 x call_length).
c. The tax on a decision is adequate to net_cost x call_tax / one hundred.
d. the entire price of a decision (rounded to the closest hundredth) is calculated by the subsequent formula: total_cost = net_cost + call_tax . All tax and price calculations ought to be rounded to the closest hundredths.
9.
print may be a void public member operate that has no formal parameters
because count and call_DB ar members of the state of the category. The
function can print each field of each call_record in call_DB to the
screen.
10.the destructor to de-allocate all memory allotted to call_DB. This operate has no formal parameters as a result of call_DB may be a member of the state of the category. it'll be known as mechanically by the compiler.
Use the driving force “call_stats6.cpp” to assist you implement this program. Output Format for the operate "print":
Consider the subsequent sample output table once coming up with and implementing the operate "print". See section “Format of Output below.
(The output is within the following order: firstname, lastname, mobile phone range, relays, minutes, net cost, tax rate, call tax, total decision cost)
print may be a void public member operate that has no formal parameters
because count and call_DB ar members of the state of the category. The
function can print each field of each call_record in call_DB to the
screen.
Jean Hayward Marlon Brando John Kennedy
Input Stream:
9546321555
5612971340
3051234567
0 zero five fifty eight twenty five
0 0.01 0 0
2 0.01 0.02 2.02 1.6 0.03 0.05 1.65
In the assignment you may declare one ifstream to bind your input to the file "callstats_data.txt" Whenever a program performs file i/o you want to embrace the "fstream" library.
Format of the computer file file(input name is "callstats_data.txt"): don't embrace column titles
(The order of the columns ar as follows: firstname, lastname, mobile phone range, relays, minutes)
Jean Hayward Marlon Brando John Kennedy Sir Edmund Hillary Clinton martyr Bush Barack Obama Donald Trump Bernie Sanders Harry Ford Michelle Obama Ann Dunham national leader Harriet Tubman Oprah Winfrey Charlotte Ray
Tina Turner
Shirley Chisholm Maritza Correla Margaret Hilda Thatcher
9546321555
5612971340
3051234567
7542346622
3054432762
9544321011
8776219988
9042224556
7877176590
5617278899
9546321555
5612971340
3051234567
5611234444
3054432762
8776219988
9042224556
7877176590
5617278899
0 zero five fifty eight twenty five
24 seventeen fifteen thirty fifty one hundred eighty seven eighty two
4 five eleven one twenty four5
4 three seventy nine eighty six eight twenty five twenty four 118 a hundred and fifteen twenty five two65 twenty two 2 five eighty nine sixty seven four0 fifty six
Format of Output to screen:
(the order of the columns is as follows: firstname, lastname, mobile phone range, relays, minutes, net cost, tax rate, call tax, total decision cost)
Jean Hayward Marlon Brando John Kennedy Sir Edmund Hillary Clinton martyr Bush Barack Obama Donald Trump Bernie Sanders Harry Ford Michelle Obama Ann Dunham national leader
9546321555
5612971340
3051234567
7542346622
3054432762
9544321011
8776219988
9042224556
7877176590
5617278899
9546321555
5612971340
0 zero five fifty eight twenty five
24 seventeen fifteen thirty fifty one hundred eighty seven eighty two
4 five eleven one twenty four5
4 3 79 86
0 0.01
2 0.01 1.6 0.03 3.26 0.08 3.6 0.05 40 0.08 57.07 0.12 0.16 0.01 0.09 0.03 7.2 0.05 0.1 0.01 54.35 0.12
0 0 0.02 2.02 0.05 1.65 0.26 3.53 0.18 3.78
3.2 43.2 6.85 63.92 0 0.16 0 0.09 0.36 7.56 0 0.1 6.52 60.87
Harriet Tubman Oprah Winfrey Charlotte Ray Madonna Carter
Tina Turner
Shirley Chisholm Maritza Correla Margaret Hilda Thatcher
3051234567
5611234444
3054432762
9544321011
8776219988
9042224556
7877176590
5617278899
8 25 1.6 0.03 0.05 twenty four 118 twenty two.66 0.08 1.81 a hundred and fifteen twenty five twenty three zero.12 2.76 43 10 3.44 0.08 0.28 265 twenty two forty six.64 0.12 5.6 2 5 0.08 0.01 zero eighty nine sixty seven forty seven.7 0.12 5.72 forty fifty six seventeen.92 0.08 1.43
1.65 24.47 25.76
3.72 52.24 0.08 53.43 19.35