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 copy constructor, (6) overload the assignment operator, (7) overload the insertion operator, (8) search an array, (9) change the size of a dynamic array, (10) write function and program headers, (11) implement a destructor, and (12) implement a destructor. 1. For this assignment you will need the following files which are given: a. The file “dynamic_array_driver.cpp” contains the declaration and implementation for the dynamic array class “tlist”. b. The file “ourData.txt” contains input data for the program. c. The file “dynamic_array_output.txt” contains the output that the main program you write will produce when you add it to the file “dynamic_array_driver.cpp”. 2. Comment every item in the private and private areas of the class declaration. Be specific in your choice of words. Consider the following as appropriate comments for some of the items in the class declaration: a. Destructor b. Copy construction c. Delete an item from the dynamic array … d. Overloaded assignment operator as a member function with chaining.. e. The dynamic array 3. Write the program header for the program “dynamic_array_driver.cpp”. 4. Write a function header for each function in the class declaration (see file “dynamic_array_driver.cpp”). Each function header should be placed above the function implementation; the code that is provided is enough information for you to write correct function headers. Remember, function headers should include the function name, precondition, post-condition, and function description. 5. Write a main program to produce the output, exactly, as in the file “dynamic_array_output.txt”. Use the file “ourData.txt” for input to your program. The body of your main program (which you will add to the file “dynamic_array_driver.cpp”) should have no more than 20 lines of code; this includes blank lines. The key to doing a good job on this assignment, is to read and understand the code that is provided. Hint: any output and/or messages should be done inside the functions of the class. Your main program should only use “cout” when invoking (calling) the overloaded insertion operator (<<).
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class tlist
{
public:
tlist();//default
~tlist();
tlist(const tlist &);
bool IsEmpty();
bool IsFull();
int Search(const string &);
void Insert(const string &);
void Remove(const string &);
void Triple_size();
tlist & operator=(const tlist &);
friend ostream & operator<<(ostream &, const tlist &);
private:
string *DB;
int count;
int capacity;
};
//***************************Sample Header Format**********************
// Function Name: Default Constructor
// Pre-Condition: The count, capacity and the dynamic array DB have not been
initialized.
// Post-Condition:The count, capacity and the dynamic array DB have been
initialized.
// Description:The default constructor initializes that state of the class.
//
//********************************************************************
tlist::tlist()
{
string s;
ifstream input;
input.open("ourData.txt");
if (input.fail())
{
cout << "problem with input data file\n";
exit(1);
}
cout << "\n\nDefault Constructor Invoked\n"
<< "***************************\n\n";
count = 0;
capacity = 1;
DB = new string[capacity];
IsEmpty();
while (!input.eof())
{
input >> s;
Insert(s);
}
input.close();
}
tlist::~tlist()
{
cout << "\n\nDestructor Invoked\n"
<< "*******************\n\n";
delete[] DB;
}
tlist::tlist(const tlist & org)
{
cout << "\n\nCopy Constructor Invoked\n"
<< "*************************\n\n";
count = org.count;
capacity = org.capacity;
DB = new string[capacity];
for (int i = 0; i < count; i++)
{
DB[i] = org.DB[i];
}
}
bool tlist::IsEmpty()
{
cout << "\n\nIsEmpty Invoked\n"
<< "****************\n\n";
return count == 0;
}
bool tlist::IsFull()
{
cout << "\n\nIsFull Invoked\n"
<< "***************\n\n";
return count == capacity;
}
int tlist::Search(const string & key)
{
for (int i = 0; i < count; i++)
{
if (DB[i] == key)
{
return i;
}
}
return -1;
}
void tlist::Insert(const string & key)
{
if (IsFull())
{
Triple_size();
}
DB[count++] = key;
}
void tlist::Remove(const string & key)
{
int i = Search(key);
if (i == -1)
{
if (IsEmpty())
{
cout << "DB is empty\n\n";
}
else
{
cout << key << " not in DB\n\n";
}
}
else
{
for (int j = i; j < count - 1; j++)
{
DB[j] = DB[j + 1];
}
cout << key << " found and deleted\n\n";
count--;
}
}
void tlist::Triple_size()
{
cout << "\n\nTriple_size Invoked\n"
<< "***************************\n\n";
capacity *= 3;
string *temp = new string[capacity];
for (int i = 0; i < count; i++)
{
temp[i] = DB[i];
}
delete[] DB;
DB = temp;
}
tlist & tlist::operator=(const tlist & org)
{
cout << "\n\noverloaded assignment operator (=) Invoked\n"
<< "***************************\n\n";
if (this != &org)
{
delete[](*this).DB;
(*this).count = org.count;
(*this).capacity = org.count;
(*this).DB = new string[(*this).capacity];
for (int i = 0; i < (*this).count; i++)
{
(*this).DB[i] = org.DB[i];
}
}
return *this;
}
ostream & operator<<(ostream & cout, const tlist & org)
{
for (int i = 0; i < org.count; i++)
{
cout << org.DB[i] << endl;
}
return cout;
}
int main()
{
//YOUR ADD YOUR CODE FOR MAIN HERE
return 0;
}
"ourData.txt" file:
cloud
azure
microsoft
sql
database
firefox
netscape
myworld
algorithm
object
class
seacrest
multiplicity
associativity
amazon
/* THE THING IS YOU ONLY HAVE TO CREATE OBJECT OF CLASS AND COUT IT EVERYFUNCTION WILL INVOKED ITESELF BY CONSTRUCTOR ITSELF */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class tlist
{
public:
tlist();//default
~tlist();
tlist(const tlist &);
bool IsEmpty();
bool IsFull();
int Search(const string &);
void Insert(const string &);
void Remove(const string &);
void Triple_size();
tlist & operator=(const tlist &);
friend ostream & operator<<(ostream &, const tlist &);
private:
string *DB;
int count;
int capacity;
};
//***************************Sample Header Format**********************
// Function Name: Default Constructor
// Pre-Condition: The count, capacity and the dynamic array DB have not been
//initialized.
// Post-Condition:The count, capacity and the dynamic array DB have been
//initialized.
// Description:The default constructor initializes that state of the class.
//
//********************************************************************
tlist::tlist()
{
string s;
ifstream input;
input.open("ourData.txt");
if (input.fail())
{
cout << "problem with input data file\n";
exit(1);
}
cout << "\n\nDefault Constructor Invoked\n"
<< "***************************\n\n";
count = 0;
capacity = 1;
DB = new string[capacity];
IsEmpty();
while (!input.eof())
{
input >> s;
Insert(s);
}
input.close();
}
tlist::~tlist()
{
cout << "\n\nDestructor Invoked\n"
<< "*******************\n\n";
delete[] DB;
}
tlist::tlist(const tlist & org)
{
cout << "\n\nCopy Constructor Invoked\n"
<< "*************************\n\n";
count = org.count;
capacity = org.capacity;
DB = new string[capacity];
for (int i = 0; i < count; i++)
{
DB[i] = org.DB[i];
}
}
bool tlist::IsEmpty()
{
cout << "\n\nIsEmpty Invoked\n"
<< "****************\n\n";
return count == 0;
}
bool tlist::IsFull()
{
cout << "\n\nIsFull Invoked\n"
<< "***************\n\n";
return count == capacity;
}
int tlist::Search(const string & key)
{
for (int i = 0; i < count; i++)
{
if (DB[i] == key)
{
return i;
}
}
return -1;
}
void tlist::Insert(const string & key)
{
if (IsFull())
{
Triple_size();
}
DB[count++] = key;
}
void tlist::Remove(const string & key)
{
int i = Search(key);
if (i == -1)
{
if (IsEmpty())
{
cout << "DB is empty\n\n";
}
else
{
cout << key << " not in DB\n\n";
}
}
else
{
for (int j = i; j < count - 1; j++)
{
DB[j] = DB[j + 1];
}
cout << key << " found and deleted\n\n";
count--;
}
}
void tlist::Triple_size()
{
cout << "\n\nTriple_size Invoked\n"
<< "***************************\n\n";
capacity *= 3;
string *temp = new string[capacity];
for (int i = 0; i < count; i++)
{
temp[i] = DB[i];
}
delete[] DB;
DB = temp;
}
tlist & tlist::operator=(const tlist & org)
{
cout << "\n\noverloaded assignment operator (=) Invoked\n"
<< "***************************\n\n";
if (this != &org)
{
delete[](*this).DB;
(*this).count = org.count;
(*this).capacity = org.count;
(*this).DB = new string[(*this).capacity];
for (int i = 0; i < (*this).count; i++)
{
(*this).DB[i] = org.DB[i];
}
}
return *this;
}
ostream & operator<<(ostream & cout, const tlist & org)
{
for (int i = 0; i < org.count; i++)
{
cout << org.DB[i] << endl;
}
return cout;
}
int main()
{
//YOUR ADD YOUR CODE FOR MAIN HERE
tlist obj;
cout<<obj;
return 0;
}
/* SCREENSHOT */
/* PLEASE UPVOTE */
C++ assignment help! The instructions are below, i included the main driver, i just need help...
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...
The code should be written in C++. I included the Class used for this function. Also, please fix the main function if necessary. Description: This function de-allocates all memory allocated to INV. This will be the last function to be called (automatically by the compiler) //before the program is exited. This function also erased all data in the data file. There are other functions that add, process and alter the file; the file printed after those functions will have new...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...
I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...
// thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...
I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...
Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp, and a test file to test the functionality of the class. Hint: read all the explanations in the header with attention. MyArray.h : #ifndef MYARRAY_H #define MYARRAY_H #include <iostream> using namespace std; class MyArray { friend ostream& operator<<( ostream & output, const MyArray & rhs); // to output the values of the array friend istream& operator>>( istream & input, MyArray & rhs); // to...
Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; cs52::FlashDrive drive1(10, 0, false); cs52::FlashDrive drive2(20, 0, false); drive1.plugIn(); drive1.formatDrive(); drive1.writeData(5); drive1.pullOut(); drive2.plugIn(); drive2.formatDrive(); drive2.writeData(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...