4 - Binary Data and Multiple Inheritance
will give you practice processing a binary
file, manipulating binary data, using casts, and multiple inheritance.
The assignment has two parts - processing a binary file and
working with the 12-class multiple inheritance
below. You should
only turn in one (set of) source code that contains both parts.
Input File: ass4data.bin
1 - Read and interpret the binary input file
binary input file contains data that will be used to create geometric
of the types listed below. There are 50 records in the input
file, consisting of 8 different types. Each type represents
for one of the non-abstact class objects described below. You
complete part 1 of the assignment to make sure that you can correctly
read and process the input file. To read each read record,
one byte from the binary file. That byte is coded and
contains the type and color of each geometric solid.
the first and last bits of the one byte that you read.
the resulting byte into two nibbles. The first nibble
the type of geometric solid. The second nibble contains the
(if any) of the geometric solid. See the (nibble codes) codes
below for the solid type and color.
Determine the type and color (if any) of the solid and read
the correct number of double values to define Thing. Use the
partial text output to verify the processing of the binary file.
Solid Type Code
(first nibble value)
(second nibble value)
2 = sphere
4 = rectangular prism
8 = cube
= No color
1 = red
2 = blue
4 = green
8 = yellow
of the binary file
this partial output to make sure you are corrected reading and
interpreting the binary file. You do not have to submit this
output. It is to be used for your verification of part 1.
This data is the input for part 2, described below.
1st Byte Toggled -Nibbles-
-------- Doubles ----------
3.41176 1.13333 4.36842
1.68421 3.40000 4.88889
2 - Multiple Inheritance
class must be able to identify itself (with a name function).
There are 8 non-abstract classes.
- Thing – Abstract,
contains a function, name() that returns the class name.
- GeometricSolid – Abstract,
contains a pure virtual function, volume().
- Circular – Abstract,
contains a floating-point radius data member.
- RectangularPrism – contains 3 floating-point data members,
define the volume function in this class.
contains string and double data members to store the color
and weight. Contains a pure virtual function, density().
- Cylinder – Derived from Circular. Contains a
double, height member. Define the volume function for this
- Sphere – Derived from Circular. Define the volume
function for this class.
- Cube – Derived from RectangularPrism.
- ColoredCylinder – Derived from ColoredThing and
Cylinder. Define density as
weight divided by volume for this class.
- ColoredSphere – Derived from ColoredThing and
Sphere. Define density
as weight divided by volume for this class.
- ColoredRectangularPrism – Derived from ColoredThing and
RectangularPrism. Define density as weight divided by volume
for this class.
- ColoredCube – Derived from ColoredThing and Cube.
Define density as weight
divided by volume for this class.
radius and height
length, width, and height
3 doubles radius,
height, weight, color
doubles radius, weight, color
doubles length, width, height, weight,
2 doubles side,
program should perform the following tasks:
- Read in the binary data file, correctly processing each
particular type of Thing.
a pointer to a Thing, and making use of polymorphism, allocate memory
dynamically for a specific type of GeometricSolid. Don’t
- Overload the insertion operator ( e.g.
ostream& operator<<(ostream&, const
GeometricSolid&) ) for printing both GeometricSolid
and ColoredThing objects. Note: the ColoredCylinder,
ColoredSphere, etc. will have to use both overloaded insertion
- Use the correct C++ cast types. In particular,
you should use a reinterpret_cast when reading in the binary file using
the istream::read() function, and use a dynamic_cast to downcast a
Thing pointer to utilize the correct operator<<()
for printing either a GeometricSolid or a ColoredThing object.
- The output should be produced by your overloaded insertion
operators and match that which is partially displayed below.
- Use the following formulas:
V = l w h
V = 4/3(pi)r3
V = (pi)r2h
V = s3
attempt to solve all of the program requirements in
one pass. There are
requirements for this assignment.
“sneak up” on the solution. Check the instantiation
of the class objects before you attempt to use the overloaded insertion
You will need virtual inheritance as
demonstracted in class.
2 Program Output