Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab, you will use the code in the List .cpp file and the List .h file to make a list of items for

For this lab, you will use the code in the List.cpp file and the List.h file to make a list of items for a camera store, and implement functions to insert, find, erase, display items.

You will have to modify the code, since it was written for a list of integers. The items for the list are in a file called InventoryFile.txt

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 probably have to define a struct, to hold the info for each item, and then your list will be an array of the structs. Your driver file should create the list, read in all the items, and then ask the user what to do (insert, delete, etc) When you are done, the list should be output to a file called NewInventory.

____________________________________________________________________________________________________________

/*-- List.h --------------------------------------------------------------- This header file defines the data type List for processing lists. Basic operations are: Constructor empty: Check if list is empty insert: Insert an item erase: Remove an item display: Output the list <<: Output operator -------------------------------------------------------------------------*/ #include  #ifndef LIST #define LIST const int CAPACITY = 1024; typedef int ElementType; class List { public: /******** Function Members ********/ /***** Class constructor *****/ List(); /*---------------------------------------------------------------------- Construct a List object. Precondition: None Postcondition: An empty List object has been constructed; mySize is 0. -----------------------------------------------------------------------*/ /***** empty operation *****/ bool empty() const; /*---------------------------------------------------------------------- Check if a list is empty. Precondition: None Postcondition: true is returned if the list is empty, false if not. -----------------------------------------------------------------------*/ /***** insert and erase *****/ void insert(ElementType item, int pos); /*---------------------------------------------------------------------- Insert a value into the list at a given position. Precondition: item is the value to be inserted; there is room in the array (mySize < CAPACITY); and the position satisfies 0 <= pos <= mySize. Postcondition: item has been inserted into the list at the position determined by pos (provided there is room and pos is a legal position). -----------------------------------------------------------------------*/ void erase(int pos); /*---------------------------------------------------------------------- Remove a value from the list at a given position. Precondition: The list is not empty and the position satisfies 0 <= pos < mySize. Postcondition: element at the position determined by pos has been removed (provided pos is a legal position). ----------------------------------------------------------------------*/ /***** output *****/ void display(ostream & out) const; /*---------------------------------------------------------------------- Display a list. Precondition: The ostream out is open. Postcondition: The list represented by this List object has been inserted into out. -----------------------------------------------------------------------*/ private: /******** Data Members ********/ int mySize; // current size of list stored in myArray ElementType myArray[CAPACITY]; // array to store list elements }; //--- end of List class //------ Prototype of output operator ostream & operator<< (ostream & out, const List & aList); #endif

_________________________________________________________________________

/*-- List.cpp------------------------------------------------------------ This file implements List member functions. -------------------------------------------------------------------------*/ #include  using namespace std; #include "List.h" //--- Definition of class constructor List::List() : mySize(0) {} //--- Definition of empty() bool List::empty() const { return mySize == 0; } //--- Definition of display() void List::display(ostream & out) const { for (int i = 0; i < mySize; i++) out << myArray[i] << " "; } //--- Definition of output operator ostream & operator<< (ostream & out, const List & aList) { aList.display(out); return out; } //--- Definition of insert() void List::insert(ElementType item, int pos) { if (mySize == CAPACITY) { cerr << "*** No space for list element -- terminating " "execution *** "; exit(1); } if (pos < 0 || pos > mySize) { cerr << "*** Illegal location to insert -- " << pos << ". List unchanged. *** "; return; } // First shift array elements right to make room for item for(int i = mySize; i > pos; i--) myArray[i] = myArray[i - 1]; // Now insert item at position pos and increase list size myArray[pos] = item; mySize++; } //--- Definition of erase() void List::erase(int pos) { if (mySize == 0) { cerr << "*** List is empty *** "; return; } if (pos < 0 || pos >= mySize) { cerr << "Illegal location to delete -- " << pos << ". List unchanged. *** "; return; } // Shift array elements left to close the gap for(int i = pos; i < mySize; i++) myArray[i] = myArray[i + 1]; // Decrease list size mySize--; }

__________________________________________________________________________________

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

____________________________________________________________

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago