You are on page 1of 9

Project #1.

You will write a PlayList class that manages a play list of songs. The PlayList class manages a
dynamically allocated array of song objects. The song class is provided for you in song.h and
song.cpp, which should NOT be modified. Your playlist class will be implemented in two files
proj5_playlist.h and proj5_playlist.cpp. The class will support two basic functions:
1. Managing the playlist. This includes adding and deleting songs.
2. Playing from the play list. This includes keeping track of which is the next song to be
played. Obviously we will not actually be playing any music. “Playing” the song will
consist of printing the name.
To support these functions, your PlayList class should have the following public member
functions:
 The class should have a default constructor that builds an empty playlist with space for 2
songs.
 void AddSong(const Song &s);
 This function will add s to the end of the play list. This function needs to adjust the song
array size when necessary. This function should not affect the current song index (for
playing songs).
 bool DeleteSong(const Song &s);
This function tries to delete s from the play list. If s is in the list, the function deletes the
song from the list and returns true. Otherwise, nothing is done and the function returns
false. If the play list has multiple copies of one song, you should just delete one copy.
This functions needs to adjust the song array size when necessary to make sure that the
number of songs in the list is at least half the size of the capacity. If after a song is
deleted, the playlist object becomes empty, the function must make the object identical to
the one created by a default constructor. This function should reset the current song index
only if the index is out of bound after a song is deleted.
 void ShowAll() const;
This function will print all of the songs in the play list on the screen.
 void play(int num=1);
This function “plays” num songs from the list. The songs in the list should be play in a
circular manner: when reaching the end of the list, repeat from the beginning.
 void ShowStatus() const;
This function shows the status information of the playlist including the total slots
allocated for the song list (size of the song array), the number of songs in the list, and the
current song index.
 The class should have a destructor that deletes the memory allocated for the playlist when
the PlayList object is deallocated.
The PlayList class must also overload the following operators and implement the described
functionality accordingly:

1. Addition operator (+): adding a song to a playlist (i.e. playlist object + song object)
This routine will return a new playlist object. The returned playlist will be a
concatenation of all songs in the caller’s playlist and the single song at the end (same as
the result of AddSong).
2. Subtraction operator (-): removing a song from a playlist (i.e. playlist object – song
object).This function will return a new playlist object that has the same content as the
result of DeleteSong.

All data members in this class should be private. To support the public and friend functions, the
PlayList must maintain a number of data members. The most important one is the playlist that
stores an array of songs. However, since there is no size limit on the play list, it must be declared
as a Song pointer (e.g. Song *plist;) so as to be used as a dynamically allocated array. The
dynamic array must expand and shrink to ensure that its size is no more than twice that number
of songs in the list or no more than 2. More specifically, there are three situations:
 At initialization, the size of the dynamic array should be 2.
 In the AddSong function, if the dynamic array is full (array capacity = number of songs),
the array size needs to double to make room for new songs.
 In the DeleteSong function, if after a song is deleted, the number of songs is less than ½
of the array capacity, the array size needs to be halved (with the exception that the
capacity is 2 as in the initialized empty playlist, in which case, the array should not
shrink).
You should isolate two memory management functions in two routines: void doublesize() and
void halfsize(). The taskes in both functions are similar with the following steps: Allocate a new
dynamic song array of the desired size, (2) copy the content in the old song array to the new
array, (3) free the old array (plist), (4) set plist to the new array and set bookkeeping variables
accordingly. For diagnostic purposes, you must call ShowStatus() at the beginning of each
function and before each function returns (see the behavior in the sample executable).
Doublesize will be called in the AddSong function while halfsize will be called in the
DeleteSong function.

The class must also contain other private member for bookkeeping with at least three private data
members: an int member to record the capacity of the dynamic array, an int member to record the
number of songs in the dynamic array, and an int member to record the current song index (to
support the play function). These members are displayed in the ShowStatus function.
Test Program
A test program menu.cpp is provided. This program will allow you to interactively test the
features of your PlayList class. Keep in mind that this program does not test everything that your
class must handle. For example, it doesn't test the operator overloads. You should write other
tests to verify you implement your memory allocation and deallocation correctly. To compile the
program: put all files in one directory and issue ‘g++ song.cpp proj5_playlist.cpp menu.cpp’
Hints

1. Start the project as soon as possible. This project is the hardest so far.
2. You will need to decide your private data members first, once that do that you should
proj5_playlist.h file that contains the playlist class declaration.
3. You should then create a shell implementation of the class in proj5_playlist.cpp that can
be compiled with song.cpp and menu.cpp.
4. After that, you should implement the default constructor and the ShowStatus function,
both are trivial
5. After that you can work on the doublesize function (which has the four steps described
earlier) and the AddSong function.
6. After that you can work on the ShowAll and Play functions, and then halfsize and
DeleteSong.

Project #2.
You will implement a MyString class that stores and performs various operations with strings. In
addition, you must provide a driver that tests each function of the MyString class. The MyString
class overcomes some of the problems in c-string such as the unchecked [] operation, the lack of
comparison operators, etc.

A complete header file, a skeleton implementation file and an empty driver file have been
provided for you :
MyString.h
MyString.cpp
driver.cpp

You should not change MyString.h in any way. Submissions will be tested using the MyString.h
above.

The skeleton implementation file contains detailed descriptions of each of the functions. You
should implement each function as described in the comments of MyString.cpp. You may use
functions in the c++ standard libraries (most, if not all, functions needed should be referenced in
the function descriptions) in their implementations but should NOT use the String class.

In addition to the completed implementation file, you must also turn in a driver file which tests
the complete functionality of their implementation. Your tests should be simple but should also
extensively test the correctness of your solution. The driver file should be well commented
indicating where each feature is tested and the expected output.

This project is a bit longer than previous projects. You will need to use the following steps to
complete the project:

1. Look over MyString.h to get an overview of what the MyString class looks like.
2. Review the function descriptions in MyString.cpp. It is not necessary to know how to
implement each function yet, just get an idea of the input/output parameters and the
general purpose of the function.
3. Start filling in the function definitions:
o Start from the top of MyString.cpp -- the functions have been ordered such that
implementing them in the order will be most intuitive.
o After you implement each routine. Write your test case in driver.cpp and test
that routine!!! This is the best time to write your test cases as you have just read
the function requirements! Your test cases (driver.cpp) will count as 25% of this
project, if you follow any direction, make it this one.
o Repeat until all functions implemented

Project #3.
You will implement an inheritance hierarchy with polymorphism and virtual functions. A simple
console based interface is all that is needed. Build your classes first, each in their own .h and .cpp
files, then test them with a main method.

Here is the following set of classes you will implement and their inheritance relationship:

The instructor will provide you with your assigned types. DO NOT make up new types or pick
your own.

Type 1 Type 2 Type 3


PitBull Jet Soldier
Cougar Helicoptor Robot
Lion Drone CarJacker
Tiger Blimp Terrorist
Bear Bomber BadCop
Enemy
The generic BASE class Enemy will serve as the parent class to three child classes.
The variables will be private: x_position, y_position, width, height and status
These methods will be protected: a 'get' and 'set' for EACH variable listed above
These methods will be pure virtual and public: move_position, fire_weapon, update_status
main
The main() function should be in it's own .cpp file; It will create Enemy objects and store them in
an array. The methods of an object define what the object DOES, the actions it will perform.
main() will loop and ask the Enemy objects to perform actions like move_position, fire_weapon
and update_status. The basic layout will be:
#include "stdafx.h" // not needed by some IDE's
#include <conio.h>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])


{
const int max_enemy = 20;
Enemy* enemy_ptr[max_enemy];
int num_enemy;

// create Enemy objects, place in array


// set value of num_enemy
while ( true ) {

// every Enemy object should move_position

// Pick a random Enemy to fire_weapon

// Pick a random Enemy to update_status

getch();
cout << endl;
}
return 0;
}
You can google 'C+ random number' for help on generating a random number, then use the
modulus '%' operator: rand() % num_enemy This will select which Enemy in the array should
perform an action.
Keep main() simple! The objects will do the work, and print messages reporting what they have
done. The ONLY enemy object methods you are allowed to call are move_position, fire_weapon
and update_status
Type 1 - Type 2 - Type 3 Classes
First, start simple, create your assigned classes and have each one print a simple message for
each action it takes:
PitBull moves position Jet moves position Soldier moves position
Jet fire weapon: missile
PitBull update status: I have been hit (bark)
These should be simple classes, a variable to track the name of the object and simple cout
statements to report each action. Make sure move_position does NOT output an end of line, if
there are 10 objects we DO NOT want it to print 10 lines of output. Do custom messages to
match the Enemy, a pitbull will bite and a soldier will shoot a rifle when they fire a weapon. A
soldier will say ouch and a Jet will make a ping sound when update status records a hit.
Make sure you cen get the simple version of your program working. Test it with different
numbers and different combinitions of enemy objects. Each time through the main loop it should
output messages like the example above. Do NOT move on until the simple version is working!
Better Enemy Classes!
When you have the simple version working, improve your child classes. Make them behave like
they would in a video game. Any change to main() or the Enemy parent class should be very
minor (if at all), the focus is on the child classes. Make them move, and fire weapons and record
hits when update status is called:
move_position
Each object exists in a 2D space, their X position can range from 0 to 800, y position 0 to 600.
Position 0,0 is the top left corner, 800,600 is the bottom right. The ground is at 500 so a person
or animal will be at y position 500. A low flying object at y position 300, a high flying one a 100.
Objects move on the X axis, have walking objects move 3, running 6 each time move position is
called. Flying objects move 15 to 30 with each call depending on their speed. Do not make them
all start in the same position, do not make them move at the same speed and do not make them
all move in the same direction. When an objects status is zero, it is DEAD, it should no longer
move.
fire_weapon
Make sure each object fires an appropriate weapon. In general type 1 objects bite or slash. Type
2 objects have missiles or bombs. Type 3 have guns. Keep track of ammo, if a jet has 4 missiles,
have fire weapon report out of ammo on the 5th call. Also check status, when dead, fire weapon
should say NO WEAPON FIRED. Since animals do not use ammo, have them vary the attack,
e.g. bite leg, slash chest, bite neck.
update_status
Update status means the Enemy object has been HIT. It is to lose status points and DIE if status
reaches zero. Type 1 objects should take only 1 or 2 hits before they die, type 3 objects 4 to 5
hits and type 2 should take 7 to 8 hits. As always, make it match the enemy, a Robot will take
more hits before death than a Car Jacker. Always report current status points when called, output
an extra special statement when death occurs. A soldier might say ouch for a non-lethal hit, but
ARRRGH for a lethal one. The simple way to do this is to start each object with a status that
matches the number of hits to kill it and subtract one every time.
Once you have your improved child classes, the output should update each time through the
loop, the example below shows the program with 3 loops:
PitBull move to 710,500 Jet move to 320,100 Soldier move to 518,500
Jet fire weapon: missile (2 left)
PitBull update status: hit by bullet, status points 0 (dead)
PitBull move to 710,500 Jet move to 360,100 Soldier move to 514,500
PitBull fire weapon: dead!!!!!
Soldier update status: hit by bullet, status points 3 (ouch)
PitBull move to 710,500 Jet move to 400,100 Soldier move to 510,500
Soldier fire weapon: rifle (12 bullets left)
Jet update status: hit by bullet, status points 7 (ping)

Project #4.

You will implement a classic Inheritance hierarchy. A simple console based interface is all that is
needed. Build your classes first, each in their own .h and .cpp files, then test them with the
simple main method provided below.

Here is the following set of classes you will implement and their inheritance relationship:

Account
The generic BASE class Account will serve as the parent class to Checking, Savings and
CreditCard.

Variables (private):
name – Name of account owner, a string
taxID – social security number, a long
balance – an amount in dollars, a double
Variables (protected):
last10withdraws – a double array of size 10. The last 10 withdrawal amounts.
last10deposits – a double array of size 10. The last 10 deposit amounts.
numdeposits – number of deposits, an int
numwithdraws – number of withdrawals, an int
Methods:
SetName, SetTaxID, Setbalance() assigns a new value for each with error
checking
GetName, GetTaxID, Getbalance() returns a value for each variable.
MakeDeposit( double amount ) - adjust the balance and put it in the deposit array
A constructor with no parameters and one with name, taxID
and balance parameters
display() a method to display the name, taxID and balance
Checking
A specific DERIVED class that represents a bank checking account. It must inherit Account.
Variables (private):
last10checks – an int array of size 10. The last 10 check numbers.
Methods:
WriteCheck( int checknum, double amount ) - adjust the balance and list it as a
withdraw in the base class
A constructor with no parameters and one with name, taxID
and balance parameters
display() - display the accounts check register (number and amount) and deposit
record
Savings
A specific DERIVED class that represents a bank savings account. It must inherit Account.
Methods:
DoWithdraw( double amount) - adjust the balance and list it as a withdraw in the
base class
A constructor with no parameters and one with name, taxID
and balance parameters
display() - display the accounts withdrawal and deposit record

CreditCard
A specific DERIVED class that represents a credit card account. It must inherit Account.
Variables:
cardnumber – a long
last10charges – a string array of size 10. The last 10 names of the charges.
Methods:
DoCharge( string name, double amount ) - adjust the balance and list it as a
withdraw in the base class
MakePayment( double amount) - adjust the balance and list it as a DEPOSIT in
the base class
A constructor with no parameters and one with name, taxID
and balance parameters

display() - display the accounts charges ( name and amount ) and deposit record
Note: all display() methods should use cout to output text to the console.
Write a main() Function
Write a main that creates 3 objects, starts each with a balance of $100. Create a loop that displays
the following menu each time through the loop. Make sure the balance is updated each time
AND you use the objects to perform the transactions.
Checking balance: $100 Savings balance: $100 Credit Card balance: $100
1. Savings Deposit
2. Savings withdrawal
3. Checking Deposit
4. Write A Check
5. Credit Card Payment
6. Make A Charge
7. Display Savings
8. Display Checking
9. Display Credit Card
0. Exit

Project #5.

For this project read problem 13.12 [Deitel - C++ How to Program-8th Edition] related to the
employee hierarchy. You will extend the problem by adding new classes as follows:

 Instead of Employee as the main base class, introduce UniversityMember as the main
base class. That is Employee and its derived classes as in 13.12 will now be derived
from UniversityMember.
 Introduce following new classes
1. TeachingStaff class
 A TeachingStaff “is a” SalariedEmployee
 Each teaching staff teaches 3 courses (use an assumed Course number)
2. ResearchStaff class
 A ResearchStaff “is a” SalariedEmployee
 A ResearchStaff only does research. Indicate the research areas by listing
upto 5 research project titles
3. Professor class
 Professor “is a” a TeachingStaff as well as a ResearchStaff
 A professor teaches 2 courses (again use an assumed Course number)
 A professor has some projects (Use an assumed Project number)

In this project, you are required to demonstrate at least the following:


 Use of Map container and associated iterators and algorithms (choose some relevant
ones) in the Standard Template Library. That is, instead of using Vector as mentioned in
13.12 you are required to use Map container.
 Show polymorphic programming by incorporating the functionality described in 13.12
(i.e., you are required to incorporate what is described in 10.12 using Map instead of
Vector).
 Use of multiple inheritance

Make sure you define abstract and concrete classes, and use multiple inheritance and
polymorphism appropriately.

Query Menu: You should provide appropriate menus for facilitating user interaction. Here are
some examples:

 Adding new Objects


 Deleting Objects
 Searching for particular object based on criteria (e.g., SSN)
 Earnings for each University employee
 Listing objects of each category (e.g., Salaried employee, ResearchStaff, etc.)

You might also like