In C++ Internal Documentation only. For this project, you will write a program t
ID: 3804315 • Letter: I
Question
In C++
Internal Documentation only.
For this project, you will write a program that keeps track of inventory for a camera store. The data is located in the file InventoryFile.txt on the S: drive. While the program is running, the information should be stored in a doubly linked list.
1. The information for each item will be stored in a struct
a. The definition will be in a separate file called item.h
2. The total inventory will be stored in a list
a. The definition of the list class will be in a file called dlist.h
3. The program should be able to perform the following functions
a. Print the inventory
b. Print the inventory in reverse order
c. Add an item to the inventory
d. Delete an item from inventory
e. Change any info for an item
4. The program will run until the user chooses an option to exit
5. The list is not in alphabetical order, so you will need to put it in order.
6. Whenever you change a name or if you add an item the list must stay in order.
7. When you are done, the list will be printed to a file called newlist.txt
8. You must have internal and external documentation:
This is what the file looks like,
Telephoto-Pocket-Camera 54.95 15 20
Mini-Pocket-Camera 24.95 15 12
Polaroid-1Step-Camera 49.95 10 20
Sonar-1Step-Camera 189.95 12 13
Pronto-Camera 74.95 5 15
8MM-Zoom-Movie-Camera 279.99 10 9
8MM-Sound/ZoomMovieCamera 310.55 10 15
35MM-Minolta-SLR-XG-7-Camera 389.00 12 10
35MM-Pentax-SLR-AE-1-Camera 349.95 12 11
35MM-Canon-SLR-ME-Camera 319.90 12 20
35MM-Hi-Matic-Camera 119.95 12 13
35MM-Compact-Camera 89.99 12 20
Zoom-Movie-Projector 129.95 5 7
Zoom-Sound-Projector 239.99 5 9
Auto-Carousel-Projector 219.99 5 10
Carousel-Slide-Projector 114.95 5 4
Pocket-Strobe 14.95 5 4
StrobeSX-10 48.55 10 12
Electonic-Flash-SX-10 28.99 15 10
Tele-Converter 32.99 15 13
28MM-Wide-Angle-Lens 97.99 15 14
135MM-Telephoto-Lens 87.95 15 13
35-105MM-Zoom-Lens 267.95 5 8
80-200MM-Zoom-Lens 257.95 5 7
Explanation / Answer
#ifndef DLISTT_H #define DLISTT_H #include <iostream> #include <iomanip> #include <new> #include <stdexcept> using namespace std;
template <typename T> class DListT { friend class Javert; // MY diagnostic test class
private: class DNodeT { public: T Element; DNodeT* Prev; DNodeT* Next;
DNodeT(); DNodeT(const T& Elem, DNodeT* P = NULL, DNodeT* N = NULL); ~DNodeT(); };
DNodeT* Fore; // handle on leading sentinel node DNodeT* Aft; // handle on trailing sentinel node
public: DListT(); // make empty list DListT(const DListT<T>& Source); // deep copy support DListT<T>& operator=(const DListT<T>& Source); ~DListT(); // deallocate all nodes
bool isEmpty() const; // true iff list has no nodes void Clear(); // restore to empty state
void Display(ostream& Out) const; // display formatted contents
// . . . interface specification continues in next display . . .
class iterator { private: DNodeT* Position; iterator(DNodeT* P) { Position = P; }
public: iterator() { Position = NULL; } iterator operator++() { // step to next data node (if any) or to trailing sentinel } iterator operator++(int Dummy) { // step to next data node (if any) or to trailing sentinel } iterator operator--() { // step to previous data node (if any) or to leading sentinel } iterator operator--(int Dummy) { // step to previous data node (if any) or to leading sentinel } bool operator==(const iterator& RHS) const { // iterators are equal iff they have the same target } bool operator!=(const iterator& RHS) const { // complement of operator==() } T& operator*() throw (range_error) { // return reference to data in iterator's target, // throw exception if no target or target not a data node }
friend class DListT<T>; // to use private constructor friend class Javert; // give test harness access friend class const_iterator; // for conversions }; // end iterator
////////////////////////////////////////// const_iterator class class const_iterator { private: DNodeT* Position; const_iterator(DNodeT* P) { Position = P; }
public: const_iterator() { Position = NULL; } const_iterator operator++() { // step to next data node (if any) or to trailing sentinel } const_iterator operator++(int Dummy) { // step to next data node (if any) or to trailing sentinel } const_iterator operator--() { // step to previous data node (if any) or to leading sentinel } const_iterator operator--(int Dummy) { // step to previous data node (if any) or to leading sentinel } // . . . interface specification continues in next display . . . bool operator==(const const_iterator& RHS) const { // iterators are equal iff they have the same target } bool operator!=(const const_iterator& RHS) const { // complement of operator==() } const T& operator*() const throw (range_error) { // return constant reference to data in iterator's target, // throw exception if no target or target not a data node } const_iterator(const iterator& It) { // create constant iterator from regular iterator } const_iterator& operator=(const iterator& It) { // assign regular iterator to constant iterator }
friend class DListT<T>; // to use private constructor friend class Javert; // give test harness access }; // end const_iterator
iterator begin(); // return iterator to head node, if any // otherwise return end() iterator end(); // return iterator to trailing sentinel
const_iterator begin() const; // analogous to previous fns const_iterator end() const;
iterator Insert(iterator It, const T& Elem); // insert before target of // iterator, if any; // if iterator is end(), // append value to list; // if iterator target is not // a data node or the // trailing sentinel, // behavior is undefined iterator Find(const T& Elem); // return iterator to matching data, // or end() if not found const_iterator Find(const T& Elem) const; // same, but return const_iterator void Delete(iterator It) throw (range_error); // delete target of iterator, // if not a sentinel; // otherwise throw exception }; // . . . non-inline implementation follows in this file