Question

In: Computer Science

A college must track equipment items purchased using special funds. Create an Inventory class that represents...

A college must track equipment items purchased using special funds.

Create an Inventory class that represents an equipment item. An equipment item consists of an 8-alphanumeric inventory number, a short description of the item, the purchase price of the item, and its current location (e.g.: room/building location). If an item is surplussed (e.g., gotten rid of), then the current location should say surplus, but the item should remain on the list.

Write a program that reads inventory items from a file into a vector. Implement a menu system that allows the user to add, edit, and delete records from the list as well as search the list based on inventory number and print a report of all records.
The list should always be maintained in order of inventory number. When the program closes, the data file should be overwritten with the most recent data from the list.

Implement one of the sorting and searching algorithms from the chapter. Do not use the built-in sort function.

Be sure to use the same menu options as shown in the example so the auto-grader can accurately grade your assignment.

Sample

MAIN MENU
1 - Add
2 - Edit
3 - Delete
4 - Search
5 - Print All
6 - Exit
Choice: 2

Enter inventory number to edit: 12-2322-12
Curent Values
12-2322-12 Printer 800.00 PW-590

EDIT MENU
1 - Inventory Number
2 - Description
3 - Price
4 - Location
5 - Done
Choice: 3
Enter new price: 820.00
EDIT MENU
1 - Inventory Number
2 - Description
3 - Price
4 - Location
5 - Done
Choice: 1
Enter new Inventory Number: 12-AB-3333
Invalid inventory number.
EDIT MENU
1 - Inventory Number
2 - Description
3 - Price
4 - Location
5 - Done
Choice: 5
MAIN MENU
1 - Add
2 - Edit
3 - Delete
4 - Search
5 - Print All
6 - Exit
Choice: 5

12-1194-94 Switch 417.00 TR-123
12-1232-35 Monitor 300.00 Surplus
12-1384-91 MicroPlus 1200.00 Surplus
12-2322-12 Printer 820.00 PW-590
12-3245-21 Test 120.00 Surplus
14-4343-41 Cabinet 175.00 AW-212
14-4992-22 Bookshelf 375.00 BN-100
14-8383-12 Chair 70.00 BN-100
14-9842-85 Desk 283.00 BN-100
14-9923-95 Typewriter 120.00 Surplus

MAIN MENU
1 - Add
2 - Edit
3 - Delete
4 - Search
5 - Print All
6 - Exit
Choice: 6

Need the answer in C++ and always need a .cpp file, .h file, and driver file

Solutions

Expert Solution

Working code implemented in C++ and appropriate comments provided for better understanding.

Here I am attaching code for these files:

  • main.cpp
  • Inventory.cpp
  • Inventory.h

main.cpp:

#include <iostream>
#include <fstream>
#include <vector>
#include "Inventory.h"
#include <iomanip>

using namespace std;

int main() {
   string partNumber, name, location;
   double price;
   bool stop = false, recordFound;
   int selection, recordNumber;

   vector<Inventory> partList;
   ifstream inputFile;
   inputFile.open("items.txt");

   if (!inputFile) {
       cerr << "Unable to open file items.txt";
       exit(1); // call system to stop
   }

   while(inputFile) {
       inputFile >> partNumber;
       inputFile >> name;
       inputFile >> price;
       inputFile >> location;
       partList.push_back(Inventory(partNumber, name, price, location));
   }
   partList.pop_back();
  
   cout << "\n\t***********************\n\t** Current Inventory **\n\t***********************\n";
   for (int i = 0; i < partList.size(); i++) {
       cout << fixed << setprecision(2) << "Record Number: " << i + 1 << setw(8) << left << " " << setw(12) << left << partList[i].getPartNumber() << " " << setw(12) << left <<
           partList[i].getName() << " " << setw(12) << left << partList[i].getPrice() << " " << partList[i].getLocation() << endl;
   }
  
   while (!stop) {
       cout << "\n\nWhat action would you like to perform?\n 1. Add\n 2. Edit\n 3. Delete\n 4. Search\n 5. Print all\n 6. Exit\n";
       cin >> selection;
       switch (selection) {
           case 1: //add a record
               cout << "You've selected to add a record..\nPlease enter the inventory number: ";
               cin >> partNumber;
               cout << "Please enter the name of the item (as one word): ";
               cin >> name;
               cout << "Please enter the cost of the item: ";
               cin >> price;
               cout << "Please enter the location of the item: ";
               cin >> location;
               cout << "\n*Confirm addition of record: " << partNumber << " " << name << " " << price << " " << location << endl << "Press 1 to add\nPress 0 to cancel";
               cin >> selection;
               if (selection == 1) {
                   partList.push_back(Inventory(partNumber, name, price, location));
               }
               else {
                   cout << "\nRecord was not added.";
               }
               break;
           case 2: //edit a record
               cout << "\nYou've selected to edit a record..\nSelect the number of Inventory Number record you would like to edit: ";
               cin >> recordNumber;
               cout << "You've selected record number: " << recordNumber;
               cout << "\n1. Inventory Number \n2. Description \n3. Price \n4. Location\n5. Done \n";
               cin >> selection;
               if (selection == 1) {
                   cout << "Please enter the new inventory number: ";
                   cin >> partNumber;
                   partList[recordNumber - 1].setPartNumber(partNumber);
               }
               else if (selection == 2) {
                   cout << "Please enter the new item name: ";
                   cin >> name;
                   partList[recordNumber - 1].setName(name);
               }
               else if (selection == 3) {
                   cout << "Please enter the new item price: ";
                   cin >> price;
                   partList[recordNumber - 1].setPrice(price);
               }
               else if (selection == 4) {
                   cout << "Please enter the new item location: ";
                   cin >> location;
                   partList[recordNumber - 1].setLocation(location);
               }
           else if(selection == 5)
{
break;
}
           case 3: //remove a record
               cout << "\nYou've selected to delete a record..\nSelect the number of the record you would like to delete: ";
               cin >> recordNumber;
               cout << "\nYou've selected: ";
               cout << fixed << setprecision(2) << "Record Number: " << recordNumber << " " << partList[recordNumber - 1].getPartNumber() << " " <<
                   partList[recordNumber - 1].getName() << " " << partList[recordNumber - 1].getPrice() << " " << partList[recordNumber - 1].getLocation() << endl;
               cout << "\nConfirm Deletion\nPress 1 for yes\nPress 0 for no\n";
               cin >> selection;
               if (selection == 1) {
                   partList.erase(partList.begin() + recordNumber - 1);
               }
               else {
                   cout << "Deletion canceled\n";
               }
               break;
           case 4: //search a record
               cout << "You've selected to search for a record..\nPlease enter the inventory of the record using the format (XX-XXXX-XX): ";
               cin >> partNumber;
               recordFound = false;
               for (int i = 0; i < partList.size(); i++) {
                   if (partList[i].getPartNumber() == partNumber) {
                       cout << "This record exists: \n" << fixed << setprecision(2) << "Record Number: " << i + 1 << " " << partList[i].getPartNumber() << " " <<
                           partList[i].getName() << " " << partList[i].getPrice() << " " << partList[i].getLocation() << endl;
                       recordFound = true;
                   }
                   if (recordFound == false && (i + 1) == partList.size()) {
                       cout << "\nThere was no record for this inventory number";
                   }
               }
               break;
           case 5: //print all records
               cout << "\n\t***********************\n\t** Current Inventory **\n\t***********************\n";
               for (int i = 0; i < partList.size(); i++) {
                   cout << fixed << setprecision(2) << "Record Number: " << i + 1 << setw(8) << left << " " << setw(12) << left << partList[i].getPartNumber() << " " << setw(12) << left <<
                       partList[i].getName() << " " << setw(12) << left << partList[i].getPrice() << " " << partList[i].getLocation() << endl;
               }
               break;
           case 6: //save and quit
               ofstream outFile("items.txt");
               for (int i = 0; i < partList.size(); i++) {
                   outFile << partList[i].getPartNumber() << " ";
                   outFile << partList[i].getName() << " ";
                   outFile << fixed << setprecision(2) << partList[i].getPrice() << " ";
                   outFile << partList[i].getLocation() << endl;
               }
               stop = true;
               break;
       }
   }

   return 0;
}

Inventory.cpp:

#include "Inventory.h"

Inventory::Inventory() {
   setPartNumber("00 - 0000 - 00");
   setName("Default");
   setLocation("None");
   setPrice(0);
}

Inventory::Inventory(string partNum, string name, double price, string location) {
   setPartNumber(partNum);
   setName(name);
   setLocation(location);
   setPrice(price);
}

void Inventory::setPartNumber(string partNum) {
   partNumber = partNum;
}

void Inventory::setName(string nameOfItem) {
   name = nameOfItem;
}

void Inventory::setLocation(string loc) {
   location = loc;
}

void Inventory::setPrice(double priceOfItem) {
   price = priceOfItem;
}

string Inventory::getPartNumber() {
   return partNumber;
}

string Inventory::getName() {
   return name;
}

string Inventory::getLocation() {
   return location;
}

double Inventory::getPrice() {
   return price;
}

Inventory.h:

#ifndef Inventory_H
#define Inventory_H

#include <string>
using namespace std;

class Inventory {
private:
   string partNumber;
   string name;
   string location;
   double price;
public:
   Inventory();
   Inventory(string partNumber, string name, double price, string location);
   void setPartNumber(string);
   void setName(string);
   void setLocation(string);
   void setPrice(double);
   string getPartNumber();
   string getName();
   string getLocation();
   double getPrice();
};
#endif

Sample Output Screenshots:


Related Solutions

JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
Under LIFO, which items of inventory are considered the first sold? a. The items purchased at...
Under LIFO, which items of inventory are considered the first sold? a. The items purchased at the lowest price b. The items purchased furthest from the date of sale c. The last items purchased d. The first items purchased
What are the major sources of purchased funds? Can using purchased funds change a bank's profitability?...
What are the major sources of purchased funds? Can using purchased funds change a bank's profitability? Its risk level? Explain.
Write a class named GroceryList that represents a list of items to buy from the market,...
Write a class named GroceryList that represents a list of items to buy from the market, and another class named GroceryItemOrder that represents a request to purchase a particular item in a given quantity (example: four boxes of cookies). It also has client class called GroceryClient which creates objects of GroceryList and GroceryItemOrder. (For this assignment, you will have to submit 3 .java files: one for each class and 3 .class files associated with these .java files. So in total...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields in the...
Blue Spruce Company uses special strapping equipment in itspackaging business. The equipment was purchased in...
Blue Spruce Company uses special strapping equipment in its packaging business. The equipment was purchased in January 2019 for $5,100,000 and had an estimated useful life of 8 years with no salvage value. At December 31, 2020, new technology was introduced that would accelerate the obsolescence of Blue Spruce’s equipment. Blue Spruce’s controller estimates that expected future net cash flows on the equipment will be $3,187,500 and that the fair value of the equipment is $2,805,000. Blue Spruce intends to...
Create a class that generates permutations of a set of symbols. Requirements The class must be...
Create a class that generates permutations of a set of symbols. Requirements The class must be named PermutationGenerator. The PermutationGenerator class has two methods as follows. hasNext This method has no parameters.  It returns true if at least one permutation remains to be generated. next This method has no parameters.  It returns an array of the symbols (char[]) in a permutation (if any remain) or null otherwise. The following main method MUST be used, with NO CHANGES to test your class. public static void main(String[] args) { int count = 0; PermutationGenerator pg...
Under LFO which items of inventory are considered the first sold ? The items purchased closest...
Under LFO which items of inventory are considered the first sold ? The items purchased closest to the date of the sale The items purchases furthest from the date of sale
Nash Company uses special strapping equipment in its packaging business. The equipment was purchased in January...
Nash Company uses special strapping equipment in its packaging business. The equipment was purchased in January 2019 for $10,200,000 and had an estimated useful life of 8 years with no salvage value. At December 31, 2020, new technology was introduced that would accelerate the obsolescence of Nash’s equipment. Nash’s controller estimates that expected future net cash flows on the equipment will be $6,426,000 and that the fair value of the equipment is $5,712,000. Nash intends to continue using the equipment,...
Blossom Company uses special strapping equipment in its packaging business. The equipment was purchased in January...
Blossom Company uses special strapping equipment in its packaging business. The equipment was purchased in January 2019 for $6,000,000 and had an estimated useful life of 8 years with no salvage value. At December 31, 2020, new technology was introduced that would accelerate the obsolescence of Blossom's equipment. Blossom's controller estimates that expected future net cash flows on the equipment will be $3,750,000 and that the fair value of the equipment is $3,300,000. Blossom intends to continue using the equipment,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT