Question
This assignment has 3 files: main.cpp clist.cpp clist.h Only clist.cpp needs to be made, as the others are already made. They are posted below This
This assignment has 3 files: main.cpp clist.cpp clist.h
Only clist.cpp needs to be made, as the others are already made. They are posted below
This homework assignment works on constructing a list of integer values similar to the example we did in class. The difference with this assignment is youll want to implement your own function, Insert, to insert a value. Also, youll write a function to remove an item, Remove. Specifically, for the previous two functions, youll create a private member function, MoveItems, that will rearrange the items when they have been inserted or removed from the list. For example, move the items to the end of the list to make room for the new item or move the items to the beginning of the list to close the gap from the item that was removed. I highly suggest you go over the example in class and read your book to get a better feel of what you should do. When making your functions, make sure you check youre within bounds! One function that has been implemented for you is DispError. It is used for debugging purposes. This function is called when you check if there is a possible error (e.g. out of bounds). For example, if youre in the Insert function and the list is full, there is no room to add a new item. So you will call the DispError function before returning a Status to the calling function. DispError takes two arguments, the name of the function calling DispError and the Status. In this case, it would be Insert and FULL.
Your objective is to implement the functions in clist.h onto clist.cpp. You wont need to change anything in main.cpp or clist.h. Get a feel for what the program is doing and study what has been given in main.cpp and clist.h to know what the functions should have as input/output. Your code should mimic the output from the sample executable file.
Get all three files (main.cpp, clist.h and clist.cpp) together in a multi-module project
THIS IS THE SAMPLE EXECUTABLE:
A)dd an item R)emove an item D)isplay the list C)lear the list Q)uit Please enter a selection:
Files:
clist.h
main.cpp
#include
using namespace std;
#include "clist.h"
// function prototypes
void DisplayList(const CList &list);
void Menu();
void FlushInstream(istream &inStream = cin);
// ==== main ==================================================================
//
// ============================================================================
int main()
{
CList list;
bool loop = true;
char selection;
int value;
int index;
do {
Menu();
cout
cin >> selection;
switch (toupper(selection))
{
case 'A':
// if the list is full, display an error message
if (list.IsFull())
{
cout
continue;
}
// try to get a valid item and index from the user
cout
if (!(cin >> value))
{
cout
FlushInstream();
continue;
}
cout
if (!(cin >> index))
{
cout
FlushInstream();
continue;
}
// insert the new item into the list
list.Insert(index, value);
break;
case 'R':
// if the list is empty, display an error message
if (list.IsEmpty())
{
cout
continue;
}
// try to get a valid index from the user
cout
if (!(cin >> value))
{
cout
FlushInstream();
continue;
}
// remove the item from the list
list.Remove(value);
break;
case 'D':
cout
DisplayList(list);
break;
case 'C':
cout
list.DestroyList();
break;
case 'Q':
loop = false;
break;
default:
cout
FlushInstream();
break;
}
cout
} while (loop == true);
return 0;
} // end of "main"
// ==== Menu ===========================================================
//
// This function displays a list of options to stdout.
//
// Input: void
//
// Output: void
//
// ============================================================================
void Menu()
{
cout
cout
cout
cout
cout
} // end of "Menu"
// ==== DisplayList ===========================================================
//
// This function displays the current contents of the list to the standard
// output stream.
//
// Input:
// list -- a const reference to a CList object
//
// Output:
// Nothing.
//
// ============================================================================
void DisplayList(const CList &list)
{
int index;
ListItemType item;
for (index = 0; index
{
list.GetItem(index, item);
cout
}
} // end of "DisplayList"
// ==== FlushInstream =========================================================
//
// This function displays the current contents of the list to the standard
// output stream.
//
// Input:
// list -- a const reference to a CSortedList object
//
// Output:
// Nothing.
//
// ============================================================================
void FlushInstream(istream &inStream)
{
char inChar;
inStream.clear();
while (false == inStream.eof())
{
inStream.get(inChar);
if (' ' == inChar)
{
break;
}
}
} // end of "FlushInstream"
// File: elist.h Header file for the CL1S ifndef CLIST HEADER #define CLIST HEADER // enable this #define aylibol t ee debug output #define DEBUG LIST t type detinitions typedef int ListicemType: enm Status FULL ERROB INVALID INDEX I conscant (a) ost int HAX IITEMS10 CLiSE CLSE -CLiSt O nember tunctions Statu5 DestroyL1SD chart functionCaller, Scatus value) coa tatusD GetIten(int index, ListicemType &item) const Insert int index, const ListicemType SnewItem): IsEmpty) const IaFull ) conat Remove int index) bool tatusau11 private / data members ListiteType mitemsMX ITEMSI // neber tunction StAtuS HoveItems (Ancndex, char dsreetion) 2 #endig // CLIST HEADER // File: elist.h Header file for the CL1S ifndef CLIST HEADER #define CLIST HEADER // enable this #define aylibol t ee debug output #define DEBUG LIST t type detinitions typedef int ListicemType: enm Status FULL ERROB INVALID INDEX I conscant (a) ost int HAX IITEMS10 CLiSE CLSE -CLiSt O nember tunctions Statu5 DestroyL1SD chart functionCaller, Scatus value) coa tatusD GetIten(int index, ListicemType &item) const Insert int index, const ListicemType SnewItem): IsEmpty) const IaFull ) conat Remove int index) bool tatusau11 private / data members ListiteType mitemsMX ITEMSI // neber tunction StAtuS HoveItems (Ancndex, char dsreetion) 2 #endig // CLIST HEADERStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started