Question: I just want the code, instructions are as follow: Read each argument carefully. Understands all the arguments and compares them with the knowledge acquired in

I just want the code, instructions are as follow: Read each argument carefully.
Understands all the arguments and compares them with the knowledge acquired in the module.
Make the code
Verify each step Program should be in C++, This is the header file list.h. This is the interface for the class List. Objects of type List can be a list of items of any type for which the operators << and = are defined. All the items on any one list must be of the same type. A list that can hold up to max items all of type Type_Name is declared as follows: List the_object(max);
#ifndef LIST_H
#define LIST_H
#include
using namespace std;
namespace listsavitch
{
template
class List
{
public:
List(int max);
//Initializes the object to an empty list that can hold up to
//max items of type ItemType.
~List();
//Returns all the dynamic memory used by the object to the freestore.
int length() const;
//Returns the number of items on the list.
void add(ItemType new_item);
//Precondition: The list is not full.
//Postcondition: The new_item has been added to the list.
bool full() const;
//Returns true if the list is full.
void erase();
//Removes all items from the list so that the list is empty.
friend ostream& operator <<(ostream& outs,
const List& the_list);
//Overloads the << operator so it can be used to output the
//contents of the list. The items are output one per line.
//Precondition: If outs is a file output stream, then outs has
//already been connected to a file.
private:
ItemType *item; //pointer to the dynamic array that holds the list.
int max_length; //max number of items allowed on the list.
int current_length; //number of items currently on the list.
};
}//listsavitch
#endif //LIST_H
Write a code for a program list cpp
#ifndef LIST_CPP
#define LIST_CPP
#include
#include
#include "list.h"//This is not needed when used as we are using this file,
//but the #ifndef in list.h makes it safe.
using namespace std;
namespace listsavitch
{
//Uses cstdlib:
template
List::List(int max) : max_length(max), current_length(0)
{
item = new ItemType[max];
}
template
List::~List()
{
delete [] item;
}
template
int List::length() const
{
return (current_length);
}
//Uses iostream and cstdlib:
template
void List::add(ItemType new_item)
{
if ( full())
{
cout << "Error: adding to a full list.
";
exit(1);
}
else
{
item[current_length]= new_item;
current_length = current_length +1;
}
}
template
bool List::full() const
{
return (current_length == max_length);
}
template
void List::erase()
{
current_length =0;
}
//Uses iostream:
template
ostream& operator <<(ostream& outs, const List& the_list)
{
for (int i =0; i < the_list.current_length; i++)
outs << the_list.item[i]<< endl;
return outs;
}
}//listsavitch
#endif // LIST_CPP Notice that we have enclosed all the template
// definitions in #ifndef... #endif.
demonstrate use of the class template List.
#include
#include "list.h"
#include "list.cpp"
using namespace std;
using namespace listsavitch;
int main()
{
List first_list(2);
first_list.add(1);
first_list.add(2);
cout << "first_list =
"
<< first_list;
List second_list(10);
second_list.add(A);
second_list.add(B);
second_list.add(C);
cout << "second_list =
"
<< second_list;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!