Question: I have an assignment in C + + that starts with: A certain charity recruits twelve volunteers each year to spearhead its fundraising efforts. Each
I have an assignment in C that starts with:
A certain charity recruits twelve volunteers each year to spearhead its fundraising efforts. Each volunteer is assigned one month to take the lead organizing events. As these are bolunteers, the charity does it best to accommodate everyone's schedule as much as possible. Before the year begins, each volunteer is asked to give his or her top three choices for a month to serve. These preferences are likely to overlap. For example:
Obviously both Susan and John cannot be assigned December; one of them will need to be assigned a different month. The best possible assignment for the three volunteers ignoring the other nine for the moment would be
Susan February
John December
Mary March
as John and Mary get their first choice and Susan receives her second. For twelve volunteers, the task above is humanly unmanageable, and so the charity has contacted you to automate this process for them.
The charity proposes that the following point system be used when determining the desirability of a particular month assignment to its volunteers: Thus, each of the possible assignments of months to volunteers will have a desirability between and Your task is to find the best calendar assignment.
It also requires:
INPUT:
The names of the twelve volunteers followed by their month preferences. The
information for each volunteer will be listed on a single line in the file
"volunteers.dat" in the following format:
where is a string of up to characters, and and are integers between and
OUTPUT:
A listing of the best possible calendar assignments found so far as your
program progresses through the permutations.
EXAMPLE OUTPUT:
SCORE:
January Yuen
February Bill
March Steve
April Alice
May Susan
June Julio
July Gary
August Mike
September Mary
October Rich
November Shilpa
December Ann
SCORE:
January Steve
February Julio
March Shilpa
I have most of the base code but Im having trouble piecing it all together and debugging errors that I don't know how to solve. so I would like help in finalizing it Included is my base code along with two h files it uses.
#include
#include
#include
#include "UnsortedType.h
#include "ItemType.h
IMPLEMENTATION FILE ARRAYBASED LIST unsorted.cpp
void UnsortedType::UnsortedType
Pre: None.
Post: List is empty.
length ;
void UnsortedType::InsertItemItemType item
Pre: List has been initialized. List is not full.
item is not in list.
Post: item is in the list.
infolength item;
length;
int UnsortedType::GetLength const
Pre: List has been inititalized.
Post: Function value number of elements in
list
return length;
bool UnsortedType::IsFull const
Pre: List has been initialized.
Post: Function value list is full
return length MAXITEMS;
ItemType UnsortedType::GetItemItemType item, bool& found
Pre: Key member of item is initialized.
Post: If found, items key matches an elements key in the list
and a copy of that element is returned;
otherwise, input item is returned.
bool moreToSearch;
int location ;
found false;
moreToSearch location length;
while moreToSearch && found
switch itemComparedToinfolocation
case LESS:
case GREATER: location;
moreToSearch location length;
case EQUAL: found true;
item infolocation;
break;
return item
void UnsortedType::DeleteItemItemType item
Pre: items key has been inititalized.
An element in the list has a key that matches items
Post: No element in the list has a key that matches items
int location ;
while itemComparedToinfolocation EQUAL
location;
move last element into position where item was located
infolocation infolength ;
length;
SPECIFICATION FILE itemtype.h
const int MAXITEMS ;
enum RelationType LESS, EQUAL, GREATER ;
class ItemType declares class data type
public: public member functions
RelationType ComparedToItemType const;
void Print const;
void Initializeint number;
private: private data member
int value; could be any different
type, including a class
;
SPECIFICATION FILE unsorted.h
#include "ItemType.h
class UnsortedType declares a class data type
public:
public member functions
bool IsFull const;
int GetLength const; returns length of list
ItemType GetItemItemType item, bool& found;
void PutItemItemType item;
void DeleteItemItemType item;
void ResetList;
void UnsortedType;
ItemType GetNextItem;
private:
private data members
int length;
ItemType infoMAXITEMS;
int currentPos;
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
