├── DictionaryApplication.exe ├── LICENSE ├── README.md └── DictionaryApplication.cpp /DictionaryApplication.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iakashchoudhary/Dictionary-Application/HEAD/DictionaryApplication.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Akash Choudhary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dictionary Application 2 | A C++ application that implements a dictionary using a hash table with linear probing. Provides functionality to add, search, delete words, and display the dictionary contents. 3 | 4 | ## Table of Contents 5 | 6 | - [Overview](#overview) 7 | - [Features](#features) 8 | - [Implementation Details](#implementation-details) 9 | - [Getting Started](#getting-started) 10 | - [Prerequisites](#prerequisites) 11 | - [Installation](#installation) 12 | - [Usage](#usage) 13 | - [Example Interaction](#example-interaction) 14 | - [Contributing](#contributing) 15 | - [License](#license) 16 | - [Contact](#contact) 17 | 18 | ## Overview 19 | 20 | This C++ console application provides a simple dictionary management system using a hash table with linear probing for collision resolution. Users can perform operations such as adding, searching, deleting, and displaying words and their meanings. 21 | 22 | ## Features 23 | 24 | - **Add Word**: Insert a new word and its meaning into the dictionary. 25 | - **Search Word**: Look up the meaning of a word in the dictionary. 26 | - **Delete Word**: Remove a word from the dictionary. 27 | - **Display Dictionary**: Show all words and their meanings currently stored in the dictionary. 28 | 29 | ## Implementation Details 30 | 31 | - **Hash Table Size**: Fixed at 5. 32 | - **Collision Resolution Method**: Linear probing. 33 | 34 | ## Getting Started 35 | 36 | ### Prerequisites 37 | 38 | - A C++ compiler (e.g., g++). 39 | - Basic understanding of C++ and hash tables. 40 | 41 | ### Installation 42 | 43 | 1. **Clone the Repository** 44 | 45 | ```bash 46 | git clone https://github.com/iakashchoudhary/Dictionary-Application.git 47 | 48 | 2. **Navigate to the Project Directory** 49 | 50 | ```bash 51 | cd Dictionary-Application 52 | 53 | 3. **Compile the Code** 54 | 55 | ```bash 56 | g++ -o Dictionary-Application DictionaryApplication.cpp 57 | 58 | 4. **Run the Application** 59 | 60 | ```bash 61 | ./DictionaryApplication 62 | 63 | ## Usage 64 | 65 | Upon running the application, you will be presented with a menu: 66 | 67 | 1. **Add Word:** Enter a word and its meaning to add to the dictionary. 68 | 69 | 2. **Search Word:** Enter a word to find its meaning. 70 | 71 | 3. **Delete Word:** Enter a word to remove it from the dictionary. 72 | 73 | 4. **Display Dictionary:** View all current entries in the dictionary. 74 | 75 | 5. **Exit:** Close the application. 76 | 77 | ### Example Interaction 78 | 79 | ![image](https://github.com/user-attachments/assets/56b041ff-fe40-419f-8348-e0757dc9bb7e) 80 | 81 | ![image](https://github.com/user-attachments/assets/cdb8ac02-c201-4e8c-b593-ce5348a58e68) 82 | 83 | 84 | ## Contributing 85 | 86 | Contributions are welcome! To contribute: 87 | 88 | 1. **Fork the Repository** 89 | 90 | Click on the "Fork" button at the top-right corner of the repository page on GitHub. 91 | 92 | 2. **Create a New Branch** 93 | 94 | ```bash 95 | git checkout -b feature-branch 96 | 97 | 3. **Make Your Changes** 98 | 99 | Edit the code or documentation as needed. 100 | 101 | 4. **Commit Your Changes** 102 | 103 | ```bash 104 | git commit -am 'Add new feature' 105 | 106 | 5. **Push to the Branch** 107 | 108 | ```bash 109 | git push origin feature-branch 110 | 111 | 6. **Create a Pull Request** 112 | 113 | Go to the repository on GitHub and create a new Pull Request from your branch. 114 | 115 | Please ensure that your code follows the project's coding standards and includes appropriate tests. 116 | 117 | ## License 118 | 119 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 120 | 121 | ## Contact 122 | 123 | For any questions or suggestions, please open an issue on GitHub or submit a pull request. 124 | -------------------------------------------------------------------------------- /DictionaryApplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Declaration of the Dictionary class 6 | class Dictionary { 7 | private: 8 | // Constants for the hash table 9 | static const int tableSize = 5; // Size of the hash table 10 | static const std::string EMPTY; // Placeholder for empty slots 11 | 12 | // HashNode represents each element in the hash table 13 | struct HashNode { 14 | std::string key; 15 | std::string value; 16 | }; 17 | 18 | // Hash table implemented as a vector of HashNode 19 | std::vector table; 20 | 21 | // Hash function to convert a key into an index in the hash table 22 | int hashFunction(const std::string& key); 23 | 24 | // Probing function for linear probing 25 | int linearProbe(int index); 26 | 27 | public: 28 | // Constructor initializes the hash table with empty slots 29 | Dictionary(); 30 | 31 | // Function to check whether the dictionary is empty 32 | bool isEmpty() const; 33 | 34 | // Function to add a word to the dictionary 35 | void addWord(const std::string& key, const std::string& value); 36 | 37 | // Function to search for a word in the dictionary 38 | std::string searchWord(const std::string& key); 39 | 40 | // Function to delete a word from the dictionary 41 | void deleteWord(const std::string& key); 42 | 43 | // Function to display hash values in the dictionary 44 | void displayDictionary(); 45 | }; 46 | 47 | // Initialization of the EMPTY constant 48 | const std::string Dictionary::EMPTY = ""; 49 | 50 | // Constructor definition 51 | Dictionary::Dictionary() : table(tableSize, {EMPTY, EMPTY}) {} 52 | 53 | // Hash function definition 54 | int Dictionary::hashFunction(const std::string& key) { 55 | int hash = 0; 56 | for (char ch : key) { 57 | hash += static_cast(ch); 58 | } 59 | return hash % tableSize; 60 | } 61 | 62 | // Probing function definition 63 | int Dictionary::linearProbe(int index) { 64 | return (index + 1) % tableSize; 65 | } 66 | 67 | // Function to check whether the dictionary is empty 68 | bool Dictionary::isEmpty() const { 69 | for (const auto& node : table) { 70 | if (node.key != EMPTY) { 71 | return false; // Hash table is not empty 72 | } 73 | } 74 | return true; // Hash table is empty 75 | } 76 | 77 | // Function to add a word to the dictionary 78 | void Dictionary::addWord(const std::string& key, const std::string& value) { 79 | int index = hashFunction(key); 80 | while (table[index].key != EMPTY) { 81 | index = linearProbe(index); 82 | if (index == hashFunction(key)) { 83 | std::cout << "Dictionary is full. Cannot add more words.\n"; 84 | return; 85 | } 86 | } 87 | table[index] = {key, value}; 88 | std::cout << "Word added to the dictionary.\n"; 89 | } 90 | 91 | // Function to search for a word in the dictionary 92 | std::string Dictionary::searchWord(const std::string& key) { 93 | int index = hashFunction(key); 94 | while (table[index].key != EMPTY) { 95 | if (table[index].key == key) { 96 | return table[index].value; 97 | } 98 | index = linearProbe(index); 99 | } 100 | return "Word not found"; 101 | } 102 | 103 | // Function to delete a word from the dictionary 104 | void Dictionary::deleteWord(const std::string& key) { 105 | int index = hashFunction(key); 106 | while (table[index].key != EMPTY) { 107 | if (table[index].key == key) { 108 | table[index] = {EMPTY, EMPTY}; 109 | std::cout << "Word deleted from the dictionary.\n"; 110 | return; 111 | } 112 | index = linearProbe(index); 113 | } 114 | std::cout << "Word not found. Cannot delete.\n"; 115 | } 116 | 117 | // Function to display hash values in the dictionary 118 | void Dictionary::displayDictionary() { 119 | for (int i = 0; i < tableSize; ++i) { 120 | std::cout << "[" << i << "]"; 121 | if (table[i].key != EMPTY) { 122 | std::cout << " -> {" << table[i].key << ": " << table[i].value << "}"; 123 | } 124 | std::cout << std::endl; 125 | } 126 | } 127 | 128 | // Entry point of the program 129 | int main() { 130 | // Create an instance of the Dictionary class 131 | Dictionary dictionary; 132 | 133 | // Variables for user input 134 | int choice; 135 | std::string word, meaning; 136 | 137 | // Display initial message 138 | std::cout << "\nDictionary Application\n"; 139 | 140 | // Main loop for user interaction 141 | do { 142 | // Display menu 143 | std::cout << "\n1. Add Word 2. Search Word 3. Delete Word 4. Display Dictionary 5. Exit" 144 | << "\nEnter your choice: "; 145 | 146 | // Get user choice 147 | std::cin >> choice; 148 | std::cin.ignore(std::numeric_limits::max(), '\n'); // Clear input buffer 149 | 150 | // Switch statement to handle user choices 151 | switch (choice) { 152 | case 1: 153 | // Add Word 154 | std::cout << "\nEnter word: "; 155 | std::getline(std::cin, word); 156 | std::cout << "Enter meaning: "; 157 | std::getline(std::cin, meaning); 158 | dictionary.addWord(word, meaning); 159 | break; 160 | 161 | case 2: 162 | // Search Word 163 | if (dictionary.isEmpty()) { 164 | std::cout << "\nDictionary is empty. Add words first.\n"; 165 | } else { 166 | std::cout << "\nEnter word to search: "; 167 | std::getline(std::cin, word); 168 | std::cout << "Search Result: " << dictionary.searchWord(word) << std::endl; 169 | } 170 | break; 171 | 172 | case 3: 173 | // Delete Word 174 | if (dictionary.isEmpty()) { 175 | std::cout << "\nDictionary is empty. Add words first.\n"; 176 | } else { 177 | std::cout << "\nEnter word to delete: "; 178 | std::getline(std::cin, word); 179 | dictionary.deleteWord(word); 180 | } 181 | break; 182 | 183 | case 4: 184 | // Display Dictionary 185 | if (dictionary.isEmpty()) { 186 | std::cout << "\nDictionary is empty. Add words first.\n"; 187 | } else { 188 | std::cout << "\nDictionary Table:\n"; 189 | dictionary.displayDictionary(); 190 | } 191 | break; 192 | 193 | case 5: 194 | // Exit 195 | std::cout << "\nExiting program.\n"; 196 | break; 197 | 198 | default: 199 | std::cout << "\nInvalid choice. Please try again.\n"; 200 | } 201 | } while (choice != 5); 202 | 203 | return 0; 204 | } 205 | --------------------------------------------------------------------------------