CS13002 Programming and Data Structures, Spring 2002--2003
(SECTION 1/A)

CLASS TEST 1


For students with odd PC numbers

Input four integers a, b, c and d with b and d positive.


Part 1: Output the rational numbers (not their float equivalents) (a/b)+(c/d), (a/b)-(c/d) and (a/b)*(c/d).

Example:

Input a : 2
Input b : 3
Input c : -4
Input d : 5
(a/b)+(c/d) = -2/15
(a/b)-(c/d) = 22/15
(a/b)*(c/d) = -8/15


Part 2: Output the rational numbers (a/b)+(c/d), (a/b)-(c/d) and (a/b)*(c/d) in lowest terms, that is, in the form m/n with n>0 and gcd(m,n)=1.

Example:

Input a : 2
Input b : 3
Input c : -5
Input d : 6
(a/b)+(c/d) = -1/6
(a/b)-(c/d) = 3/2
(a/b)*(c/d) = -5/9

Test inputs:
  SET 1           SET 2
----------     ------------
 a = -377       a = -100
 b = 481        b = 31753
 c = -899       c = 125
 d = 1147       d = 19951


Typical output
Input a : 2
Input b : 3
Input c : -5
Input d : 6

Raw output:
(a/b)+(c/d) = -3/18
(a/b)-(c/d) = 27/18
(a/b)*(c/d) = -10/18

Reduced output:
(a/b)+(c/d) = -1/6
(a/b)-(c/d) = 3/2
(a/b)*(c/d) = -5/9

DO NOT FORGET TO ECHO YOUR INPUTS


For students with even PC numbers

Input four integers a, b, c and d with c or d (or both) non-zero and with a or b (or both) non-zero.


Part 1: Output the complex numbers (a+ib)/(c+id) and (c+id)/(a+ib) in the form (r/s)+i(u/v) with r,s,u,v integers and s,v>0.

Example:

Input a : 2
Input b : 3
Input c : -4
Input d : 5
(a+ib)/(c+id) = (7/41)+i(-22/41)
(c+id)/(a+ib) = (7/13)+i(22/13)


Part 2: Output the complex numbers (a+ib)/(c+id) and (c+id)/(a+ib) in the form (r/s)+i(u/v) with r/s and u/v in lowest terms, that is, with s,v>0 and with gcd(r,s)=gcd(u,v)=1.

Example:

Input a : 1
Input b : 2
Input c : -3
Input d : 4
(a+ib)/(c+id) = (1/5)+i(-2/5)
(c+id)/(a+ib) = (1/1)+i(2/1)

Test inputs:
  SET 1           SET 2
----------     ------------
 a = 37         a = -15163
 b = -33        b = 11387
 c = -2         c = 6667
 d = 35         d = -4189


Typical output
Input a : 1
Input b : 2
Input c : -3
Input d : 4

Raw output:
(a+ib)/(c+id) = (5/25)+i(-10/25)
(c+id)/(a+ib) = (5/5)+i(10/5)

Reduced output:
(a+ib)/(c+id) =(1/5) + i(-2/5)
(c+id)/(a+ib) =(1/1) + i(2/1)

DO NOT FORGET TO ECHO YOUR INPUTS


[Course home] [Home]