Section25.3The Fraction Calculator Using Structures
Subsection25.3.1Define a New Data Type
Remember our fraction calculator? We’ll start rewriting it using structures now.
Activity25.1.
Let’s start by defining a new data type fraction_t, designed to store the numerator and denominator of a fraction (as integers). Try implementing this below:
When you are done, please paste your code into the code submission box below:
Subsection25.3.2Declare the Variables
Activity25.2.
Now that we have our fraction type, let’s declare two variables, frac1 and frac2, of this type, and make them correspond to the fractions \(\frac{5}{3}\) and \(\frac{-2}{5}\text{.}\)
When you are done, please paste your code into the code submission box below:
Subsection25.3.4Adding Fractions
Activity25.4.
Since we are working on a fraction calculator, how would we go about adding these two fractions? Let’s store the result in a third variable, result. Can we simply say the following?