Question

Vliestion (1) while make testman I will generate an executable called Testman IX to test your program for Question (2). If yo

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

//C++ program

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

bool linearSearch(const vector<string> dictionary , int &pos, string aWord , int &count){
   pos = -1;
   for(int i=0;i<dictionary.size();i++){
       count++;
       if(dictionary[i] == aWord){
           pos = i;
           return true;
       }
   }
   return false;
}

void myAdd(vector<string> & dictionary, string aWord){
   for(int i=0;i<dictionary.size();i++){
       if(dictionary[i] == aWord){
           cout<<aWord<<" is already added\n";
           return ;
       }
   }
   dictionary.push_back(aWord);
   cout<<aWord<<" is added\n";

}

void myDelete(vector<string> & dictionary, string aWord){
   vector<string>::iterator it;
it = dictionary.begin();
   for(it = dictionary.begin(); it != dictionary.end(); ++it)
       if(*it == aWord)break;
  
   if(it== dictionary.end()){
       cout<<aWord<<" is not found\n";
       return ;
   }
   dictionary.erase(it);
   cout<<aWord<<" is deleted\n";
  
}

void mySearch(vector<string> dictionary, string aWord){
   int count=0 , i;
   for( i=0;i<dictionary.size();i++){
       count++;
       if(dictionary[i] == aWord)break;
   }
   if (i != dictionary.size())
       cout<<aWord<<" is found\n";
   else cout<<aWord<<" is not found\n";
  
   cout<<"Total comparisions : "<<count<<"\n\n";
}

void myList(vector<string> dictionary){
   for(int i=0;i<dictionary.size();i++){
       cout<<dictionary[i]<<"\n";
   }
   cout<<"\n\n";
}

void myExit(){
   cout<<"bye bye\n\n";
}

int main(){
   string aWord , command;
   vector<string> dictionary;
   int wordCount=0;
  
   while(1){
       cin>>command;
      
       if(command == "ADD"){
           cin>>aWord;
           myAdd(dictionary ,aWord);
       }
      
       else if(command == "DELETE"){
           cin>>aWord;
           myDelete(dictionary ,aWord);
       }
       else if(command == "SEARCH"){
           cin>>aWord;
           mySearch(dictionary ,aWord);
       }
       else if(command == "LIST"){
           myList(dictionary);
       }
       else if(command == "EXIT"){
           myExit();
           break;
       }
       else{
           cout<<"Invalid command\n";
       }
   }
  
   return 0;
}

//sample output

C:\Users\IshuManish\Documents\dictionaory.exe ADD Java Java is added. ADD Java Java is already added ADD Python Python is add

Add a comment
Know the answer?
Add Answer to:
Vliestion (1) while make testman I will generate an executable called Testman IX to test your...
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
  • In this assignment you will implement the second version of your spell checker. Using the randomi...

    In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry...

    Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...

  • Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for...

    Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for push_back() function as below: void push_back(string str) { // increase vector size by one // initialize the new element with str } In addition, the standard library vector doesn't provide push_front(). Implement push_front() for your vector. Test your code with the main function below. int main() {    vector v1(3);    cout<<"v1: ";    v1.print(); // this should display -, -, -    for...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

  • / Animal.hpp #ifndef ANIMAL_H_ #define ANIMAL_H_ #include <string> class Animal { public: Animal(); Animal(std::string, bool domestic=false,...

    / Animal.hpp #ifndef ANIMAL_H_ #define ANIMAL_H_ #include <string> class Animal { public: Animal(); Animal(std::string, bool domestic=false, bool predator=false); std::string getName() const; bool isDomestic() const; bool isPredator() const; void setName(std::string); void setDomestic(); void setPredator(); protected: // protected so that derived class can directly access them std::string name_; bool domestic_; bool predator_; }; #endif /* ANIMAL_H_ */ //end of Animal.h // /////////////////////////////////////////////////////////////////Animal.cpp #include "Animal.h" Animal::Animal(): name_(""),domestic_(false), predator_(false){ } Animal::Animal(std::string name, bool domestic, bool predator): name_(name),domestic_(domestic), predator_(predator) { } std::string Animal::getName() const{ return...

  • Introduction In this lab, you are supposed to implement a graph class with the data structure...

    Introduction In this lab, you are supposed to implement a graph class with the data structure implemented before like linked list and queue. graph The class graph contains three member variables: linkedList *adjacentVertices; //an array of linked list. For a vertice i, adjacentVertices[i] stores the linked list that contains all other vertices connected to vertice i. int numVertices; //The number of vertices in the graph. int maxNumVertices; //The maximum number of vertices the graph can hold. Following public methods are...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • in c++ Program 1 Write a program that sorts a vector of names alphabetically using the...

    in c++ Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...

  • Name the program for this assignment "bst_driver.cpp." In this assignment you will make several modifications to...

    Name the program for this assignment "bst_driver.cpp." In this assignment you will make several modifications to the BST class in the file “bst.cpp” that I provided. Consider the following: 1. Change the declaration of treenode to class treenode //node in a BST { public: string county_name; double population_size; treenode *lchild, *rchild; //left and right children pointers }; 2. Make the following changes to the BST class: a) change the name from “BST” to “bst”; b) change default constructor from “BST”...

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