I need some assistance with this lab, any help will be appreciated. I will attach a .txt file, with my programming so far.


Thanks, I appreciate all those who take time out of their day to help.



Description


Modify the Inventory program from Lab 5 to add file I/O to the Inventory class. Perform the following.
Inventory Class

Add class level attributes and methods to maintain the list of loans. The array of inventory items should be kept in the Inventory class using a class level array (static).

Add the class level data member to store the number of inventory items.

The sortInventory and searchInventory functions will be part of the Inventory class instead of separate functions. They will be class level functions.

A new class level member function called getNumberOfItems will be added to return the number of inventory items in the file (array).

A new class level member function called initialize that will open the Inventory file, read the inventory records and add inventory objects to the array.

A new class level member function called terminate that will write the records back to the file and close the file.

A new class level member function call addInventory will be added to add an inventory item to the array.

A new class level member function called deleteInventory will be added to delete an inventory item from the array.

A new class level member function called updateInventory will be added to update an inventory item .

A new class level member function called getInventory will be added to return the nth inventory item.

main.cpp – Source File

The options in main will remain the same. It will need to be modified to use the new class level functions.
Inventory.txt – Data File


The file is a Sequential Access file with fixed length records containing the inventory ID, type, description, quantity, and unit cost for each inventory item.

Attachments
\\:Inventory
.h
#ifndef INVENTORY_H
#define INVENTORY_H

#include <string> //program uses string
using std::string; //program uses string

class Inventory //Inventory class definition

{
	private:
		
		int inventoryID; //variable
		int inventoryType, type; //variable
		string inventoryDescription; //variable
		int inventoryQuantity; //variable
		float inventoryUnitCost; //variable
		string getType; //variable

		
	public:
		
		void addItems(int, float); //function to update the quantity and unit cost of the Inventory
		
		string getDescription(); //function to retrieve the item description
		int	   getID(); //function to retrieve the item ID
		float  getPrice(); //function to retrieve the item's price
		int    getQuantity(); //function to retrieve the item's quantity
		float  getUnitCost(); //function to retrieve the item's unit cost
		int    getInventoryType(); //function to retrieve the Inventory type
		float  getPriceDurable(); //function to retrieve the Durable price
		float  getPriceClothing(); //function to retrieve the Clothing price
		float  getPriceGrocery(); //function to retrieve the Grocery Price

		string getTypeString();  //function to retrieve the type string
		void setDescription(string); //function to set the item description
		void setID(int); //function to set the item ID
		void setQuantity(int); //function to set the item quantity
		void setInventoryType(int); //function to set the inventory type
		void setUnitCost(float); //function to set the unit cost

};

#endif
\\:main
.cpp
//Lab 05
// This program will give the user a place to input the quantity and the unit cost.

#include "Inventory.h"  //using the header file Inventory.h
#include <iomanip> //parameterized stream manipulators
#include <string>  //makes the program use strings
#include <iostream> //allows program to perform input and output
using std::cin;  //program uses cin
using std::cout; //program uses cout
using std::endl; //program uses endl
using std::string; //program uses string
using std::fixed; //ensures that decimal point is displayed
using std::left;
using std::getline; //program uses getline
using std::setprecision; //sets numeric output precision
using std::setiosflags;
using std::setw;

bool verifyValue(char *s);


int searchInventory(Inventory[], int, int);
void sortInventory(Inventory[], int);



int main ()

{
	
	//variable declarations
	int option, id, type, quantityAdded;
	int i = 0;
	int quantity;
	float unitCost;
	string description;

	int numberOfItems=0;
	Inventory inventoryItem[25];

	int x = 0;
	int searchInventory(Inventory Array[], int setID, int numberOfItems); //includes searchInventory
	int sortInventory (Inventory Array[], int setID, int numberOfItems); //includes sortInventory
	int index;

	char inputString[100];
	char *idString, *descriptionString, *typeString, *quantityString, *unitCostString;


	do
	
	{
		cout << "\nSelect one of the following options." << endl
			 << "\n1. Add An Inventory Item: " << endl
			 << "2. Update An Inventory Item: " << endl
			 << "3. Receive Inventory: " << endl
			 << "4. Delete An Inventory Item: " << endl
			 << "5. Display Inventory: " << endl
			 << "6. Exit: " << endl;
		
		cin  >> option;//read integer from user into option

		switch (option) //display case for option chosen by user
		
		{
		
		case 1:

			cout << "\nEnter the ID, Type, Descripiton, Quantity, and Unit Cost of the item seperated  by commas." << endl; //prompt user for data
			cout << "\nSelect one of the following for a type." << endl; //prompt user for data
			cout << "Type 1: Durable Goods:" << endl; // One of the type that the user could select
			cout << "Type 2: Clothing:" << endl; // One of the type that the user could select
			cout << "Type 3: Grocery:" << endl; // One of the type that the user could select
			
			cin.get();
			cin.getline(inputString, 100, '\n'); //gets input from user

			idString = strtok (inputString, ",");
			if (verifyValue(idString))
				id = atoi(idString);
			else
			{
				cout << "\nID has an invalid value." << endl;  //tells the user its an invalid value
				id = numberOfItems + 1;
			}
			inventoryItem[numberOfItems].setID(id);

			typeString = strtok(NULL, ",");
			if (verifyValue(typeString))
				type = atoi(typeString);
			else
			{
				cout << "Type has an invalid value." << endl;
				type = numberOfItems + 1;
			}
			inventoryItem[numberOfItems].setInventoryType(type);

			descriptionString = strtok (NULL, ",");
			description = descriptionString;
			inventoryItem[numberOfItems].setDescription(description);

			quantityString = strtok (NULL, ",");
			if (verifyValue(quantityString))
				quantity = atoi(quantityString);
			else
			{
				cout << "Quantity has an invalid value." << endl;
				quantity = numberOfItems + 1;
			}
			inventoryItem[numberOfItems].setQuantity(quantity);

			unitCostString = strtok (NULL, ",");
			if (verifyValue(unitCostString))
				unitCost = atof(unitCostString);
			else
			{
				cout << "Unit Cost has an invalid value." << endl;  //tells the user it is an invalid value
				unitCost = numberOfItems + 1;
			}
			inventoryItem[numberOfItems].setUnitCost(unitCost);
			
			numberOfItems++;

			break;



		case 2:

		/*	cout << "Enter the inventory ID:"; //prompt user for data
			cin  >> id; //read and stores the user input
			i = searchInventory (inventoryItem, id, numberOfItems);
			cout << i <<endl;
			
			cout << "Update Description:"; //prompt user for data
			cin  >> description; //read and stores the user input
			inventoryItem[i].setDescription(description);
			
			cout << "Update Quantity:"; //prompt user for data
			cin  >> quantity; //read and stores the user input
			inventoryItem[i].setQuantity(quantity);
		
			cout << "Update Unit Cost:"; //prompt user for data
			cin  >> unitCost; //read and stores the user input
			inventoryItem[i].setUnitCost(unitCost);
			*/

			break;

		case 3:

			cout << "Enter the ID, Quantity Received, and the Unit Cost." << endl;
			cout << "Seperate them by commas." << endl;
			cin>> quantity;
	
			
			
			cout << "Enter the inventory ID;"; //prompt user for data
			cin  >> id; //read and stores the user input

			i =  searchInventory (inventoryItem, id, numberOfItems);
			cout << i <<endl;

			cout << "Enter quantity to add:" << endl; //prompt user for data
			cin  >> quantityAdded; //read and stores the user input
			inventoryItem[i].setQuantity(quantity + quantityAdded);

			cout << "Enter Unit Cost:" << endl; //prompt user for data
			cin  >> unitCost; //read and stores the user input
			inventoryItem[i].setUnitCost(unitCost);
				
			break;

		case 4:

			cout << "Enter the inventory ID:" << endl; //prompt user for data
			cin  >> id; //read and stores the user input

			index = searchInventory(inventoryItem, id, numberOfItems);
			cout << index <<endl;

				for(i=index; i<numberOfItems-1; i++)
				{
					inventoryItem[i] = inventoryItem[i+1];
				}

				numberOfItems = numberOfItems - 1;

			break;

		case 5:

			cout << setw(11) << left << "\nID"
				 << setw(18) << left << "Type"
				 << setw(16) << left << "Description"
				 << setw(9)  << left << "QOH"
				 << setw(11) << left << "Cost"
				 << left << "Price"
				 << endl;

			for (i=0; i<numberOfItems; i++)
			
			{

				sortInventory(inventoryItem, id, numberOfItems);
				cout << setw(10) << left << inventoryItem[i].getID()
					 << setw(19) << left << inventoryItem[i].getTypeString()
					 << setw(16) << left << inventoryItem[i].getDescription()
					 << setw(9)  << left << inventoryItem[i].getQuantity()
					 << setw(10) << left << setprecision(2) << fixed << inventoryItem[i].getUnitCost()
					 << setprecision(2)  << left << fixed << inventoryItem[i].getPrice()
					 << endl;
			}
			
			break;

		case 6:
			cout<< "\nThank you and have a nice day." << endl; //a message to the user when they decide to exit the program

			break;

		default:
			cout<<"\nPlease choose an option from 1-6."<<endl;  //tells the user to select an option on the screen which is between 1 and 4
		
		}
	}while (option !=6); //option must be below 6
	

	return 0; //indicate that program ended successfully
}

\\:Inventory
.cpp
#include "Inventory.h" //include the Inventory header file

void Inventory::addItems(int quantity, float unitCost)
{	
	inventoryUnitCost = (inventoryQuantity * inventoryUnitCost) + (quantity * unitCost); //total inventory unit cost equals quantity times unit cost plus quantity added times quantity added unit cost 
	inventoryQuantity += quantity; //inventory quantity equals old inventory quantity plus quantity added
	inventoryUnitCost = inventoryUnitCost / inventoryQuantity; //final inventory unit cost equals total inventory unit cost divded by total quantity
} //end of the function

string Inventory::getDescription() //function to retrieve item description
{
	return inventoryDescription;
} //end of the function

int Inventory::getID()  //function to retrieve item ID
{
	return inventoryID;
} //end of the function

int Inventory::getInventoryType() //function to retrieve item type
{
	return inventoryType;
} //end of the function

float Inventory::getPriceDurable()
{
	float price;

		if (inventoryUnitCost<=100)
			price = inventoryUnitCost + (inventoryUnitCost * .24); //multiplies the inventory cost and the markup
		else

			if (inventoryUnitCost>100, inventoryUnitCost<=500)
				price = inventoryUnitCost + (inventoryUnitCost * .15);  //multiplies the inventory cost and the markup
			else

				if (inventoryUnitCost>500)
					price = inventoryUnitCost + (inventoryUnitCost * .115); //multiplies the inventory cost and the markup

	return price;
} //end of the function

float Inventory::getPriceClothing()
{
	float price;

		if (inventoryUnitCost<=75)
			price = inventoryUnitCost + (inventoryUnitCost * .15); //multiplies the inventory cost and the markup
		else

			if (inventoryUnitCost>75, inventoryUnitCost<=200)
				price = inventoryUnitCost + (in

Just read through the description and I need help altering my program to get this thing. You will have to look at my program first and then read the description to understand this better.

The descriptions appear to be pretty clear to me. Just start at the top of the list and implement each one at a time. After you do the first requirement then compile and fix all errors. Then go on to the next requirement.

Sorry I am really new at C++ programming and I need a push start on how to apply these.
Thanks

I actually took the time to do that project and find some confusing instructions:

>> Add class level attributes and methods to maintain the list of loans.
This is an inventory program, not a loan progam.

many of those new Inventory class methods need to be static, not class-level member functions. For example, searchInventory can't be used as a class-level function because you need an instance of the class to call it, which doesn't make sence. Several others are like that too.

I think you need to get clarification of these issues with your instructor.

Thank you so much for trying to do this, I will either see my instructor tomorrow or Monday. I will let you know what he says, but he's not the greatest teacher and I know he is teaching us things that are not as effiecient as others. But I will let you know.

This is all I got out of the instructor, see if you can get anything with this.

Believe this goes in the Inventory.cpp

Inventory::addInventory(Inventory variableName) void addInventory(Inventory);
{
inventoryItems[numberOfItems]=variableName;
numberOfItems ++;
}
Inventory Inventory::getInventory(int n)
{
return inventoryItems[n];
}


Then add this to the Inventory.h

Private:
static Inventory inventoryItems[25];
static int numberofItems;

Public:
static void addInventory(Inventory);
static Inventory getInventory(int);

though, yo have not solved out what AD said... there's a lot of function in your inventory class that you should better use as general functions...

This is some more stuff. I am this close to paying someone to do this for me.

main.cpp
  case 5:
/*
   cout << setw(11) << left << "\nID"
     << setw(18) << left << "Type"
     << setw(16) << left << "Description"
     << setw(9)  << left << "QOH"
     << setw(11) << left << "Cost"
     << left << "Price"
     << endl;
   for (i=0; i< Inventory::getNumberOfItems(); i++)
   
   {
    inventoryItems = Inventory::getInventory(i);
    sortInventory(inventoryItem, id, numberOfItems);
    cout << setw(10) << left << inventoryItem[i].getID()
      << setw(19) << left << inventoryItem[i].getTypeString()
      << setw(16) << left << inventoryItem[i].getDescription()
      << setw(9)  << left << inventoryItem[i].getQuantity()
      << setw(10) << left << setprecision(2) << fixed << inventoryItem[i].getUnitCost()
      << setprecision(2)  << left << fixed << inventoryItem[i].getPrice()
      << endl;
   }
*/   
   break;
 

Inventory.h
#ifndef INVENTORY_H
#define INVENTORY_H
#include <string> //program uses string
using std::string; //program uses string
class Inventory //Inventory class definition
{
 private:
  
  int inventoryID; //variable
  int inventoryType, type; //variable
  string inventoryDescription; //variable
  int inventoryQuantity; //variable
  float inventoryUnitCost; //variable
  string getType; //variable
  static Inventory inventoryItems[25];
  static int numberOfItems;
  
 public:
  
  void addItems(int, float); //function to update the quantity and unit cost of the Inventory
  
  string getDescription(); //function to retrieve the item description
  int    getID(); //function to retrieve the item ID
  float  getPrice(); //function to retrieve the item's price
  int    getQuantity(); //function to retrieve the item's quantity
  float  getUnitCost(); //function to retrieve the item's unit cost
  int    getInventoryType(); //function to retrieve the Inventory type
  float  getPriceDurable(); //function to retrieve the Durable price
  float  getPriceClothing(); //function to retrieve the Clothing price
  float  getPriceGrocery(); //function to retrieve the Grocery Price
  string getTypeString();  //function to retrieve the type string
  void setDescription(string); //function to set the item description
  void setID(int); //function to set the item ID
  void setQuantity(int); //function to set the item quantity
  void setInventoryType(int); //function to set the inventory type
  void setUnitCost(float); //function to set the unit cost
  static void addInventory(Inventory);   (one of these is not needed, can't remember which one)
  static Inventory getInventory(int);
  static getNumberOfItems;
  static Inventory addInventory(inventoryItem);
  static bool termination();
};
#endif

Inventory.cpp
(This stuff at the top)
#include ofstream;
using std::ofstream;
using STD::ifstream;
#include "Inventory.h" //include the Inventory header file
Inventory Inventory::inventoryItems[25],
int Inventory::numberOfItems = 0;
Inventory::addInventory(Inventory variableName) void addInventory(Inventory);
{
 inventoryItems[numberOfItems]=variableName;
 numberOfItems ++;
}
Inventory Inventory::getInventory(int n)
{
 return inventoryItems[n];
}
void Inventory::addInventory(Inventory Item)
{
 inventoryItems(numberOfItems) = item
 numberOfItems++
}

(This stuff at the bottom)

bool Inventory::termination()
{
 ofstream outFile('Inventory.txt'. int::out)
  if (!outFile)
   return false
 for (int i = 0 i < numberOfItems i++)
 {
  outFile.write(reinterpret_cast(char *> (&inventoryItems[i]. inventoryID).sizeof(inventoryID))
  outFile.write(reinterpret_cast(char *> (&inventoryItems[i]. inventoryType).sizeof(inventoryType))
  outFile.write(reinterpret_cast(char *> (&inventoryItems[i]. inventoryQuantity).sizeof(inventoryQuantity))
  outFile.write(reinterpret_cast(char *> (&inventoryItems[i]. inventoryUnitCost).sizeof(inventoryUnitCost))
 }
 return true
}

Thanks for the help

Please keep posting and give me some more ideas with this. I know I am not the greatest help, but I will try to answer what I can. Any assistance would be a great deal of help.

This article has been dead for over six months. Start a new discussion instead.