Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C programming, (a) Declare a data structure that will contain a rational number. (b) Write functions that will add, subtract, multiply, and divide rational

In C programming,

(a) Declare a data structure that will contain a rational number.

(b) Write functions that will add, subtract, multiply, and divide rational numbers. In all functions, pass in three parameters, each pointing to a data structure of the type you declared in part a. Use two of the parameter for the operands, and the third for the result.

(c) Write a function that takes a pointer to your data structure as a parameter and returns the greatest common divisor of the numerator and denominator.

(d) Use your function from part c to write a function that will reduce a fraction (rational number) to lowest terms. Pass in a pointer to the fraction and have the fraction modified by the function.

(e) Write input and output functions so that a user can enter a fraction in the form.

2/3, -5/6, 4/-5, or -12/-33

and the output is the same form. Have your input function check for errors in the input and return a value of -1 in case an error was sensed. The error might consist of a zero denominator as in 3/0 , or an error in form as in 4a/5 or 4%5. Both the input function and the output function should take a single pointer to your data structure from part a as a parameter.

(f) Combine your functions from part b through e to write a program that will perform rational number arithmetic for the user. The user should be allowed to enter any number of problems, and the program should output the answer in lowest terms. A sample dialogue is below. The user's input is in boldface.

Fraction Arithmetic

-----------------------------

Input problem: 2/3 + 1/5

answer : 13/15. want input another problem (y/n)? y

Input problem : 4/2-5/0

Error ! want to input another problem (y/n)? y

input problem : 2/9 * 3/4

Anwser: 1/6 want to input another problem (y/n) n

Goodbye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

G Domasknner - ue Main.sq | Laad fetad Amplute

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago