In: Computer Science
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"<
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;
}