CS60 Homework 13 ------------------ Due Wed Nov 12th at 1:00pm Object Hierarchy ------------------ The task of this assignment is to design a 'number' hierarchy using C++ classes. We're going to assume that the only native type we have to work with is the 'int' type, and therefore your object hierarchy should not use any other native types other than 'ints'. Your hierarchy should contain the following 'number' classes: integer floatingpoint complex fraction Examples of each type integer: 10, 20, -1, 4 floatingpoint: 10.5, 0.0, 1.4, 1.554 complex: 1 + 0i, 2 + 10i, 0 + 1i fraction: 1/2, 3/4, 10/5, 0/1 Notice that all of these numbers, although representing different information, can be constructed using only 'int's. At a minimum, your child classes integer, floatingpoint, complex, and fraction must support a 'print' function that prints the type in the form appropriate to it's specific type (like in the examples above). You must also provide a constructor or member function mechanism for initializing the objects, and a function for asking whether the type is positive. For instance: int main() { fraction myfrac(1, 2); myfrac.print(); if (myfrac.ispos()) { cout << "it's pos!" << endl; } else { cout << "it's neg!" << endl; } } would print the string: 1/2 it's pos! and exit. The other types should behave in a similar manner and must all be derived from a common parent class. Program Requirements --------------------- To reiterate, you must design an object hierarchy that has a parent 'number' class, and four child classes 'integer', 'floatingpoint', 'complex' and 'fraction'. You may only 'int' types as class member variables. The following functions must be available for each child type: - constructor - integer - no params or one param - floating point - no params or two params (base and after decimal point) - complex - no params or two params (base and imaginary) - fraction - no params or two params (numerator and denominator) - print function - integer - prints the int - floating point - prints the base, a decimal point, and the portion after the decimal point - complex - prints real, a '+' sign, imaginiary, a 'i' - fraction - prints numerator, a '/' character, denominator - ispos function - returns '1' if type is positive, '0' otherwise You must provide an example program that makes an instance of each of the four types of numbers, initializes them, prints them, and decides if each is positive or not. You should use the following to initialize: integer: -10 floatingpoint; 4.5234 complex: 4 + 3i fraction: -4/3 Turnin ---------- The turnin tag for this assignment is 'hw13' and should include your object hierarchy header and code files, a hw13.cpp that shows usage of the hierarchy, a typescript showing compilation and execution of the program, a Makefile, and an optional README contianing special instructions for the grader. Sample Output --------------- [nurmi@localhost hw13]$ make clean rm -f *.o *.a hw13 *~* [nurmi@localhost hw13]$ ls Makefile floatingpoint.h integer.cpp typescript complex.cpp fraction.cpp integer.h complex.h fraction.h number.cpp floatingpoint.cpp hw13.cpp number.h [nurmi@localhost hw13]$ make g++ -I./ -ansi -pedantic -c -o number.o number.cpp g++ -I./ -ansi -pedantic -c -o integer.o integer.cpp g++ -I./ -ansi -pedantic -c -o complex.o complex.cpp g++ -I./ -ansi -pedantic -c -o fraction.o fraction.cpp g++ -I./ -ansi -pedantic -c -o floatingpoint.o floatingpoint.cpp ar rs libnumber.a number.o integer.o complex.o fraction.o floatingpoint.o ar: creating archive libnumber.a g++ -I./ -ansi -pedantic -c -o hw13.o hw13.cpp g++ hw13.o -o hw13 -L./ -lnumber [nurmi@localhost hw13]$ ./hw13 -10 4.5234 4 + 3i -4/3 integer is neg! floatingpoint is pos! complex is pos! fraction is neg! [nurmi@localhost hw13]$ exit