Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment Description: Call your driver \"vector_test_driver.cpp\", and your cl

ID: 3698128 • Letter: A

Question

Assignment Description:
Call your driver "vector_test_driver.cpp", and your class implementation file "VLIST.cpp". Define the
following behavior for VLIST
1. Implement a default constructor. Include the following message, "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 following message, "Destructor Invoked"
every time the function is called.
4. Implement Is_Full() which returns true if full; otherwise false; Include the message,
"Is_Full Invoked” every time the function is called.
5. Implement Is_Empty() which returns true if empty; otherwise false; Include the
message, "Is_Empty Invoked”
every time the function is called.
6. Implement the member function called "Search" to search the vector for an item. The
function should print the message, “Item Found” or
“Item Not Found”. Which message is print depends on if the item was found or not
found in the vector. Print the item (search key) you were looking for. Include the
following message, "Search Invoked" every time the function is called.
7. Implement a function called "Insert" to add an item to the vector in order
(alphabetical order). The function should print the contents of the VLIST object before
and after the function has been executed on single separate lines. Include the following
message, "Insert Invoked" every time the function is called.
8. Implement a function called "Remove" to remove an item from the vector. The
function should print the contents of the VLIST object before and after the function has
been executed on single separate lines. Include the following message, "Remove
Invoked" every time the function is invoked.
Your program should test the operation 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
consider the file “vlist_driver.cpp” and the following skeleton class to help you implement the class
VLIST:
class VLIST
{
public:
//VLIST(); //default constructor
//VLIST(const VLIST &); //copy constructor
//~VLIST(); //destructor
//bool IsEmpty(); //return true if empty; otherwise false
//bool IsFull(); //return true if full; otherwise false
//vector<string>::iterator Search(const string &); //returns the location of the string in the dynamic
array
//void Insert(const string & key); //add key to dynamic array if not full; otherwise prints a message
stating dynamic array is full
//void Remove(const string & key); //removes key from dynamic array if it is there; otherwise prints a
message stating it was not in dynamic array; the function using an iterator and the erase function to
remove an item from the vector.
//void Print(); //Print every string in the array
//other functions may be implemented if necessary
private:
// vector<string> DB; //vector
//additonal state variables you may wish add
};
Document your code well...
Good luck...
Submission of Assignment:
Submit the files vlist.h, vlist.cpp, and the driver vlist_driver.cpp ONLY in one zip file called
“program2_array” to blackboard before 11:00PM on or before the due date. Remember, ask questions
in class. You may need clarification on the assignment, so start early.
Consider the following pieces of code to help you get started:
/**********************************************************************************************
Sample skeleton for the file vlist.h.
Remember to always add comments. Documentation is very important!
**********************************************************************************************/
#include <vector>
using namespace std;
#ifndef VLIST_H
#define VLIST_H
class VLIST
{
public:
VLIST();
VLIST(const VLIST &);
~VLIST();
bool Is_Full();
bool Is_Empty();
vector<string>::iterator Search(const string &);
void Insert(const string &);
void Remove(const string &);
void Print();
private:
vector<string> DB; //vector
//additonal state variables you may wish add
};
#endif
/**********************************************************************
Sample skeleton for the file vlist.cpp
Remember to always add comments. Documentation is very important!
***********************************************************************/
#include <iostream>
#include <vector?
#include <string>
#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_Full(){return true;}
bool VLIST::Is_Empty(){return true;}
//vector<string>::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(allocate and de-allocate memory).
// (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 <iostream>
#include <string>
#include "vlist.h"
using namespace std;
int main()
{
//Testing default constructor
cout << "Test1:Testing the default constructor for string ";
VLIST String_List;
//Testing functionality for string list
cout << "Test2: Testing Insert ";
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 ";
VLIST Copied_String = String_List;
Copied_String.Print();
cout << "Test 4: Testing Remove for string ";
cout << "Testing Search and IsEmpty also ";
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;
return 0;
}

Explanation / Answer

#include <iostream>

#include <vector?

#include <string>

#include "VLIST.h"

using namespace std;

VLIST::VLIST()

{

                ifstream inputFile;

                string fromFile;

              count = 0;

                capacity = 9;

                DB = new string[capacity];

                cout << "Default Constructor Invoked" << endl;

                inputFile.open("myData.txt");

                if(inputFile.fail())

                                cout << "COULD NOT OPEN FILE" << endl;

                while(!inputFile.eof())

                {

                                if (IsFull())

                                {

                                                DoubleSize();

                                }

                                inputFile >> fromFile;

                                if(!inputFile.eof())

                              {

                                                                Insert(fromFile);

                                                                cout << endl;

                                }

                }

                inputFile.close();

}

VLIST:: VLIST(const VLIST& other)

{

                count = other.count;

                capacity = other.capacity;

                DB = new string[capacity];

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

           DB[i] = other.DB[i];

        cout << "Copy Constructor Invoked" << endl << "Calling Object: " << *this << endl

                                << "Copied Object: " << other << endl;

}

VLIST::~VLIST()

{

cout << "Destructor Invoked" << endl;

                delete [] DB;

}

bool VLIST::Is_Full()

{

cout << "IsFull Invoked" << endl;

                if(count == capacity)

                                return true;

                else

                                return false;

}

bool VLIST::Is_Empty()

{

cout << "IsEmpty Invoked" << endl;

                if(count == 0)

                                return true;

                else

                                return false;

}

void VLIST::Insert(const string & key)

{

cout << "Search invoked" << endl;

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

                {

                                if(DB[i] == key)

                                {

                                                cout << "Item: " << key << " Found" << endl;

                                                return i;

                                }

                }

               

                cout << "Item: " << key << " Not Found" << endl;

                return -1;

}

void VLIST::Remove(const string & key)

{

int location = 0;

                cout << "Remove Invoked" << endl;

                cout << "Array before Remove: " << *this << endl;

               if((location = Search(key)) < 0 || count == 0)

                                cout << "Key does not exist in this array." << endl;

                else

                {

                while(location < count - 1)

                {

                                DB[stringLocation][location] = DB[stringLocation][location + 1];

                                location++;

                }

                count -= 1;

                }

         cout << "Array after Remove: " << *this << endl;

}

void VLIST::Print()

{

for (int i = 0; i < capacity;i++) {

        cout << " " << DB[capacity].at(i) << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote