Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Assignment:
(1) Design a modular program to solve the following problem.
(2) Enter and successfully run the program in the Visual C++ environment Problem (100 points):
prepare a program to do fractional arithmetic. The program should handle the operations of addition,subtraction, multiplication, and division. It should also reduce the answer to its lowest form.
The program should have separate functions to handle the input and output of fractions, and to perform the various operations. The user should be allowed to enter any number of problems. The main program should only contain the variable declarations, the main loop, and function calls. Your program must consist of at least the following functions:
- A function to read in a single fraction
- A function to prepare out a single fraction
- A function to read in a problem
- A function to solve the problem (this may call other functions to perform the addition,subtraction, multiplication, and division, but this is not required)
- A function to reduce a fraction
The program will assume that fractions are entered properly (no zero denominators).
A sample dialogue follows (yours does not have to be like this). The user responses are underlined:
=======================================================================
Fractional Arithmetic Program
This program will perform arithmetic on fractions. Problems should be entered like this:
2/5 - 4/7
The allowed operations are addition (+), subtraction (-), multiplication (*), and division (/).
There must be at least one space around these operators.
Please enter a problem: 1/2 + 1/4
The answer is 3/4
Another problem (y/n)? y
Please enter a problem: 2/9 / 3/4
The answer is 8/27
Another problem (y/n)? n
Goodbye.
=======================================================================
To reduce a fraction, you will need to find the greatest common factor of the numerator and denominator. Once it is found, divide both the numerator and denominator by this value.
The greatest common factor (gcf) of two integers is the largest integer that will divide both numbers evenly. For ex, the greatest common factor of 18 and 27 is 9, since 9 is the largest integer to divide evenly into both 18 and 27. Since 9 goes into 18 twice and into 27 three times, the fraction 18/27 can be reduced to 2/3. An efficient algorithm for computing the gcf is attributed to the Greek
mathematician Euclid (ca. 300 B.C.).
Euclid's algorithm:
1. let A and B be two positive integers
2. let R = remainder after dividing A by B
3. while R != 0
A = B
B = R
R = remainder after dividing A by B
4. B is the gcf
For ex, consider finding the gcf of 24 and 60:
A = 24, B = 60 24/60 is 0 with remainder R = 24
set A = 60, B = 24 60/24 is 2 with remainder R = 12
set A = 24, B = 12 24/12 is 2 with remainder R = 0
So, the gcf is 12
Use sufficient test data sets to show your program works (at least one for each arithmetic operation,
which may include sets showing that the fraction reducing also works).
Some useful formulae (NOTE: deal with the numerators and denominators separately!):
bc
ad
d
c
b
a
bd
ac
d
c
b
a
bd
ad bc
d
c
b
a
bd
ad bc
d
c
b
a
÷ =
× =
-
- =
+
+ =
Extra Bonus Part A (10 points). This part is optional. If you can get it done, you will receive 10 extra
points.
Modify your program for Assignment 4 so that it can compute a list of fractions. For ex, it can
compute
.
5
4
11
7
33
25
13
12 + × ÷
Extra Bonus Part B (20 points). This part is optional. If you can get it done, you will receive 20 extra
points.
Modify your program for Extra Bonus Part A so that it can compute a list of fractions with possible
parentheses. For ex, it can compute
.
5
4
11
7
109
67
45
11
33
25
13
12
?? 

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9129438

Have any Question?


Related Questions in Programming Language

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

  • 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