Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ASAP! ONLY IN C++! PLEASE NEAT WRITTEN AND READ CAREFULLY! I AM HAVING TROUBLE ON THIS! PLEASE HELP! THANK YOU! WILL GIVE THUMB UP

PLEASE ASAP! ONLY IN C++! PLEASE NEAT WRITTEN AND READ CAREFULLY! I AM HAVING TROUBLE ON THIS! PLEASE HELP! THANK YOU! WILL GIVE THUMB UP IF SATISTIED!

Write a program in C++ language that implements an English Dictionary using Doubly Linked List and OOP concepts. This assignment has five parts: 1- Write a class(new type) to define the Entry type that will hold the word and its definition. 2- Define the Map or Dictionary ADT using the interface in C++. 3- Implement the interface defined on point 2 using Doubly Linked List, which will operate with Entry type. Name this class NodeDictionaryG. Do not forget to create the Node (DNodeG class) for the doubly linked list. 4- Implement the EnglishDictioanry class. 5- Test it in the main function All Constructors should use the initializer list. You must submit in total a minimum of 6 files, min 5 for coding and 1 pdf file with the explanation. 1. Entry class The class should be designed in such a way that can store any type of key and any type of value. In this implementation, we will use it to store . Member variables: K _key;//English word (key) V _value;//word definition (value) Member functions: Entry(K, V); virtual ~ Entry (); K getK (); V getV (); void setK(K); void setV(V); Answer the questions below before implementing class Entry: Which methods should be public and which ones can be private? Should data members be public or private? 2. Define the Map or Dictionary ADT using the interface in C++, the interface should be designed to hold any type. You can find the list of operations in lesson 11 (Map ADT) and lesson 12 (Dictionary ADT) posted on the blackboard. Note: if you define Map ADT you should add the extra operations that Dictionary ADT has during the implementation of the Map interface. 3. Implement the interface defined in point 2 using Doubly Linked List. You can find the C++ header file in lesson 12. You have to make additional implementations as required for new types. NodeDictionaryG class Member variables: int uniqueKeys; //the current number of unique keys in the Dictionary int size // the total number of entries DNodeG* header; // head-of-list sentinel DNodeG* trailer; // tail-of-list sentinel Member functions: NodeDictionaryG (); virtual ~ NodeDictionaryG (); int size() const; // returns the number of nodes int uniqueKeys() const; // returns the current number of unique keys in the Dictionary bool empty() const; // is the list empty IteratorG begin() const; // beginning position IteratorG end() const; // (just beyond) last position IteratorG find(K) const; // returns an iterator that points to the first entry with key k IteratorG put(K, V); // insert pair (k,v) void erase(K& k); // remove the first entry with key k void erase(IteratorG); // erase entry at Iterator void erase(Range); // erase entry at range Range findAll(K); //returns the range for a key void print(Range); //prints all Entries in range Answer the questions below before implementing NodeDictionaryG class: Which methods should be public and which ones should be private? Should data members be public or private? Should we create getters and setters methods for member variables? For which member makes sense to implement them? Implement them. Note: The IteratorG class is defined in lesson 7. The Range type is the type defined in lesson 12. 4. Implement the EnglishDictioanry class using the NodeDictionaryG class operations. The EnglishDictioanry class should have at least the following functions and member variables: EnglishDictionary class Member variables: string name; //will hold the name of the English dictionary NodeDictionaryG dictionary; //will hold the words and their definitions Member functions: EnglishDictionary (string); virtual ~ EnglishDictionary (); int words() const; // number of words in dictionary int uniqueWords() const; // number of unique words in dictionary bool empty() const; // is the dictionary empty void add(Entry) // adds a word with its definition in the dictionary void deleteFirst(string) // removes the first word equal to a given string void delete(string) // removes from dictionary all the words equal to a given string void printDictionary(bool) //prints all words and definitions. If bool is true print from the beginning, else print them from the end of the dictionary (this function should be designed as a recursive function). void printDictionary (string) //prints the definitions for a given word (this function should be designed as a recursive function). Entry find(string) // returns the first word and its definition equal to a given string Answer the questions below before implementing EnglishDictionary class: Which methods should be public and which ones should be private? Should data members be public or private? Should we create getters and setters methods for member variables? For which member makes sense to implement them? Implement them. 5. Test it in the main function Create e English Dictionary with 10 words and their definitions, with word repetition as {3 definitions, 4 definitions, 1 definition, 2 definitions). Print the list of all words and definitions, starting from the beginning. Print the list of all words and definitions, starting from the end. Print the definitions for the word with 2 definitions, starting from the beginning of the range. Print the definitions for the word with 2 definitions, starting from the end of the range. Remove the first definition from the word that has 3 definitions. Search for the word that has 4 definitions and print them all. Remove the first definition from the word that has 4 definitions. Remove all the definitions from the word that has 2 definitions (you have two words that have 2 definitions remove both). Print the list of all words and definitions, starting from the beginning. Print the list of all words and definitions, starting from the end.

My Current Code(Separate Files)

***I need to implement EnglishDictionaryG.cpp and NodeDictionary.cpp ***

***Most of the code need to be exactly how it is like EnglishDictionaryG.h, Entry.h, NodeDictionaryG.h)

***Don't add new items or change codes even the .h files***

Implement Only EnglishDictionaryG.cpp and NodeDictionaryG.cpp

EnglishDictionaryG.h

#ifndef ENGLISHDICTIONARYG_H_ #define ENGLISHDICTIONARYG_H_

#include #include using namespace std;

class EnglishDictionaryG { private: string name; //will hold the name of the English dictionary EnglishDictionaryG dictionary; //will hold the words and their definitions public: EnglishDictionaryG(string); virtual ~EnglishDictionaryG(); int words() const; // number of words in dictionary int uniqueWords() const; // number of unique words in dictionary bool empty() const; // is the dictionary empty void add(Entry); // adds a word with its definition in the dictionary void deleteFirst(string); // removes the first word equal to a given string void deleteWord(string); // removes from dictionary all the words equal to a given string void printDictionary(bool) const; //prints all words and definitions. If bool is true print from the beginning, else print them from the end of the dictionary (this function should be designed as a recursive function). void printDictionary (string) const; //prints the definitions for a given word (this function should be designed as a recursive function). Entry find(string) const; // returns the first word and its definition equal to a given string };

#endif /* ENGLISHDICTIONARYG_H_ */

Entry.cpp

#include #include "Entry.h" using namespace std;

// Constructor template Entry::Entry(K key, V value) : _key(key), _value(value) {}

// Destructor template Entry::~Entry() {}

// Getter for key template K Entry::getK() const { return _key; }

// Getter for value template V Entry::getV() const { return _value; }

// Setter for key template void Entry::setK(K key) { _key = key; }

// Setter for value template void Entry::setV(V value) { _value = value; }

// Explicit instantiation for specific types template class Entry; // Add more explicit instantiations for other types if needed template class Entry; template class Entry;

Entry.h

#ifndef ENTRY_H_ #define ENTRY_H_

using namespace std;

template class Entry { private: K _key;//English word (key) V _value;//word definition (value) public: Entry(K, V); // Constructor virtual ~Entry(); // Destructor K getK() const; V getV() const; void setK(K); void setV(V); };

#endif /* ENTRY _H_ */

NodeDictionaryG.h

#ifndef NODEDICTIONARYG_H_ #define NODEDICTIONARYG_H_

#include #include #include "DNodeG.h" using namespace std;

template class NodeDictionaryG { private: int uniqueKeys; //the current number of unique keys in the Dictionary int size; // the total number of entries DNodeG* header; // head-of-list sentinel DNodeG* trailer; // tail-of-list sentinel

public: NodeDictionaryG(); virtual ~ NodeDictionaryG (); int getSize() const; // returns the number of nodes int getUniqueKeys() const; // returns the current number of unique keys in the Dictionary bool empty() const; // is the list empty IteratorG begin() const; // beginning position IteratorG end() const; // (just beyond) last position IteratorG find(K) const; // returns an iterator that points to the first entry with key k IteratorG put(K, V); // insert pair (k,v) void erase(K& k); // remove the first entry with key k void erase(IteratorG); // erase entry at Iterator void erase(Range); // erase entry at range Range findAll(K); //returns the range for a key void print(Range); //prints all Entries in range };

#endif /* NODEDICTIONARYG_H_ */

MapDictionaryInterface.h

#ifndef MAPDICTIONARYINTERFACE_H_ #define MAPDICTIONARYINTERFACE_H_

template class MapDictionaryInterface { // map interface public: virtual ~ MapDictionaryInterface() = default;

virtual int size() const = 0; // number of entries in the map virtual bool empty() const = 0; // is the map empty? virtual I find(const K& k) const = 0;; // find entry with key k virtual I put(const K& k, const V& v) = 0; // insert/replace pair (k,v) virtual void erase(const K& k) = 0; // remove entry with key k virtual void erase(const I& p) = 0; // erase entry at p virtual I begin() const = 0; // iterator to first entry virtual I end() const = 0; // iterator to end entry };

#endif /* MAPDICTIONARYINTERFACE_H_ */

#ifndef DNODEG_H_ #define DNODEG_H_

#include #include "NodeDictionaryG.h" using namespace std;

template class DNodeG { public: K key; V value; DNodeG* prev; DNodeG* next;

DNodeG(const K& k, const V& v) : key(k), value(v), prev(nullptr), next(nullptr) {} };

template class IteratorG { public: DNodeG* node;

IteratorG(DNodeG* n) : node(n) {}

// Overload the increment operator (++it) IteratorG& operator++() { if (node != nullptr) { node = node->next; } return *this; }

// Overload the dereference operator (*it) DNodeG& operator*() const { return *node; }

// Overload the arrow operator (it->) DNodeG* operator->() const { return node; }

// Overload the equality operator (it == it) bool operator==(const IteratorG& other) const { return node == other.node; }

// Overload the inequality operator (it != it) bool operator!=(const IteratorG& other) const { return !(*this == other); } };

template class Range { public: IteratorG start; IteratorG end;

Range(const IteratorG& s, const IteratorG& e) : start(s), end(e) {}

IteratorG getStart() const { return start; }

IteratorG getEnd() const { return end; } };

template class NodeMapG;

template class IteratorG;

template class Entry;

template class DNodeG{ private: Entry elm; DNodeG *next; DNodeG *prev;

friend class NodeMapG; friend class IteratorG; };

#endif /* DNODEG_H_ */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago