{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2002-2-mt

# 2002-2-mt - 2002-2 Midterm CMPT 101 1 A rational number is...

This preview shows pages 1–2. Sign up to view the full content.

2002-2 Midterm CMPT 101 1. A rational number is any number of the for a/b where a, b are integers. Programming lan- guages do not generally support a rational number data type. The following five parts of this question require you to develop and use teh following rational number data type. Read all parts of this question before attempting part a Generally, rational numbers must be reduced, Do not concern yourself with reduction in this problem . The following is part of a Java implementation of the ADT RationalType class Rational Type { private int num; private int dem; public RationalType(); // initialize to 0 public RationalType(int a, int b); //initialize to a/b public int giveNumerator(); public int giveDenominator(); public void setRational(int a, int b); //set to a/b where b neq 0 public void input(); // input with no prompts public void output(); //output to screen no prompts public void absolute(); //take absolute value public void negate(); //multiply by -1 public void add(RationalType x); //add x to invoking number

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}