{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}