Department of Computer Science
The University of Hong Kong
CSIS1117A Computer Programming
Assignment 5
Due Date: 23:59, Nov 29, 2009.
You may assume all input are valid in this exercise.
Write a program to do fraction arithmetic. Your program should consists of 3 functions:
get_fraction() and add_fraction() and print_fraction().
struct Fraction {
int integral; //integral part of the fraction
int num;
//numerator of the fraction
int denom;
//denominator of the fraction, num < denom, and they
// are relatively prime, i.e. No common factors.
}
Fraction get_fraction()
//post: return a fraction from 3 integers read from cin, in the order of
//integral, num & denom.
void print_fraction(Fraction data)
//pre: data is a valid Fraction
//post: fraction are output as integral{num/denom}, such as 1{2/3}
Fraction add_fraction(Fraction a, Fraction b)
//pre: a, and b are valid Fractions
//post: return the sum of a and b as a valid Fraction
Note that a/b + c/d = (ad+bc)/bd,

This ** preview** has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*