Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Defines the entry point for the console application. // #include stdafx.h #includeDSA.h int main() { // Declare a dynamic string array DSA names; // Add

Defines the entry point for the console application. 

//


#include \"stdafx.h\"

#include\"DSA.h\"


int main()

{

// Declare a dynamic string array

DSA names;


// Add a list of names to the array

names.addEntry(\"Frank\");

names.addEntry(\"Woody\");

names.addEntry(\"Max\");

names.addEntry(\"Mary\");

names.addEntry(\"Flanders\");


// Output list

cout

names.printList();


// Add one more name

names.addEntry(\"Jon\");

cout

names.printList();


// Add one more name using the + operator

names = names + \"Jack\"; // the class's assignment operator should be used here

cout

names.printList();


// Delete a specific entry (name) from the list

names.deleteEntry(\"Woody\");

cout

names.printList();



// Delete a specific entry (name) from the list using the - operator

names = names - \"Flanders\";

cout

names.printList();


// Remove all of the names by repeatedly deleting the last one

while (names.getSize() > 0) {

names.deleteEntry(names.getEntry(names.getSize() - 1));

}


cout

names.printList();



names.addEntry(\"Burns\");

cout

names.printList();


// Testing the Copy constructor

cout

DSA names2(names);

// Remove Burns from names

names.deleteEntry(\"Burns\");

cout

names2.printList();


// Testing the assignment operator

cout

DSA names3 = names2;

// Remove Burns from names2

names2.deleteEntry(\"Burns\");

cout

names3.printList();


cout


return 0;

}

to add or delete entries from the array

Your task is to create a class called DSA that includes member functions that allow it to emulate the behavior of a vector of strings. Once your class is ready, test it using the main function uploaded to Blackboard.

Your class should have:

A private member variable called dynamicArray that references a dynamic array of type string (this should be a pointer variable).

A private member variable called size that holds the number of entries in the array

A default constructor that sets the dynamic array to nullptr and sets size to 0

A function that returns size.

A function named addEntry that takes a string as input. The function should create a new dynamic array one element larger than dynamicArray, copy all elements from dynamicArray into the new array, add the new string onto the end of the new array, increment size, delete the old dynamicArray, and then set dynamicArray to the new array.

A function named deleteEntry that takes a string as input. The function should search dynamicArray for the string. If not found, return false. If found, create a new dynamic array one element smaller than dynamicArray. Copy all elements except the input string into the new array, delete dynamicarray, decrement size, and return true

A function named getEntry that takes an integer as input and returns the string at that index in dynamicArray. Return nulltptr if the index is out of dynamicArray's bounds

A copy constructor that makes a copy of the input object's dynamic array.

Overload the assignment operator so that the dynamic array is properly copied to the target object.

Overload the plus (+) operator to act as an alias for the addEntry function. Simply, the user should be able to add new strings to the array as follows myArraymyArray + \"new String\";

Overload the minus (-) operator to act as an alias for the deleteEntry function Simply, the user should be able to delete strings from the array as follows: myArray = myArray- \" some String\".

A destructor that frees up the memory allocated to the dynamic array



Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

Draw a labelled diagram of the Dicot stem.

Answered: 1 week ago

Question

4. How do you ask for specific action in a courteous manner?

Answered: 1 week ago