Assignment #4, COP-3337
This assignment is due on Tuesday, February 11 at the
start of class.
Absolutely no late submissions will be accepted.
Basic Assignment
You are to design the class interface for a new class named
Integer.
The Integer class should allow all standard
operations to be performed with arbitrarily large
integers.
In other words, unlike the standard int which may
range from -2147483648 to 2147483647, and will overflow silently,
your Integer will internally store as many digits as
needed (in an array).
Note however, that you do not have to actually implement anything.
You must simply provide a class interface.
(Actually, as described below, you will provide two interfaces
representing alternate designs).
Operations That Must Be Supported
Your Integer must specify the following:
- How an Integer is constructed. Provide a reasonable
set of constructors.
Make sure that there is some way to initialize
an Integer with a value that is logically
123456789123456678 (an int cannot store this value).
- How an Integer is destructed. If the default is acceptable,
say so in a comment.
- What to do about copy construction and operator=.
If the default is acceptable say so; otherwise if you are disabling these
operations or (eventually) providing your own non-default implementation,
indicate this in your code by doing the appropriate action.
- All reasonable mathematical operators, relational and equality operators,
prefix and postfix ++ and --, etc.
Look to the Rational class for design hints.
- Input and output functions.
- A member function named IntValue that will return an int
representing the stored value.
This value will make sense if the stored value is in the legal range of
an int.
- A member function named ToString that will return a
String representing the stored value.
Implementations
You must provide interfaces for two separate implementations.
Implementation #1
The internal data for the Integer consists of a
Vector<int> that stores the digits, an
int that tells whether the stored value is positive or
negative, and an
int that tells how many digits are logically
stored (not counting leading zeros).
It may help to remember that the copy constructor
is disabled in the current Vector implementation,
but operator= is not.
Since an implementation is not required, you do not need to know
anything else.
Implementation #2
The internal data for the Integer is identical
to implementation #1 except that the Vector<int>
is replaced by an int* object that represents a
dynamically allocated array and an int that represents
the maximum number of digits that the array can store.
Important Decisions
As you write the interface, make sure you carefully decide:
- What's public and what's private.
- Whether each member function is an accessor or a mutator.
- How each parameter is passed (by value, reference, or constant reference).
- Whether the return values should be by value, reference, or constant reference.
- If any functions should be non-members (in which case
you should make them friends).
Also, be sure to comment judiciously, use appropriate white space, and
make sure that your code is easy to read.
What To Submit
Place the interfaces for each of the Integer
implementations described above in separate header files
Integer1.h and Integer2.h.
Remember to use the #ifndef trick.
You can check for syntax errors by writing a
main.cpp program that includes the header file,
and attempts to compile.
Of course, without an implementation, you can only test for
trivial things such as missing braces, parentheses, semicolons.
However, any syntax errors that are found in the course
of grading the program will require deductions.
Submit both Integer1.h and Integer2.h.
Since there is no implementation, there is no output.