Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Business Economics Expert

Define a Fraction class similar to the one shown in earlier modules with num and den as its private data. Include a constructor to initialize the fraction to 0/1, a copy constructor, a destructor, and overloading functions to overload the assignment operator =, the comparison operators <, >, ==, !=, arithmetic operators +, +=, -, -=, *, *=, /, /=, as well as friend functions (non-member) to overload << and >> to output and input a fraction (see book example). Also, include a private member function called reduce() that gets called after arithmetic operations to reduce the frraction. +, -, *, / must return the result of the operation; e.g.: the sum or difference of the two fractions. +=, -=, *= and /= must assign the result of the operation to the object that's invoking the operation; i.e.: frac1 += frac2 must modify frac1 to make it equal to the sum of the two fractions, but frac1 + frac2 must simply return the sum.

If n1/d1 and n2/d2 are two fractions, their sum fraction's numertor is: n1 * d2 + n2 * d1 and its denominator is d1 * d2. To compare the two fractions, you can compare n1 * d2 with n2 * d1.

Define a class called FracList with private members fracPtr, a Fraction pointer and size to hold the size of the array of Fraction objects. Use the List container class developed in the modules as an example. Include constructor, destructor, copy constructor and overload the assignment, insertion (>>) and extraction (<<) operators. the [] operators for accessing array elements (both as lvalue and rvalue - see the example given in last module) and relational operators <, >, ==, and !=. For < and >, compare the size of the two FracList objects and for == and != see if they're identical with identical array elements. Also, include two resize() member function to resize the list, one keeping the existing vales and one without keeping old values (see the List example). Also, include a sort and binary search function (see the example).

In main, create two FracList objects, ask the user how many elements to allocate for each list, read as many Fraction objects from the keyboard as specified by the user into each (using >> operator). Sort both lists using the sort member function and display them; and then search for a value read from the user in both lists and print the index of the first occurrence or that it could not be found in either list.

Swap the two lists entered by the user so that the smaller size list (using < or > operator which only comares their size) is the first and larger size is the second. Use a swap function to swap the two lists. The example given in module did not use a function. Remember to swap two objects, you must either pass them by reference, or pass their addresses into couple of pointers. Print both lists again to verify the swap.

Resize the larger list to a size one larger than its original size, keeping all its values and assigning to its last element the sum of all other fractions (after reducing it), and print again.

Example run of the program:

Enter size of first fraction list: 5

Enter size of second fraction list: 3

Enter 5 fractions for first list: 1/4 1/8 2/3 1/3 1/2

Enter 3 fractions for second list: 3/4 1/5 1/4

Sorted lists:

1/8 1/4 1/3 1/2 2/3

1/5 1/4 3/4

Enter a fraction to search for: 1/4

1/4 was found at index 1 of list 1.

Swapped lists:

1/5 1/4 3/4

1/8 1/4 1/3 1/2 2/3

Resized list with sum of fractions at the end:

1/8 1/4 1/3 1/2 2/3 15/8

Print any key to continue.

Use separate files for class definitions (.h), function definitions and main program (3 files).

Business Economics, Economics

  • Category:- Business Economics
  • Reference No.:- M92477812
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Business Economics

Should we be renegotiating nafta yes or no if it is

Should we be renegotiating NAFTA? yes or no? If it is renegotiated, should it be replaced? What reasons would make it better in your point of view? What is the best argument you can make why NAFTA should or should not be ...

Ross textiles wishes to measure its cost of common stock

Ross Textiles wishes to measure its cost of common stock equity. The firm's stock is currently selling for $57.50. The firm expects to pay a $3.40 dividend at the end of 2013. The dividends for the past 5 years are shown ...

Think about a good or service for which you believe there

Think about a good or service for which you believe there has been a shift in demand or supply. Explain the reasons behind the shift and how that has influenced the equilibrium price.

Letnbspxnbspbe a random variable that represents the

Let  x  be a random variable that represents the weights in kilograms (kg) of healthy adult female deer (does) in December in a national park. Then  x  has a distribution that is approximately normal with mean  μ  = 67.0 ...

A suppose that for a given year national saving in a

a. Suppose that, for a given year, national saving in a country (an open economy) equals 100, private consumption equals 50, and government consumption equals 20. What is the level of output in this country in this year? ...

An insurance company will pay dave 220000 the market value

An insurance company will pay Dave $220,000 (the market value of the house) should his house be destroyed by fire during the year. In return, Dave pays the insurance company $1280 that year (called the "premium") for tha ...

Hey can someone give me super detailed answer as to why

Hey can someone give me super detailed answer as to why neoclassical economic theory could not have emerged prior to 1860s? Like I get that neoclassical economy focuses more heavily on mathematical part of economy but wh ...

A game is played with a bag of marbles the bag contains 3

A game is played with a bag of marbles. The bag contains 3 red, 5 blue, and 10 yellow marbles. A player can reach in the bag and randomly select one marble. If the marble is Red the player gets $12. If the marble is Blue ...

A biased coin has probability 06 of turning up heads you

A biased coin has probability 0.6 of turning up heads. You win $x if a head comes up and you lose $y if a tail comes up. If your expected winnings is $0, what is the relationship between x and y?

In one of your classes the syllabus states that hw is worth

In one of your classes the syllabus states that HW is worth 10%,quizzes 20%, test 40% and the final 30%. Your grades on the HW is 80, quizzes 75 and tests 68. What is your current grade in the class? What do you need to ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As