[SOLVED] CS30 Project 1-The Year of the Quarantine

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon BirthdayParty_HashTables-0pkqwe.zip (400.7 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Project 1:Β  The Year of the Quarantine

Apparently, 2020 didn’t get the memo.Β  Every year, we like to celebrate milestones.Β  That might be a graduation, whether it’s kindergarten, high school, or college.Β  There were supposed to be weddings, whether here or at a destination.Β  Most importantly, I was supposed to celebrate my 40th birthday during the summer.Β  Big blowout, big barbecue, friends getting back together, enjoying memories, great food, and maybe one (or more) adult beverages.Β  Alas, 2020 isn’t having any of that.Β  In fact, every celebration is pretty much being sponsored by Zoom, Google Meet, or WebEx.Β  In other words, it’s the Year of the Quarantine.Β  Nevertheless, I’m going to celebrate…and you’ll be celebrating with me.Β  I’m still going to have a big guest list, just virtually.

To help me out, you will write the implementation of the BirthdayParty using a doubly linked list, which should be sorted alphabetically according to last name, then first name. You will also implement a couple of algorithms that operate on a BirthdayParty.Β  Implement BirthdayParty

Consider the following BirthdayParty interface:

typedef std::string BirthdayType;

class BirthdayParty

{Β Β  public:

BirthdayParty();Β Β Β Β Β Β  // Create an empty BirthdayParty list

bool noInvitees() const;Β  // Return true if the BirthdayParty listΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // is empty, otherwise false.

int whosOnTheGuestList() const;Β  // Return the number of players in

// the BirthdayParty list.

bool addInvitee(const std::string& firstName, const std::string&Β Β  Β Β Β Β Β Β Β Β Β Β Β Β Β Β lastName, const BirthdayType& value);

// If the full name (both the first and last name) is not equal

// to any full name currently in the list then add it and return

// true. Elements should be added according to their last name.

// Elements with the same last name should be added according to

// their first names. Otherwise, make no change to the list andΒ Β Β Β Β Β  // return false (indicating that the name is already in theΒ Β Β Β Β Β Β  // list).

bool modifyInvitee(const std::string& firstName, const std::string& lastName, const BirthdayType& value);

// If the full name is equal to a full name currently in the

// list, then make that full name no longer map to the value itΒ Β Β Β Β Β Β  // currently maps to, but instead map to the value of the thirdΒ Β Β Β Β Β Β  // parameter; return true in this case. Otherwise, make noΒ Β Β Β Β Β Β  // change to the list and return false.

bool addOrModify(const std::string& firstName, const std::string& lastName, const BirthdayType& value);

// If full name is equal to a name currently in the list, then

// make that full name no longer map to the value it currently

// maps to, but instead map to the value of the third parameter;

// return true in this case. If the full name is not equal to

// any full name currently in the list then add it and returnΒ Β Β Β Β Β Β  // true. In fact, this function always returns true.

bool dropFromGuestList(const std::string& firstName, const std::string& lastName);

// If the full name is equal to a full name currently in the

// list, remove the full name and value from the list and returnΒ Β Β Β Β Β Β  // true.Β  Otherwise, make no change to the list and returnΒ Β Β Β Β Β Β  // false.

bool personOnGuestList(const std::string& firstName, const std::string& lastName) const;

// Return true if the full name is equal to a full nameΒ Β Β Β Β Β Β  // currently in the list, otherwise false.

bool checkGuestList(const std::string& firstName, const std::string& lastName, BirthdayType& value) const;

// If the full name is equal to a full name currently in the

// list, set value to the value in the list that that full nameΒ Β Β Β Β Β Β  // maps to, and return true.Β  Otherwise, make no change to theΒ Β Β Β Β Β Β  // value parameter of this function and return false.

bool selectInvitee(int i, std::string& firstName, std::string& lastName, BirthdayType& value) const;

// If 0 <= i < size(), copy into firstName, lastName and value

// parameters the corresponding information of the element at

// position i in the list and return true.Β  Otherwise, leave the

// parameters unchanged and return false. (See below for details

// about this function.)

Β 

void changeGuestList(BirthdayParty& other);

// Exchange the contents of this list with the other one. };

Β 

The addInvitee function primarily places elements so that they are sorted in the list based on last name. If there are multiple entries with the same last name then those elements, with the same last name, are added so that they are sorted by their first name. In other words, this code fragment

BirthdayParty theLastDance;

Β 

theLastDance.addInvitee (β€œMichael”, β€œJordan”, 23);Β Β Β Β  theLastDance.addInvitee (β€œScottie”, β€œPippen”, 33);Β Β Β Β  theLastDance.addInvitee (β€œDennis”, β€œRodman”, 91);Β Β Β Β  theLastDance.addInvitee (β€œLuc”, β€œLongley”, 13);Β Β Β Β  theLastDance.addInvitee (β€œRon”, β€œHarper”, 9);

for (int n = 0; n < theLastDance.whosOnTheGuestList(); n++)

{Β Β Β Β Β Β Β Β  string first;Β Β Β Β Β Β Β Β  string last;Β Β Β Β Β Β Β Β  int val;Β Β Β Β Β Β Β Β  theLastDance.selectInvitee (n, first, last, val);Β Β Β Β Β Β Β Β  cout << first << ” ” << last << ” ” << val << endl;

}

Β 

must result in the output:

Ron Harper 9

Michael Jordan 23Β Β Β Β  Luc Longley 13

Scottie Pippen 33

Dennis Rodman 91

Β 

Notice that the empty string is just as good a string as any other; you should not treat it in any special way:

BirthdayParty dodgers;Β Β Β Β  dodgers.addInvitee(β€œClayton”, β€œKershaw”, 31.0);Β Β Β Β  dodgers.addInvitee(β€œCody”, β€œBellinger”, 11.5);Β Β Β Β  assert(!dodgers.personOnGuestList (β€œβ€,””));Β Β Β Β  dodgers.addInvitee(β€œMookie”, β€œBetts”, 27.0);Β Β Β Β  dodgers.addInvitee(β€œβ€, β€œβ€, 0.57);Β Β Β Β  dodgers.addInvitee(β€œJustin”, β€œTurner”, 20.0);Β Β Β Β  assert(dodgers.personOnGuestList (β€œβ€, β€œβ€));Β Β Β Β  dodgers.dropFromGuestList(β€œMookie”, β€œBetts”);Β Β Β Β  assert(dodgers.whosOnTheGuestList() == 4

&& dodgers.personOnGuestList(β€œClayton”, β€œKershaw”)

&& dodgers.personOnGuestList (β€œCody”, β€œBellinger”)

&& dodgers.personOnGuestList (β€œJustin”, β€œTurner”)

&& dodgers.personOnGuestList (β€œβ€, β€œβ€));

When comparing keys for addInvitee, modifyInvitee, addOrModify, dropFromGuestList, personOnGuestList, and checkGuestList, just use the == or != operators provided for the string type by the library. These do case-sensitive comparisons, and that’s fine.

For this project, implement this BirthdayParty interface using a doubly-linked list. (You must not use any container from the C++ library.)

For your implementation, if you let the compiler write the destructor, copy constructor, and assignment operator, they will do the wrong thing, so you will have to declare and implement these public member functions as well:

Destructor

When a BirthdayParty is destroyed, all dynamic memory must be deallocated.

Copy Constructor

When a brand new BirthdayParty is created as a copy of an existing BirthdayParty, a deep copy should be made.

Assignment Operator

When an existing BirthdayParty (the left-hand side) is assigned the value of another BirthdayParty (the right-hand side), the result must be that the left-hand side object is a duplicate of the right-hand side object, with no memory leak (i.e. no memory from the old value of the left-hand side should be still allocated yet inaccessible).

Notice that there is no a priori limit on the maximum number of elements in the

BirthdayParty (so addOrModify should always return true). Also, if a BirthdayParty has a size of n, then the values of the first parameter to the selectInvitee member function are 0, 1, 2, …, n – 1; for other values, it returns false without setting its parameters.

Implement Some Non-Member Functions

Using only the public interface of BirthdayParty, implement the following two functions. (Notice that they are non-member functions; they are not members of BirthdayParty or any other class.)

bool combineGuestLists(const BirthdayParty & bpOne,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  const BirthdayParty & bpTwo,

BirthdayParty & bpJoined);

Β 

When this function returns, bpJoined must consist of pairs determined by these rules:

If a full name appears in exactly one of bpOne and bpTwo, then bpJoined must contain an element consisting of that full name and its corresponding value.

If a full name appears in both bpOne and bpTwo, with the same corresponding value in both, then bpJoined must contain an element with that full name and value.

When this function returns, bpJoined must contain no elements other than those required by these rules. (You must not assume bpJoined is empty when it is passed in to this function; it might not be.)

If there exists a full name that appears in both bpOne and bpTwo, but with different corresponding values, then this function returns false; if there is no full name like this, the function returns true. Even if the function returns false, result must be constituted as defined by the above rules.

For example, suppose a BirthdayParty maps the full name to integers. If bpOne consists of these three elements

β€œKobe” β€œBryant” 8Β Β  β€œAC” β€œGreen” 45 β€œShaquille” β€œOneal” 34Β Β Β  and bpTwo consists of

β€œKobe” β€œBryant” 8 β€œHorace” β€œGrant” 54

then no matter what value it had before, bpJoined must end up as a list consisting of

β€œKobe” β€œBryant” 8 β€œHorace” β€œGrant” 54 β€œAC” β€œGreen” 45

β€œShaquille” β€œOneal” 34

and combineGuestLists must return true.

If instead, bpOne consists of

β€œKobe” β€œBryant” 8Β Β  β€œAC” β€œGreen” 45 β€œShaquille” β€œOneal” 34 and bpTwo consists of

β€œKobe” β€œBryant” 24 β€œPau” β€œGasol” 16

then no matter what value it had before, bpJoined must end up as a list consisting of

β€œPau” β€œGasol” 16 β€œAC” β€œGreen” 45 β€œShaquille” β€œOneal” 34

Β 

and combineGuestLists must return false.

void verifyGuestList (const std::string& fsearch,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  const std::string& lsearch,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  const BirthdayParty& bpOne,

BirthdayParty& bpResult);

Β 

When this function returns, bpResult must contain a copy of all the elements in bpOne that match the search terms; it must not contain any other elements. You can wildcard the first name, last name or both by supplying β€œ*”. (You must not assume result is empty when it is passed in to this function; it may not be.)

For example, if memories consists of the three elements

β€œGianna” β€œBryant” 13Β Β  β€œKobe” β€œBryant” 41Β Β  β€œLittle” β€œRichard”

87Β Β  β€œJerry” β€œStiller” 92Β  and the following call is made:

verifyGuestList(β€œ*”, β€œBryant”, memories, bpResult);

then no matter what value it had before, bpResult must end up as a BirthdayParty consisting of

β€œGianna” β€œBryant” 13Β Β  β€œKobe” β€œBryant” 41

If instead, moreMemories were

β€œKirk” β€œDouglas” 103Β Β  β€œFred” β€œNeal” 77Β Β  β€œPop” β€œSmoke” 20

β€œFred” β€œWillard” 86

and the following call is made:

verifyGuestList(β€œFred”, β€œ*”, moreMemories, result);

then no matter what value it had before, result must end up as a list consisting of

β€œFred” β€œNeal” 77Β Β  β€œFred” β€œWillard” 86

If the following call is made:

verifyGuestList(β€œ*”, β€œ*”, memories, result);

then no matter what value it had before, result must end up being a copy of memories.

Be sure these functions behave correctly in the face of aliasing: What if moreMemories and result refer to the same BirthdayParty, for example?

Other Requirements

Regardless of how much work you put into the assignment, your program will receive a low score for correctness if you violate these requirements:

  • Your class definition, declarations for the two required non-member functions, and the implementations of any functions you choose to inline must be in a file named h, which must have appropriate include guards. The implementations of the functions you declared in BirthdayParty.h that you did not inline must be in a file named BirthdayParty.cpp. Neither of those files may have a main routine (unless it’s commented out). You may use a separate file for the main routine to test your BirthdayParty class; you won’t turn in that separate file.
  • Except to add a destructor, copy constructor, assignment operator, and dump function (described below), you must not add functions to, delete functions from, or change the public interface of the BirthdayParty You must not declare any additional struct/class outside the BirthdayParty class, and you must not declare any public struct/class inside the BirthdayParty class. You may add whatever private data members and private member functions you like, and you may declare private structs/classes inside the BirthdayParty class if you like. The source files you submit for this project must not contain the word friend. You must not use any global variables whose values may be changed during execution.
  • If you wish, you may add a public member function with the signature void dump() const. The intent of this function is that for your own testing purposes, you can call it to print information about the map; we will never call it. You do not have to add this function if you don’t want to, but if you do add it, it must not make any changes to the map; if we were to replace your implementation of this function with one that simply returned immediately, your code must still work correctly. The dump function must not write to cout, but it’s allowed to write to cerr.
  • Your code must build successfully (either Xcode or Visual C++) if linked with a file that contains a main routine, but it must also use standard C++.
  • You must have an implementation for every member function of

BirthdayParty, as well as the non-member functions combineGuestLists and verifyGuestList. Even if you can’t get a function implemented correctly, it must have an implementation that at least builds successfully. For example, if you don’t have time to correctly implement

BirthdayParty::dropFromGuestList or verifyGuestList, say, here

are implementations that meet this requirement in that they at least build successfully:

bool BirthdayParty::dropFromGuestList(const std::string& fname,Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  const std::string& lname)

{Β Β Β  return false; // not correct, but at least this code compiles

}

void verifyGuestList(const std::string& fsearch, const std::string&Β Β Β Β  lsearch, const BirthdayParty& bpOne, BirthdayParty& bpResult)

{Β Β Β  return; // not correct, but at least this code compiles }

Β 

You’ve probably met this requirement if the following file compiles and links with your code. (This uses magic beyond the scope of CS 30.)

#include β€œBirthdayParty.h”

#include <type_traits>

Β 

#define CHECKTYPE(f, t) { auto p = (t)(f); (void)p; }

static_assert(std::is_default_constructible<BirthdayParty>::valu e,

β€œMap must be default-constructible.”);

static_assert(std::is_copy_constructible<BirthdayParty>::value,

β€œMap must be copy-constructible.”);

void ThisFunctionWillNeverBeCalled()

{

CHECKTYPE(&BirthdayParty::operator=, BirthdayParty&

(BirthdayParty::*)(const BirthdayParty&));

CHECKTYPE(&BirthdayParty::noInvitees, bool

(BirthdayParty::*)() const);

CHECKTYPE(&BirthdayParty::whosOnTheGuestList, int

(BirthdayParty::*)() const);

CHECKTYPE(&BirthdayParty::addInvitee, bool (BirthdayParty::*)

(const std::string&, const std::string&, const

BirthdayType&));

CHECKTYPE(&BirthdayParty::modifyInvitee, bool

(BirthdayParty::*)(const std::string&, const std::string&,Β Β Β Β Β Β Β Β  const BirthdayType&));

CHECKTYPE(&BirthdayParty::addOrModify, bool

(BirthdayParty::*)(const std::string&, const std::string&,Β Β Β Β Β Β Β Β  const BirthdayType&));

CHECKTYPE(&BirthdayParty::dropFromGuestList, bool

(BirthdayParty::*)

(const std::string&, const std::string&));

CHECKTYPE(&BirthdayParty::personOnGuestList, bool

(BirthdayParty::*)(const std::string&, const std::string&)Β Β Β Β Β Β Β Β  const);

CHECKTYPE(&BirthdayParty::checkGuestList, bool

(BirthdayParty::*)

(const std::string&, const std::string&, BirthdayType&) const);

CHECKTYPE(&BirthdayParty::selectInvitee, bool

(BirthdayParty::*)

(int, std::string&, std::string&, BirthdayType&)Β Β Β Β Β Β Β Β  const);

CHECKTYPE(&BirthdayParty::changeGuestList, void

(BirthdayParty::*)(BirthdayParty&));

Β 

CHECKTYPE(combineGuestLists,Β  bool (*)(const BirthdayParty&, const

BirthdayParty&, BirthdayParty&));

CHECKTYPE(verifyGuestList, void (*)(const std::string&,Β Β Β Β Β  const std::string&, const BirthdayParty&, BirthdayParty&));

}

int main()

{}

Β 

If you add #include <string> to BirthdayParty.h, have the typedef define

BirthdayType as std::string, and link your code to a file containing

#include β€œBirthdayParty.h”

#include <string>

#include <iostream> #include <cassert> using namespace std;

Β 

void test()

{

BirthdayParty aListCommissioners;

assert(aListCommissioners.addInvitee(β€œAdam”, β€œSilver”,

β€œ[email protected]”));Β  Β Β assert(aListCommissioners.addInvitee(β€œRoger”, β€œGoodell”,

β€œ[email protected]”));Β Β Β  assert(aListCommissioners.whosOnTheGuestList() == 2);

string first, last, e;

assert(aListCommissioners.selectInvitee(0, first, last, e)

&& e == β€œ[email protected]”);Β Β Β  assert(aListCommissioners.selectInvitee(1, first, last, e)

&& (first == β€œAdam” && e == β€œ[email protected]”));

return; }

int main() {Β Β Β  test();Β Β Β  cout << β€œPassed all tests” << endl;Β Β Β  return 0;

}

Β 

the linking must succeed. When the resulting executable is run, it must write Passed all tests to cout and nothing else to cout.

If we successfully do the above, then make no changes to BirthdayParty.h other than to change the typedefs for BirthdayParty so that BirthdayType specifies int, recompile BirthdayParty.cpp, and link it to a file containing

#include ” BirthdayParty.h”

#include <string>

#include <iostream> #include <cassert> using namespace std;

Β 

void test()

{

BirthdayParty terribleCommissioners;

assert(terribleCommissioners.addInvitee(β€œGary”, β€œBettman”,

68));Β Β Β  assert(terribleCommissioners.addInvitee(β€œRobert”, β€œManfred”,

61));Β Β Β  assert(terribleCommissioners.whosOnTheGuestList() == 2);

string first, last;Β Β Β  int a;Β Β Β Β  assert(terribleCommissioners.selectInvitee(0, first, last, a)

&& a == 68);Β Β Β  assert(terribleCommissioners.selectInvitee(1, first, last, a)

&& (first == β€œRobert” && a == 61));

return;

}Β  int main() {Β Β Β  test();Β Β Β  cout << β€œPassed all tests” << endl;Β Β Β  return 0;

}

Β 

the linking must succeed. When the resulting executable is run, it must write Passed all tests to cout and nothing else to cout.

During execution, if a client performs actions whose behavior is defined by this spec, your program must not perform any undefined actions, such as dereferencing a null or uninitialized pointer.

Your code in BirthdayParty.h and BirthdayParty.cpp must not read anything from cin and must not write anything whatsoever to cout. If you want to print things out for debugging purposes, write to cerr instead of cout. cerr is the standard error destination; items written to it by default go to the screen. When we test your program, we will cause everything written to cerr to be discarded instead β€” we will never see that output, so you may leave those debugging output statements in your program if you wish.

1 file Β· 400.7 KB

  • BirthdayParty_HashTables-0pkqwe.zip 400.7 KB