Question

== Programming Assignment == For this assignment you will write a program that reads in the...

== Programming Assignment == For this assignment you will write a program that reads in the family data for the Martian colonies and stores that data in an accessible database. This database allows for a user to look up a family and its immediate friends. The program should store the data in a hashtable to ensure quick access time. The objective of this assignment is to learn how to implement and use a hashtable. Since this is the objective, you cannot use a premade hashtable (e.g. the STL map class). Note: there is an advanced version of this program (for no additional credit) that also adds the feature of finding ALL friends, friends of friends, etc. until a certain group size it met. == Program Design == Your program should use good design methodologies so you should have separate classes for each of the following: - family -- This class represents a family. Each family has a family ID (guaranteed to be unique), a family name (not unique), a number of family members, and a list of 0-3 friends. The friends are identified by their associated family ID. - hashtable -- This is the data storage for family data. It is a hash table that contains families. It supports the ability to lookup a family and an ability to insert a family. (Remove is not needed for this assignment). For debugging purposes, this class also needs to have a "dumpTable()" method that will print out the contents of the hashtable. - familymgr -- This class is the interface to the main program for handing family data. The family manager has a method to add families to the database. It can also print a list of all known families. The primary value of the family manager is that, given a family id, it can look up that family and all of the friends of that family. This functionality is meant to be used by the HR group to make housing assignments. The simple functionality for this assignment takes a family and prints out only the immediate friends. The advanced version will print the full transitive closure of all friends from a given family up to a given group size limit. == Other Files == I have provided two test programs: testfamily.cpp and testhashtable.cpp. These are for your use. You are not required to use them but they will be helpful for developing and debugging your classes. Finally, for your convenience I have provided a "makefile". If you name all of your files the same as I have then you can use the following makefile to simplify your building and testing. Using the makefile is optional. You are welcome to modify it anyway you want. You do not need to turn in the makefile. == External Requirements == - The main driver (housinghelper.cpp) will add families to your family manager. When all of the families have been added the driver program will ask the family manager class to print out a list of all of the families. After that, it calls the method to print out the family and immediate friends for a few families. - The output from your program must match expected.txt exactly. == Internal Requirements == - The program must use the supplied housinghelper.cpp file, unmodified, as the main driver. - The program must store all families in a hashtable. - The hashtable must use linked list chaining to deal with hash collisions. New items should be added to the front of the linked list. - The hashtable hashing function should use the method discussed in the book and in class. That is: s[0] + s[1]*32 + s[2]*32^2 + s[3]*32^3 + ... s[n-1]*32^n-1 Hint: when calculating the hash value keep in mind each of these things: 1) Use the ASCII values of the letters (e.g. "A" = 65). 2) The hash index needs to be an unsigned integer (e.g. size_t). 3) Apply the modulus operator AFTER summing and multiplying all of the numbers. - The hashtable hash function must use Horner's rule to refactor the calculation to make it more efficient (you cannot use the pow() function or anything else like it). - The hashtable array size should be 7877 elements (that is a prime number). - You do not need to resize the table. - The should be no memory leaks. - All "string" data should be stored as char* variables. DO NOT USE std::string. some examples of family.txt (not the entire file) Family ID: Smith001 Name: Smith Members: 2 Friends: Ayala002 Goode001 --- Family ID: Smith002 Name: Smith Members: 4 Friends: Roderick003 --- Family ID: Johnson001 Name: Johnson Members: 4 Friends: Springer002 --- Family ID: Johnson002 Name: Johnson Members: 4 Friends: Harman001 Millard002 Hornsby001 --- Family ID: Johnson003 Name: Johnson Members: 2 Friends: Custer001 Aviles001 Haney001 --- Family ID: Williams001 Name: Williams Members: 2 Friends: Baylor002 Cleveland001 Kelley001 --- Family ID: Jones001 Name: Jones Members: 2 Friends: Quinonez001 Groce001 --- Family ID: Jones002 Name: Jones Members: 2 Friends: Cavazos001 --- Family ID: Jones003 Name: Jones Members: 4 Friends: Himes002 Guyton002 Macon001 --- Family ID: Brown001 Name: Brown Members: 3 Friends: Holland002 --- testfamily.cpp #include #include "family.h" using namespace std; void addFriendHelper(family& fam,const char* myfriend) { if (!fam.addFriend(myfriend)) { cout << "Too many friends for " << fam.getId() << endl; } } int main() { // Test some of the basic family functionality. Normally a test like this // should be self-checking but for this class I am just having it print to // screen since I think that will be more helpful for you (the students) family fam("Test001","Test",3); cout << fam; addFriendHelper(fam,"Friend001"); cout << fam; addFriendHelper(fam,"Friend002"); cout << fam; addFriendHelper(fam,"Friend003"); cout << fam; addFriendHelper(fam,"Friend004"); cout << fam; return(0); } testhashtable.cpp #include #include "hashtable.h" using namespace std; int main() { const int HASHTABLESIZE = 13; const int NUMFAMILIES = 50; hashtable ht(HASHTABLESIZE); cout << "======================================================================" << endl; cout << "Testing inserts (should show full table)" << endl; for (int i=0;iaddFriend(friendName); ht.insert(id,*familyPtr); delete familyPtr; } ht.dumpTable(); cout << "======================================================================" << endl; cout << "Testing searches (should show no errors)" << endl; const family* foundFam; foundFam = ht.lookup("Test44"); if (foundFam == nullptr) cout << "ERROR searching for Test44" << endl; foundFam = ht.lookup("Test39"); if (foundFam == nullptr) cout << "ERROR searching for Test39" << endl; foundFam = ht.lookup("Test999"); if (foundFam != nullptr) cout << "ERROR searching for Test999" << endl; cout << "======================================================================" << endl; cout << "Testing removes (should show empty table)" << endl; for (int i=0;i #include #include #include #include "familymgr.h" using namespace std; int main(int argc,char** argv) { if (argc != 2) { cout << "Usage: " << argv[0] << " " << endl; exit(0); } // family manager object; familymgr familyMgr; // Read the data const int MAX_LINE = 64; char* datafile = argv[1]; ifstream infile(datafile); char line[MAX_LINE]; char id[MAX_LINE]; char name[MAX_LINE]; int members; char friend1[MAX_LINE]; char friend2[MAX_LINE]; char friend3[MAX_LINE]; if (infile.is_open()) { while (infile.getline(line,MAX_LINE) ) { char* s; // ID -- Family ID: s = strchr(line,':') + 2; // Skip the space strncpy(id,s,MAX_LINE); // Name infile.getline(line,MAX_LINE); s = strchr(line,':') + 2; // Skip the space strncpy(name,s,MAX_LINE); // members infile.getline(line,MAX_LINE); s = strchr(line,':') + 2; // Skip the space members = atoi(s); // friends infile.getline(line,MAX_LINE); s = strchr(line,':') + 2; // Skip the space char* friendPtr; friendPtr = strtok(s," "); if (friendPtr != nullptr) strncpy(friend1,friendPtr,MAX_LINE); else friend1[0] = '\0'; friendPtr = strtok(nullptr," "); if (friendPtr != nullptr) strncpy(friend2,friendPtr,MAX_LINE); else friend2[0] = '\0'; friendPtr = strtok(nullptr," "); if (friendPtr != nullptr) strncpy(friend3,friendPtr,MAX_LINE); else friend3[0] = '\0'; infile.getline(line,MAX_LINE); if (strcmp(line,"---")!=0) { cout << "Error parsing the file" << endl; } // Add the family to the family manager family* famPtr = new family(id,name,members); famPtr->addFriend(friend1); famPtr->addFriend(friend2); famPtr->addFriend(friend3); familyMgr.addFamily(*famPtr); delete famPtr; } infile.close(); familyMgr.printAllFamilies(); // familyMgr.printGroup("Smith001"); familyMgr.printSmallCircle("Smith001"); familyMgr.printSmallCircle("Hall001"); familyMgr.printSmallCircle("Noel003"); } return(0); }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clas Hashtable: de nur- sel.size 100 en (s eluc: familymembeo l data thashualu J: desfa Chextrlet1l None mextulst-sell.iuhadamimbe data N stop&falre found fare poiten startsiet and net sto enos found = tylle

asttionulf suhashperition,.ten rely totl sutran do fondilymenbeudeta suoria M4.get. CKey farnar membeno). stop- Tsuwe am dtal

Add a comment
Know the answer?
Add Answer to:
== Programming Assignment == For this assignment you will write a program that reads in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • The following program is in c++ ; I am trying to read in games from a...

    The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :( --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void Business::addGamesFromFile() {...

  • == Programming Assignment == For this assignment you will write a program that controls a set...

    == Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

  • %%%%% c++ assignment %%%%%% ///////// please test your program and check for errors. //////// you should...

    %%%%% c++ assignment %%%%%% ///////// please test your program and check for errors. //////// you should use the file bellow For this assignment you will write a program that creates a tree of "plants". Each plant is the result of an exeperiment. I have provided the main driver program that is responsible for running each of the experiments but you will need to create a tree for storing the results. The objective of this assignment is to learn how to...

  • Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function...

    Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function has already been implemented for you. // hash.CPP program to implement hashing with chaining #include<iostream> #include "hash.hpp" using namespace std; node* HashTable::createNode(int key, node* next) { node* nw = new node; nw->key = key; nw->next = next; return nw; } HashTable::HashTable(int bsize) { this->tableSize= bsize; table = new node*[tableSize]; for(int i=0;i<bsize;i++) table[i] = nullptr; } //function to calculate hash function unsigned int HashTable::hashFunction(int key)...

  • Using C++ Use the below program. Fill in the code for the 2 functions. The expected...

    Using C++ Use the below program. Fill in the code for the 2 functions. The expected output should be: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: #include #include #include using namespace std; //Assume a line is less than 256 //Prints the characters in the string str1 from beginIndex //and inclusing endIndex void printSubString( const char* str1 , int beginIndex, int endIndex ) { } void printWordsInAString( const char* str1 ) { } int main() { char str1[] = "The fox jumps over the...

  • Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly...

    Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly linked lists", as well as "hashing with chaining using doubly linked lists". Notice this program is complete except it doesn't include the remove function. Write the remove function and test it with the rest of the program including the given main program. Upload your C++ source file. ---Here is the referenced program: "hashing with chaining using singly linked lists". Below this...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT