Lab 7: Final Wrap-up -- Pointers and Inheritance
COM1101 Winter 2001
(Version of 2/24/2001)
College of Computer Science, Northeastern U., Boston, MA
This lab is based on the wrap-up notes
that I have prepared for the last two
weeks of the course. You will find that each part of the assignment can be
done by finding the appropriate example in my wrap-up notes.
This page explains everything you are to do and turn in for this Lab 7 assignment.
There is no separate page for the details. They are here.
The lab takes place on Tuesday, February 27th
and is due by 4pm on Monday, March 5th,
the beginning of the last week of classes.
WHAT YOU ARE TO DO AND HAND IN FOR LAB 7 --
RULE: Do not use cin to set any values in any functions
in this lab, or in your main(). Note also that all the work with classes
will involve references to them via pointers and the use of the arrow notation, '->'.
Create a function, pointerFun2(), with two pointer arguments one
to a double and the other
to a string which changes the original values of the arguments handed to it.
Show that the changes "stick"
by printing the values before and after the call to the function.
Note that for this to work, you'll need to use the built-in string constructor,
e.g., string *s = new string("hi there") to set a pointer initially and to change
the value pointed to in the function.
Define a class called Link that has two member variables,
an int and a pointer to
a Link. Create four Link objects, A, B, C and D, with int member values 30, 40, 50
All four should be created with new and assigned to the pointer variables
A through D.
Then "link" them together so that A contains a pointer to B, B to C and
C to D. The link in D should be set to NULL (pg. 686).
Write a function that when given a Link object, prints the value of the int in the
next Link (the one it's linked to) as well as returning a pointer to the next Link
object. Show by various printouts that your function does what it's supposed to
do. It should check for NULL and avoid trying to print the next int member
in that case. But it should return the NULL.
Define a class called Restaurant with double member variables cheapest,
open and close, for the cheapest meal,
the most expensive meal, the opening hour
and the closing hour. Define a default constructor, a constructor that only sets
the hours and another that sets all four members. Show an example of the use
of each of the constructors, using new.
Create an array of pointers to objects of class HiTechCompany. Each company should
have a name string and a numberOfEmployees int member variable.
Create a function which when called with the array will construct a HiTechCompany
instance with the name string and number of employees passed as arguments and attach
it to the index element of the array, where the index is also passed as an argument.
Demonstrate the use of what you've done by filling in three elments of the array in
this way and printing
out some of the values after setting them with your function.
Create three subclasses of HiTechCompany which are SoftwareCo,
HardwareCo and NetworkingCo.
at least one distinct member variable for each of the subclasses. Build constructors
and demonstrate the initialization of an instance of one or more of the subclasses.
Note that this will require you to deal with the constructor for the superclass
as part of your subclass constructor.
- For the three hi tech subclasses, create distinct definitions of
a member function, showName() that prints the name of the company but
also prints along with it the type of company it is, e.g., "Speedo, a networking company".
This function should have a distinct definition for each of the subclasses.