Question: nstructions: For this lab, you will write a program that reads in a list of items for a camera store. The items for the list

nstructions: For this lab, you will write a program that reads in a list of items for a camera store. The items for the list are in a file called InventoryFile.txt. The program will give the user options to insert an item, remove an item, display the list of items, search for an item, or exit the program. Each line of the file InventoryFile has the following format: Item Number an integer Number in stock an integer (between 0 and 999) Unit Price a floating-point value Minimum inventory level an integer Item name a character string You will have to define a struct to hold the info for each item, and then your list will be an array of the structs. You will probably have to overload some operators for your struct. Your struct definition and overloaded operators should be in a separate header/implementation file from the list header/implementation. Your driver file should create the list, read in all the items, and then ask the user what to do (insert, delete, etc...), repeating until the user chooses to exit When you are done, the list should be output to a file called NewInventory. You will send me your driver, the list header and implementation, and the struct header and implementation.

#inventory file

1011 20 54.95 15 Telephoto-Pocket-Camera 1012 12 24.95 15 Mini-Pocket-Camera 1021 20 49.95 10 Polaroid-1Step-Camera 1022 13 189.95 12 Sonar-1Step-Camera 1023 15 74.95 5 Pronto-Camera 1031 9 279.99 10 8MM-Zoom-Movie-Camera 1032 15 310.55 10 8MM-Sound/ZoomMovieCamera 1041 10 389.00 12 35MM-Minolta-SLR-XG-7-Camera 1042 11 349.95 12 35MM-Pentax-SLR-AE-1-Camera 1043 20 319.90 12 35MM-Canon-SLR-ME-Camera 1044 13 119.95 12 35MM-Hi-Matic-Camera 1045 20 89.99 12 35MM-Compact-Camera 1511 7 129.95 5 Zoom-Movie-Projector 1512 9 239.99 5 Zoom-Sound-Projector 1521 10 219.99 5 Auto-Carousel-Projector 1522 4 114.95 5 Carousel-Slide-Projector 2011 4 14.95 5 Pocket-Strobe 2012 12 48.55 10 StrobeSX-10 2013 10 28.99 15 Electonic-Flash-SX-10 3011 13 32.99 15 Tele-Converter 3012 14 97.99 15 28MM-Wide-Angle-Lens 3013 13 87.95 15 135MM-Telephoto-Lens 3014 8 267.95 5 35-105MM-Zoom-Lens 3015 7 257.95 5 80-200MM-Zoom-Lens 3111 4 67.50 5 Heavy-Duty-Tripod 3112 10 19.95 5 Lightweight-Tripod 3511 10 159.99 5 35MM-Enlarger-Kit 4011 4 35.98 5 40x40-Deluxe-Screen 4012 10 44.98 5 50x50-Deluxe-Screen 5011 17 4.29 25 120-Slide-Tray 5012 33 2.95 25 100-Slide-Tray 5021 12 6.25 15 Slide-Viewer 5031 12 55.95 10 Movie-Editor 6011 10 59.95 5 Condenser-Microphone 6111 80 0.89 100 AA-Alkaline-Battery 7011 19 19.79 20 Gadget-Bag 8011 45 1.49 50 135-24-Color-Film 8021 60 0.99 50 110-12-Color-Film 8022 42 1.45 50 110-24-Color-Film 8023 37 0.59 25 110-12-B/W-Film 8024 43 0.95 25 110-24-B/W-Film 8031 44 0.89 50 126-12-Color-Film 8032 27 0.59 25 126-12-B/W-Film 8041 39 6.89 50 8MM-Film-Cassette 8042 25 11.89 20 16MM-Film-Cassette 9111 10 959.99 12 Combination-Camera-Kit

#cpp.file

//----- List.cpp ----- #include using namespace std;

#include "linkedlist.h" //-- Definition of the class constructor List::List() : first(0), mySize(0) { }

//-- Definition of the copy constructor List::List(const List & origList) { mySize = origList.mySize; first = 0; if (mySize == 0) return; NodePointer origPtr, lastPtr; first = new Node(origList.first->data); // copy first node lastPtr = first; origPtr = origList.first->next; while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } //-- Definition of the destructor inline List::~List() { NodePointer prev = first, ptr; while (prev != 0) { ptr = prev->next; delete prev; prev = ptr; } }

// Definition of empty() bool List::empty() { return mySize == 0; } //-- Definition of the assignment operator const List & List::operator=(const List & rightSide) { mySize = rightSide.mySize; first = 0; if (mySize == 0) return *this; if (this != &rightSide) { this->~List(); NodePointer origPtr, lastPtr; first = new Node(rightSide.first->data); // copy first node lastPtr = first; origPtr = rightSide.first->next; while (origPtr != 0) { lastPtr->next = new Node(origPtr->data); origPtr = origPtr->next; lastPtr = lastPtr->next; } } return *this; }

//-- Definition of insert() void List::insert(ElementType dataVal, int index) { if (index < 0 || index > mySize) { cerr << "Illegal location to insert -- " << index << endl; return; } mySize++; NodePointer newPtr = new Node(dataVal), predPtr = first; if (index == 0) { newPtr->next = first; first = newPtr; } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; newPtr->next = predPtr->next; predPtr->next = newPtr; } } //-- Definition of erase() void List::erase(int index) { if (index < 0 || index >= mySize) { cerr << "Illegal location to delete -- " << index << endl; return; } mySize--; NodePointer ptr, predPtr = first; if (index == 0) { ptr = first; first = ptr->next; delete ptr; } else { for (int i = 1; i < index; i++) predPtr = predPtr->next; ptr = predPtr->next; predPtr->next = ptr->next; delete ptr; } }

//-- Definition of display() void List::display(ostream & out) const { NodePointer ptr = first; while (ptr != 0) { out << ptr->data << " "; ptr = ptr->next; } }

//-- Definition of the output operator ostream & operator<<(ostream & out, const List & aList) { aList.display(out); return out; }

#header.file

//----- List.h ----- #ifndef LINKEDLIST #define LINKEDLIST #include using namespace std;

typedef int ElementType; class List { private: class Node { public: ElementType data; Node * next; Node() : next(0) { } Node(ElementType dataValue) : data(dataValue), next(0) { } }; //--- end of Node class

typedef Node * NodePointer;

public: //------ List OPERATIONS List(); List(const List & origList); ~List(); const List & operator=(const List & rightSide); bool empty(); void insert(ElementType dataVal, int index); void erase(int index); void display(ostream & out) const; private: //------ DATA MEMBERS NodePointer first ; int mySize; }; //--- end of List class

ostream & operator<<(ostream & out, const List & aList); //istream & operator>>(istream & in, List & aList); #endif

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!