Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code for TrackSongs.cpp: #include #include #include using namespace std; template class List { private: static const int CHUNK _ SIZE = 1 0 0 ;
Code for TrackSongs.cpp:
#include
#include
#include
using namespace std;
template
class List
private:
static const int CHUNKSIZE;
ItemType list;
int numItems;
int maxItems;
public:
default constructor and destructor
List numItems ; maxItems CHUNKSIZE;
list new ItemTypeCHUNKSIZE;
~List delete list;
list member functions
bool isEmpty const return numItems;
int getLength const return numItems;
bool insertint pos, const ItemType& item;
bool removeint pos;
clear the list
clear can simply set numItems to zero. The array list may still contain
items already inserted into the list, but since numItems is zero, there
isn't any way to get at them using getEntry or setEntry
void clear numItems ;
return entry at postion pos
throw invalidargument if pos or posgetLength
ItemType getEntryint pos const;
set entry at postion pos to item
throw invalidargument if pos or posgetLength
void setEntryint pos, const ItemType& item;
;
template
bool List::insertint pos, const ItemType& item
bool canAdd;
canAdd pos && pos numItems && numItems maxItems;
if canAdd
first, we have to move everything after our insertion point over one
position to make room for our new item. start at the back of the list.
don't forget arrays start at postion zero and our list ADT starts at
position
forint inumItems; ipos; i
listi listi;
now put our item at position pos
listpos item;
numItems;
return canAdd;
template
ItemType List::getEntryint pos const
ifpos posgetLength
throw invalidargumentERROR: getEntry using invalid position";
return listpos;
TODO: add implementations for setEntry and remove functions
Utility function to input a track number with some input checking
to make sure it's a number
int getTrack
bool inputCheck;
int trackNumber;
do
inputCheck true;
cout "Please enter the track number you'd like to view: ;
if cin trackNumber
cout "Please enter numbers only.
;
cin.clear;
cin.ignore
;
inputCheck false;
while inputCheck;
return trackNumber;
int main
List songs;
char goAgain y;
int trackNumber;
string trackName;
Insert some songs into our list
songs.insert "One More Saturday Night";
songs.insert "Friday Im in Love";
songs.insert "Sunday Morning Coming Down";
songs.insert "California Love";
cout "Welcome! There are songs.getLength tracks.
;
while goAgainn
trackNumber getTrack;
try
trackName songs.getEntrytrackNumber;
catch invalidargument arg
cout arg.what endl;
trackName No Track";
cout "Your track name is trackName endl;
cout Go again? yn;
cin goAgain;
cout "Rock on
;
return ;
Step 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