Define a fraction class similar

Assignment Help Business Economics
Reference no: EM131669111

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).

Reference no: EM131669111

Questions Cloud

What is the expected value of the house : Assume you own a home that is worth $1M (Congratulations!) and there is no depreciation. What is the Expected Value of the house
What are the major limitations to direct marketing : What are the major limitations to direct marketing?
Research the growth opportunities in the industry : Evaluate whether the strategy currently used by your industry, as discussed in previous sections, appears to be sustainable over time.
Integrate an academic electronic health record : What main resources would you need to integrate an academic electronic health record in healthcare simulations (with and without human patient simulators)?
Define a fraction class similar : Define a Fraction class similar to the one shown in earlier modules with num and den as its private data.
Discuss your views of that particular film : Visit greatplacetowork website and take a look at the UK's 50 best places to work, as well as the 100 best workplaces in Europe
Folder and the calculator app : After Photos is removed from the folder, what happened to the folder and the Calculator app?
Create a list of possible deductions for your household : Create a list of possible deductions for your household. Are you able to reduce your taxable income enough to place you in the next lowest tax bracket?
Results of a horse race with three horses : You are tracking the results of a horse race with three horses. 1. PSEUDOCODE: Write the pseudocode that:

Reviews

Write a Review

Business Economics Questions & Answers

  Economics assignment

This document contains various important questions and their appropriate answers in the subject field of Economics.

  Demand and supply curves

Economics is the study of the principles governing the allocation of scarce means among competing ends when the objective of the allocation is to maximize the attainment of the ends.

  Long-run perfectly competitive equilibrium for the firm

Evaluate Government intervene and correct this situation?(a) Explain the concept of a concentration ratio. A rise in the price of magarine Explain the impact of external costs and external benefits on resource allocation long-run perfectly c..

  Supply and demand diagrams

Explain each of the following using supply and demand diagrams,  With the use of a graph, explain how these two programs affect cigarette consumption and the price of cigarettes.

  Case study: fisher-price toys

The case study of the Fisher-Price Toys, Inc., a popular case in basic economics and management from the prestigious Harvard Business School.

  Draw the production possibility curve

Draw the production possibility curve and a. Define consumer surplus and producer surplus.

  Tax revenue

The Australian government administers two programs that affect the market for cigarettes

  Maximize total welfare

How many tickets to sell to maximize total welfare.

  Difference between the cv and the ev

The change in consumer surplus (?CS) is not "theoretically" justifiable like the CV and EV but it continues to be the most widely used measure of consumer welfare change. Explain how this can be reconciled

  Depict von neumann-morgenstern utility index u in a diagram

Depict the von Neumann-Morgenstern utility index u in a diagram

  What is the market solution

What is the market solution (market price and quantity) and What is the total surplus of the society under the market solution

  Calculate gross national product and net national product

Calculate gross national product and net national product

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