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 12! possible assignments of months to volunteers will have a desirability between 0 and 36. 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 20 characters, and ,, and are integers between 1 and 12.
OUTPUT:
A listing of the best possible calendar assignments found so far as your
program progresses through the permutations.
EXAMPLE OUTPUT:
SCORE: 12
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: 14
January Steve
February Julio
March Shilpa
...
I have most of the base code but I'm 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 ARRAY-BASED LIST ( unsorted.cpp )
void UnsortedType::UnsortedType()
// Pre: None.
// Post: List is empty.
{
length =0;
}
void UnsortedType::InsertItem(ItemType item)
// Pre: List has been initialized. List is not full.
// item is not in list.
// Post: item is in the list.
{
info[length]= 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 == MAX_ITEMS);
}
ItemType UnsortedType::GetItem(ItemType 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 =0;
found = false;
moreToSearch =(location length);
while (moreToSearch && !found)
{
switch (item.ComparedTo(info[location]))
{
case LESS:
case GREATER: location++;
moreToSearch =(location length);
case EQUAL: found = true;
item = info[location];
break;
}
}
return item
}
void UnsortedType::DeleteItem(ItemType 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 =0;
while (item.ComparedTo(info[location])!= EQUAL)
location++;
// move last element into position where item was located
info[location]= info[length -1];
length--;
}
// SPECIFICATION FILE ( itemtype.h )
const int MAX_ITEMS =5;
enum RelationType { LESS, EQUAL, GREATER };
class ItemType // declares class data type
{
public: //3 public member functions
RelationType ComparedTo(ItemType) const;
void Print() const;
void Initialize(int number);
private: //1 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:
//8 public member functions
bool IsFull() const;
int GetLength() const; // returns length of list
ItemType GetItem(ItemType item, bool& found);
void PutItem(ItemType item);
void DeleteItem(ItemType item);
void ResetList();
void UnsortedType();
ItemType GetNextItem();
private:
//3 private data members
int length;
ItemType info[MAX_ITEMS];
int currentPos;
};
 I have an assignment in C++ that starts with: A certain

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!