Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with simple C++ lab. Most of the code is givin, just need to modify in

ID: 3605725 • Letter: N

Question

Need help with simple C++ lab. Most of the code is givin, just need to modify inventory.cpp. Included all code given though. Thanks.

Inventor.cpp (the one that needs finishing)

Inventory.h:

MAIN:

Item.h:

Item.cpp:

Text Data File:

Learning Objectives: - Coding of a class that uses an array of already-coded objects More practice with Object Oriented Programming Experience with Maintenance Programming: finishing a program mostly written by someone else. General Description: Most of a small project has been coded. It contains the files: -main.cpp item.h item.cpp inventory.h inventory.cpp All are complete except inventory.cpp. You shouldn't have to make any changes to the other files. In inventory.cpp, look for the // TO DO: comments. These will explain what needs to be completed. Startup Instructions: start a new project in MS Visual Studio (Lab9) SAVE all the files given on the website to the source file folder. Ex: C:UserslyourWinld Documents Visual Studio 2015 Projects Lab9 Lab9 -Use the Solution Explorer to: o (if you don't see Solution Explorer, it is under the View menu at the top) o Add Existing Item to the Source Files grouping (all.h and.cpp files) o Add Existing Item to the Resource Files grouping (inventory.txt) Search Solution Explorer Cl Resource File nventory.bt Sample Execution:

Explanation / Answer

===

inventor.cpp

===

#include <iostream>
#include <fstream>
#include <iomanip>
#include "inventory.h"

//----------------------------------------------------------------------------
//                              askNewItem
//----------------------------------------------------------------------------
// asks the user for information on a new item and adds it to the inventory
void inventory::askNewItem() {
   string name, taxYorN;
   int number;
   double price;
   cout << "Enter number, price, name and taxable(Y/N): ";
   cin >> number >> price >> name >> taxYorN;
   // TO DO: add the data to the inventory
   addItem(number, name, price, taxYorN);
} // askNewItem()

//----------------------------------------------------------------------------
//                              addItem
//----------------------------------------------------------------------------
// given data for a new item, checks to see if there is enough room and if so,
// adds it to the inventory
void inventory::addItem(int num, string name, double price, string taxable) {
   if (numItems <= MAX_ITEMS) {
       // TO DO: add the data to the inventory
       items[numItems++].set(num, name, price, taxable);
   } else
       cout << "inventory::addItem(): inventory is full ";
} // addItem()

//----------------------------------------------------------------------------
//                              getItem
//----------------------------------------------------------------------------
// Searches for and retrieves an item from the inventory
// given: an item number to search for
// returns: the found item object; or an empty item object
item inventory::getItem(int num) {
   item emptyItem;         // no need to change anything inside emptyItem
   // TO DO: search for the item; if found, return it; otherwise return emptyItem
   int found = search(num);
   if (found == -1) {
       return emptyItem;
   } else {
       return items[found];
   }

} // getItem()

//----------------------------------------------------------------------------
//                              print
//----------------------------------------------------------------------------
// prints the inventory list
void inventory::print() {
   // TO DO: replace the ITEM_* tags in the following code to print data
   //        from the inventory.
   cout << fixed << setprecision(2);
   cout << "Inventory List: number of items = " << numItems << endl;
   for (int i = 0; i < numItems; i++) {
       cout << left << setw(10) << items[i].getNumber() << setw(20)
               << items[i].getName() << "$" << right << setw(5)
               << items[i].getPrice() << " ";
       if (items[i].isTaxable())
           cout << "Taxable ";
       else
           cout << "Not taxable ";
   }
   cout << endl;
} // print()

//----------------------------------------------------------------------------
//                              read
//----------------------------------------------------------------------------
// reads the inventory from an input file
// file format: list of items, one line per item
//              each line has number, price, taxable (Y or N) and item name
//              item names are assumed to have NO SPACES
//              the last line of the file contains a Sentinel Record:
//              -1 0 N END_OF_DATA
void inventory::read() {
   string name, taxYorN;
   int num;
   double price;
   ifstream f;

   f.open("inventory.txt");
   if (f.fail()) {
       cout << "Unable to open input file. Inventory not read. ";
       return;
   }

   f >> num >> price >> taxYorN >> name;
   while (num != -1) {
       // TO DO: add data just read to the inventory
       addItem(num, name, price, taxYorN);
       f >> num >> price >> taxYorN >> name;
   }
   f.close();
} // read()

//----------------------------------------------------------------------------
//                              lookup
//----------------------------------------------------------------------------
void inventory::lookup() {
   int num;
   cout << "Enter item number: ";
   cin >> num;
   int found = search(num);
   // TO DO: determine if the number was found; finish the coditional expression
   if (found == -1) {
       cout << "Item not found ";
   } else {
       // TO DO: print the data from the found item
       //        replace the ITEM_* tags with code
       cout << items[found].getName() << " " << items[found].getName() << " "
               << items[found].getPrice() << " ";
       if (items[found].isTaxable())
           cout << "Taxable ";
       else
           cout << "Not taxable ";
   }
} // lookup()

//----------------------------------------------------------------------------
//                              search
//----------------------------------------------------------------------------
// searches the inventory list for an item with an item number equal to the
// given num.
// Returns: the INDEX of the item found in the inventory[] array, when found
//          -1 when NOT FOUND
int inventory::search(int num) {
   // TO DO: write the search as described above
   int i = 0;
   int found = 0;
   // TO DO: search for the number just found
   while (true) {
       if (items[i].getNumber() == num) {
           return i;
           break;
       }
       i++;
   }
   return -1;
} // search()

========

1. Print
2. Add Item
3. Lookup Item
0. Exit
1
Inventory List: number of items = 6
1001      Bat                 $22.36 Taxable
1002      Baseball            $ 5.75 Taxable
1003      Glove               $42.59 Taxable
1004      Hot_Dog             $ 2.50 Not taxable
1005      Soft_Drink          $ 1.75 Not taxable
1006      Seat_Cushion        $12.35 Taxable

1. Print
2. Add Item
3. Lookup Item
0. Exit
2
Enter number, price, name and taxable(Y/N): 1007
50
Ball
Y
1. Print
2. Add Item
3. Lookup Item
0. Exit
1
Inventory List: number of items = 7
1001      Bat                 $22.36 Taxable
1002      Baseball            $ 5.75 Taxable
1003      Glove               $42.59 Taxable
1004      Hot_Dog             $ 2.50 Not taxable
1005      Soft_Drink          $ 1.75 Not taxable
1006      Seat_Cushion        $12.35 Taxable
1007      Ball                $50.00 Taxable

1. Print
2. Add Item
3. Lookup Item
0. Exit
3
Enter item number: 1003
Glove Glove 42.59 Taxable
1. Print
2. Add Item
3. Lookup Item
0. Exit
0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote