Question

In: Computer Science

In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou...

In the assignment you will use the vector class tomanage a dynamic array.After completing this assignmentyou will be able to • use thevector classto implement programs; • using iteratorsto morethrough a vector; • use pointers to a vector; • use member functions of thevector class. Assignment Description: Call your driver "vector_test_driver.cpp", your classdeclaration file “vlist.h” and your class implementation file "vlist.cpp". Define the following behavior for vlist 1. Implement a default constructor. Include the followingmessage, "Default Constructor Invoked" every time the function is called. 2. Implement a copy constructor to perform a deep copy of a vlist object.Include the following message, "Copy Constructor Invoked" every time the function is called.The function should also print the contents of each vlist object on single separate lines. 3. Implement the destructor. Include the followingmessage, "DestructorInvoked" every time the function is called. 4. Implement

is_Empty()which returnstrue if empty; otherwise false. 5. Implement the memberfunction called"Search" to search thevector for an item.The function willreturn an iterator tothe location of the item in the vector it isthere; otherwise, the function shouldprint themessage, “Item Found”or “Item Not Found”. Which message is printed dependson ifthe item wasfound or not foundin the vector. Also, print the item (search key) you were looking for. 6. Implement a function called "insert" to add an item tothe vector in order (alphabetical order). 7. Implement a function called "remove" toremove an item from thevector if it isthere; otherwise prints a message stating it was not in vector; the function should use an iterator and the erase function to remove an item from the vector. 8. Implement the memberfunction called“Print”, to print every item stored in the vector; Your program shouldtest theoperation of the class on C++ strings. For this assignment, put the class declaration in the implementation file “vlist.h" and the implementation file in “vlist.cpp”. Please considerthe file “vlist_driver.cpp” and the following skeleton classto help you implement the class vlist: class vlist { public: //vlist(); //default constructor //vlist(const //~vlist(); vlist &); //copy constructor //destructor //bool isEmpty(); //return true if empty; otherwise false //vector::iterator search(const string &); //returns the location of the string in the dynamic //array //void insert(const string & key); //add key to dynamic array //void remove(const string & key); //removes key from the vector if it is there; otherwise prints a //message stating it was not in vector; the function should use an iterator and the erase //function to //remove an item from the vector. //void print(); //Print every string in the vector //other functions may be implemented if necessary private: // vector DB; //vector //additonal state variables you may wish add }; Document your code well... Good luck... Submission of Assignment: Submit vlist.h, vlist.cpp, and vlist_driver.cpp together in a zip file named with the format “lastname_firstname_infix.zip”to Canvas before the due date and time. For example,ifI submitted this assignment,the zip file would be named “bullard_lofton_vlist.zip”. Consider the following pieces of code to helpyou getstarted: /********************************************************************************************** Sample skeleton for the file vlist.h. Remember to always add comments. Documentation is very important! **********************************************************************************************/ #include using namespace std; #ifndef vlist_H #define vlist_H class vlist { public: vlist(); vlist(const vlist &); ~vlist(); bool Is_Empty(); vector::iterator Search(const string &); void Insert(const string &); void Remove(const string &); void Print(); private: vector DB; }; #endif /********************************************************************** Sample skeleton for the file vlist.cpp Remember to always add comments. Documentation is very important! ***********************************************************************/ #include #include #include #include "vlist.h" using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// //Function Name: vlist //Precondition: Constructor has not been invoked. //Postcondition: count=0, vector size is 9. //Description: Constructs an instance of a vlist object. /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// vlist::vlist(){} /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// //Function Name: vlist //Precondition: A vlist object is being passed by reference. //Postcondition: A hard copy of a vlist object has been created. //Description: Creates a hard copy of a vlist object. /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// vlist::vlist(const vlist & Org){} /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// //Function Name: ~vlist //Precondition: Destructor has not been invoked. //Postcondition: array DB deleted. //Description: Deallocates memory of a vlist object. /////////////////////////////////////////////////////////////////////////////////////////////// /////////////// vlist::~vlist(){} bool vlist::is_Empty(){return true;} //vector::iterator vlist::Search(const string & key){} void vlist::Insert(const string & key){} void vlist::Remove(const string & key){} void vlist::Print(){} /****************************************************************************** S A M P L E T E S T D R I V E R Remember to always comment. Document is very important! *****************************************************************************/ //***************************************************************************** //P R O G R A M H E A D E R // // Name: Jane Doe // Z#: 000000000 // Instructor: Dr. Bullard // Class: Data Structures // Term: Summer 2015 // Assignment #1 (vlist) // Due Date: May 20, 2015 // Due Time: 11:00PM // Points: 100 // // Description: This program accesses your C++language skills. // After completing this assignment you will be able to perform the following: // // (1) Manage a vector(allocatm and de-allocate memory, insert inorder, remove, etc). // (2) Implement a default constructor and a copy constructor. // (3) Implement an insert function to add a string, in order, into a vector // (4) Implement a remove function to delete a string from a vector //****************************************************************************** #include #include #include "vlist.h" using namespace std; int main() { //Testing default constructor cout << "Test1:Testing the default constructor for string\n"; vlist String_List; //Testing functionality for string list cout << "Test2: Testing Insert \n"; String_List.insert("Hello"); String_List.insert("Zebra"); String_List.insert("Good_Bye"); String_List.insert("Space"); String_List.insert("No_One"); String_List.print(); cout << "Test 3: Testing copy constructor for string \n"; vlist Copied_String = String_List; Copied_String.print(); cout << "Test 4: Testing Remove for string \n"; cout << "Testing Search and IsEmpty also\n"; String_List.remove("Zebra"); String_List.remove("Good_Bye"); String_List.remove("Hello"); String_List.remove("No_One"); String_List.remove("Space"); String_List.remove("Hello"); cout<<"When leave main destructor will be called"<

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE

vlist.h

//Define header

#
ifndef vlist_H
#define vlist_H

//Include file
#include <vector>

//Include file
#include <string>
using namespace std;

//Create class

class vlist

{

        //Access specifier

        public:

                //Constructor

                vlist();

        //Constructor

        vlist(const vlist &myvlist);

        //Destructor

        ~vlist();

        //Create function

        bool is_Empty();

        //Create function

        vector<string>::iterator Search(const string &str);

        //Create function

        void insert(const string &str);

        //Create function

        void remove(const string &str);

        //Create function

        void Print();

        //Access specifier

        private:

                //Declare variable

                vector<string> DB;

        //Declare variable

        int count;

        //Declare variable

        int size;

};

//End

#
endif

vlist.cpp

//Include files
#include "vlist.h"
#include <iostream>
using namespace std;

//Constructor

vlist::vlist()

{

  //SEt value

  count = 0;

  //Set value

  size = 9;

  //Print statement

  cout << "Default Constructor invoked." << endl;

}

//Define constructor

vlist::vlist(const vlist &myvlist)

{

  //Empty the vector

  DB.empty();

  //SEt size

  size = myvlist.size;

  //SEt count

  count = myvlist.count;

  //Loop

  for (int kk = 0; kk < count; kk++)

  {

    //Add element

    DB.push_back(myvlist.DB.at(kk));
  }

  //Print message

  cout << "Copy constructor is invoked." << endl;

}

//Define destructor

vlist::~vlist()

{

  //Set value

  count = 0;

  //Call function

  DB.empty();

  //Print statement

  cout << "Destructor is invoked." << endl;

}

//Define function

bool vlist::is_Empty()

{

  //Check condition

  if (count == 0)

    //Return

    return true;

  //Return

  return false;

}

//Define function

vector<string>::iterator vlist::Search(const string &searchKey)

{

  //Print message

  cout << "\nSearch is invoked. \n";

  //Check condition

  if (!is_Empty())

  {

    //Loop

    for (vector<string>::iterator kk = DB.begin(); kk != DB.end(); kk++)

    {

      //Check condition

      if (searchKey == *kk)

      {

        //Print message

        cout << "\nItem " << *kk << " found." << endl;

        //Return

        return kk;
      }
    }
  }

  //Print message

  cout << "\nItem Not Found\n";

  //Call function and return

  return DB.end();

}

//Define function

void vlist::insert(const string &insertKey)

{

  //Check condition

  if (is_Empty())

  {

    //Insert element

    DB.push_back(insertKey);

    //Increase count

    count++;

    //Return

    return;
  }

  //Check condition

  else if (insertKey <= *DB.begin())

  {

    //Insert value

    DB.insert(DB.begin(), insertKey);

    //Increase count

    count++;

    //Return

    return;
  }

  //Else

  else

  {

    //Loop

    for (vector<string>::iterator kk = DB.begin(); kk != DB.end(); kk++)

    {

      //Check condition

      if (insertKey <= *kk)

      {

        //insert value

        DB.insert(kk, insertKey);

        //Increase count

        count++;

        //Return

        return;
      }
    }

    //insert value

    DB.insert(DB.end(), insertKey);

    //Increase count

    count++;
  }
}

//DEfine function

void vlist::remove(const string &removeKey)

{

  //Check condition

  if (is_Empty())

  {

    //Print message

    cout << "\nEmpty vector \n";

    //Return

    return;
  }

  //check condition

  else if (Search(removeKey) != DB.end())

  {

    //Call function and delete

    DB.erase(Search(removeKey));

    //decrease value

    count--;

    //Print message

    cout << "\n" << removeKey << " is deleted. \n";

    //Return

    return;
  }

  //Check condition

  else if (removeKey == *DB.end())

  {

    //delete value

    DB.erase(DB.end());

    //decrease value

    count--;

    //Print message

    cout << "\n" << removeKey << " is deleted. \n";

    //REturn

    return;
  }

  //Else

  else

  {

    //Print message

    cout << "\nNot found" << endl;
  }
}

//Define function

void vlist::Print()

{

  //Check condition

  if (is_Empty())

  {

    //Print message

    cout << "\nEmpty vector" << endl;
  }

  //Else

  else

  {

    //Loop

    for (vector<string>::iterator kk = DB.begin(); kk != DB.end(); kk++)

    {

      //Print value

      cout << (*kk) << endl;
    }

    //Print new line

    cout << endl;
  }
}

demo.cpp

#include <iostream>
#include <string>
#include "vlist.h"
using namespace std;

int main()

{

   //Testing default constructor

   cout << "Test1:Testing the default constructor for string\n";

   vlist String_List;

   //Testing functionality for string list

   cout << "Test2: Testing Insert \n";

   String_List.insert("Hello");

   String_List.insert("Zebra");

   String_List.insert("Good_Bye");

   String_List.insert("Space");

   String_List.insert("No_One");

   String_List.Print();

   cout << "Test 3: Testing copy constructor for string \n";

   vlist Copied_String = String_List;

   Copied_String.Print();

   cout << "Test 4: Testing Remove for string \n";

   cout << "Testing Search and IsEmpty also\n";

   String_List.remove("Zebra");

   String_List.remove("Good_Bye");

   String_List.remove("Hello");

   String_List.remove("No_One");

   String_List.remove("Space");

   String_List.remove("Hello");

   cout << "When leave main destructor will be called" << endl;

   //system("pause");

   return 0;

}


Related Solutions

For this lab you will continue your dynamic array by completing the class called MyDynamicArray. The...
For this lab you will continue your dynamic array by completing the class called MyDynamicArray. The MyDynamicArray class should manage the storage of an array that can grow and shrink. The public methods of your class should already be the following: MyDynamicArray(); Default Constructor. The array should be of capacity 2. MyDynamicArray(int s); For this constructor the array should be of capacity and size s. int& operator[](int i); Traditional [] operator. Should print a message if i is out of...
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary....
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current...
In this assignment, you will be completing a comprehensive health screening and history on a young...
In this assignment, you will be completing a comprehensive health screening and history on a young adult. To complete this assignment, do the following: Select an adolescent or young adult client on whom to perform a health screening and history. Students who do not work in an acute setting may "practice" these skills with a patient, community member, neighbor, friend, colleague, or loved one. Complete the "Health History and Screening of an Adolescent or Young Adult Client" worksheet. Complete the...
In this assignment, you will be completing a health assessment on an older adult. To complete...
In this assignment, you will be completing a health assessment on an older adult. To complete this assignment, do the following: Perform a health history on an older adult. Students who do not work in an acute setting may "practice" these skills with a patient, community member, neighbor, friend, colleague, or loved one. (If an older individual is not available, you may choose a younger individual). Complete a physical examination of the client using the "Health History and Examination" assignment...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to enter the digit code of the following text input MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY Use an inherited class using pointer variable to output the phone number from the following text input 1-800-COMCAST 1-800-VERIZON 1-800-BANCORP 1-800-MYKOHLS 1-800-JCPENNY Write C++ code and pseudocode in a doc file A computer key board has defect (like speech defect in humans) in reading for ‘p’ /’P’ as...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to...
In the following keypad notation Use a class and dynamic allocation of a pointer variable to enter the digit code of the following text input MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY Use an inherited class using pointer variable to output the phone number from the following text input 1-800-COMCAST 1-800-VERIZON 1-800-BANCORP 1-800-MYKOHLS 1-800-JCPENNY Write C++ code and pseudocode in a doc file A computer key board has defect (like speech defect in humans) in reading for ‘p’ /’P’ as...
This activity we will begin in class session and you will be responsible for completing and...
This activity we will begin in class session and you will be responsible for completing and submitting through Blackboard.  The  titles below will allow you to brainstorm on paper and then submit a narrative of your discoveries. To begin you will need to think of a good/ great leader that you have admired or worked with in the past. Think about the qualities that individual displayed during your interactions with or observations of that person that made you admire him or her....
C++ In this assignment you will use your Card class to simulate a deck of cards....
C++ In this assignment you will use your Card class to simulate a deck of cards. You will create a Deck class as follows: The constructor will create a full 52-card deck of cards. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace for each suit: Clubs, Diamonds, Hearts, Spades Each card will be created on the heap and the deck will be stored using an STL vector of Card pointers. The destructor will free the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT