An example class
- I am working on a program that will require fractions.
- So I have decided to make a fraction class.
- What are is the domain of a fraction?
- An integer numerator
- A non-zero integer denominator.
- A possible sign
- What are the operations on a fraction?
- Likely Observers
- Get the numerator
- Get the denominator.
- Get a decimal equivalent
- Likely Transformers
- Set the value (numerator, denominator)
- Others
- A constructor that sets the value to be +, 0, 1
- Others
- Math functions (add, subtract, multiply, divide)
- The standard library has gcd and lcm functions.
- Need to include algorithm
- We will use these for now.
- The class needs to make sure that the denominator is never 0.
- The class declaration goes in FractionT.h
- The class implementation goes in FractionT.cpp
- We will need to put member functions in scope with the class scope operator in the implementation file.
-
classname::function
-
type classname::function
- Constructors are declared
- As a function with the class name as its name.
- With no return type.
-
FractionT::FractionT();
- We will not need a destructor for this code.