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 TypeName is declared as follows: List theobjectmax;
#ifndef LISTH
#define LISTH
#include
using namespace std;
namespace listsavitch
template
class List
public:
Listint 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 addItemType newitem;
Precondition: The list is not full.
Postcondition: The newitem 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& thelist;
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 maxlength; max number of items allowed on the list.
int currentlength; number of items currently on the list.
;
listsavitch
#endif LISTH
Write a code for a program list cpp
#ifndef LISTCPP
#define LISTCPP
#include
#include
#include "list.hThis 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::Listint max : maxlengthmax currentlength
item new ItemTypemax;
template
List::~List
delete item;
template
int List::length const
return currentlength;
Uses iostream and cstdlib:
template
void List::addItemType newitem
if full
cout "Error: adding to a full list.
;
exit;
else
itemcurrentlength newitem;
currentlength currentlength ;
template
bool List::full const
return currentlength maxlength;
template
void List::erase
currentlength ;
Uses iostream:
template
ostream& operator ostream& outs, const List& thelist
for int i ; i thelist.currentlength; i
outs thelist.itemi endl;
return outs;
listsavitch
#endif LISTCPP 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 firstlist;
firstlist.add;
firstlist.add;
cout "firstlist
firstlist;
List secondlist;
secondlist.addA;
secondlist.addB;
secondlist.addC;
cout "secondlist
secondlist;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
