Provide an interface then a full implementation for each of the following ADTs:
Data values to track:
numerator, denominator: both integer values
Operations:
read a fraction
print a fraction
given two fractions, f1 and f2,
compute and return f1+f2
given two fractions, f1 and f2,
compute and return f1-f2
given two fractions, f1 and f2,
compute and return f1*f2
given two fractions, f1 and f2,
compute and return f1/f2
given two fractions, f1 and f2,
compute and return f1%f2
|
Data values to track:
dollars, cents: both integer values
Operations:
read a cash amount
print a cash amount
given two cash amounts, c1 and c2,
compute and return c1+c2
given two cash amounts, c1 and c2,
compute and return c1-c2
given a cash amount, c, and a multiplier, m,
compute and return the cash amount m*c
|
#include <cstdio>
int main()
{
float penny = 0.0f;
printf("The cents from one to 100 are:\n");
for (int i = 1; i <= 100; i++) {
penny += 0.01f;
printf(" %g", penny);
if ((i%5) == 0) printf("\n");
}
}
|