Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C program do the following: (a) Declare a data structure that will contain a rational number (b) write a function that will add, subtract,

In C program do the following:

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

(b) write a function 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 parameters for the operands, and the third for 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 in the same form. Have your input function check for errors in the input and return value of -1 in case an error was sensed. The error might consist of a zero in the denominator as in 3/0 or an error in form as in 4a/5 or 4%5. Both the input and 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.

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago