C++ code only
Inventory Items:
We're going to do an inventory management system. In the real world, this would use a database, not a file. A single inventory item contains:
item names (or description), like "socks, - red" or "socks - blue". This has to be a character string that WILL include spaces.
item numbers that are unique to the item, similar to UPC codes, like 121821 or 128122. Even though they look like numbers, they are really character strings.
a price, like 4.99, a double.
a quantity on hand, like 13, an integer.
Your program will need to manage arrays of these items.
-----------------------------------------------------------------------------------
Menu:
Your code need to have the following features, all accessible from a menu.
Add a new inventory item to the data into the array in memory. You'll type in the inventory number, description, quantity and price. This will also update the number of items on the menu screen.
List the inventory (in the array in memory) on the screen in neat columns. Display it in chucks of 15 items with a pause in between.
Search the inventory (in the array in memory) for an item by inventory number. If found, print the stored info, otherwise print 'not found'.
Calculate the total value on hand of the inventory (in the array in memory). The sum is the accumulation of all the (quantities * prices).
Save the array in memory to a disk file. It can then be loaded later.
Read from a disk file to the array in memory. This will overwrite the array in memory with new information from the disk. If you data isn't saved, it will be lost. That how is SHOULD work!
----------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
Menu Sample:
56 items stored
1) Add an item to memory
2) Search memory for an item
3) List what's in memory
4) Total value on hand
5) Save to a file
6) Read in from a file
0) Exit Program
Enter Choice:
-------------------------------------------------------------------------------------------------------------------
How to store the arrays: Parallel Arrays Option
You can maintain 4 arrays, one for each type. You will need to be careful to keep the items in the same position.
string descriptions[1000];
string idNumbers[1000];
float prices[1000];
int quantity[1000];
In this scenario, an item will be spread over the 4 arrays, but all at the same index.
------------------------------------------------------------------------------------------------------------------------------
How to store the data on the disk:
You are required to use the following text based format
Socks - Blue (in the inventory file)
74627204651538
4.99
27
Yellow Socks
25435567456723452345
7.99
27
Each individual item is stored in 4 separate lines. Records follow each other directly.

Respuesta :

Using the computational language C++ it is possible to write a code is possible to create a function that stores items like this:

Writting the code in C++:

//Header files

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

//Class inventoryItem

class inventoryItem

{

public:

//Variable declaration

string itemName;

string itemNumber;

double itemPrice;

int itemQuantity;

};

//implementation of menuItems() function.

void menuItems()

{

// Display the Menu

cout << "=============================\n";

cout << " 1) Add an item to memory\n"

<< " 2) Search memory for an item \n"

<< " 3) List what's in memory\n"

<< " 4) Total value on hand\n"

<< " 5) Save to a file\n"

<< " 6) Read from a file\n"

<< " 0) Exit Program" << endl;

}

//main method.

int main()

{

//variable declaration.

int mnuChoice, cn = 0, d;

string n;

double sum = 0, c;

int temp;

string a, b;

string inputBuffer;

inventoryItem items[100];

ifstream inventoryFile("inventory.txt");

if (inventoryFile)

{

//store the data from the file to memory.

while (!(inventoryFile.eof()))

{

inventoryFile >> items[cn].itemName;

inventoryFile >> items[cn].itemNumber;

inventoryFile >> inputBuffer;

items[cn].itemPrice = atof(inputBuffer.c_str());

inventoryFile >> inputBuffer;

items[cn].itemQuantity = atoi(inputBuffer.c_str());

cn++;

}

inventoryFile.close();

ifstream inventoryFile("inventory.txt");

ofstream fout;

fout.open("inventory.txt");

do

{

menuItems();

cout << cn << " items stored." << endl;

// Prompt and read choice form the user

cout << "Enter your choice: ";

cin >> mnuChoice;

switch (mnuChoice)

{

//Add a new inventory item to the data in memory.

case 1:

// Prompt and read name of the item from the user

cout << "Enter name of the item: ";

cin >> inputBuffer;

items[cn].itemName = inputBuffer;

// Prompt and read itemNumber from the user

cout << "Enter the itemNumber: ";

cin >> inputBuffer;

items[cn].itemNumber = inputBuffer;

// Prompt and read itemPrice from the user

cout << "Enter the itemPrice: ";

cin >> inputBuffer;

items[cn].itemPrice = atof(inputBuffer.c_str());

// Prompt and read itemQuantity from the user

cout << "Enter the itemQuantity: ";

cin >> inputBuffer;

items[cn].itemQuantity = atoi(inputBuffer.c_str());

cn++;

break;

//Search the inventory for an item by inventory number.

case 2:

temp = 0;

cout << "Enter inventory itemNumber: ";

cin >> n;

for (int i = 0; i < cn&&temp != 1; i++)

{

// If found, print the stored info

if (items[i].itemNumber.compare(n) == 0)

{

// Display the stored information

cout << "Item Name" << "\t" << "Item Number" << "\t" << " Item Price" << "\t" << " Item Quantity" << endl;

cout << items[i].itemName << "\t " << items[i].itemNumber << " \t" << items[i].itemPrice << "\t " << items[i].itemQuantity << endl;

temp = 1;

}

}

// otherwise print 'not found'.

if (temp == 0)

{

cout << "Not found!!!" << endl;

}

break;

//List the inventory on the screen

case 3:

cout << "The data in the memory is:" << endl;

cout << "Item Name" << "\t" << "Item Number" << "\t" << " Item Price" << "\t" << " Item Quantity" << endl;

for (int i = 0; i < cn; i++)

{

cout << items[i].itemName << "\t " << items[i].itemNumber << "\t " << items[i].itemPrice << " \t" << items[i].itemQuantity << endl;

}

break;

// Calculate the total value on hand.

case 4:

for (int i = 0; i < cn; i++)

{

// The sum is the accumulation of all the (quantities * prices).

sum += items[i].itemPrice*items[i].itemQuantity;

}

cout << "sum value on hand: " << sum << endl;

break;

// Save the inventory data in the given file

case 5:

for (int i = 0; i < cn; i++)

{

if (i == cn - 1)

{

fout << items[i].itemName << " \t" << items[i].itemNumber << " \t" << items[i].itemPrice << " \t" << items[i].itemQuantity;

}

else

{

fout << items[i].itemName << " \t" << items[i].itemNumber << " \t" << items[i].itemPrice << " \t" << items[i].itemQuantity << endl;

}

}

break;

// Read the data from the file

case 6:

while (!(inventoryFile.eof()))

{

inventoryFile >> a;

inventoryFile >> b;

inventoryFile >> inputBuffer;

c = atof(inputBuffer.c_str());

inventoryFile >> inputBuffer;

d = atoi(inputBuffer.c_str());

// Dsiplays the data in the file

cout << a << " " << b << " " << c << " " << d << endl;

}

break;

}

// Check the menu choice is not equal to 0,

//if it is equal exit from the loop

} while (mnuChoice != 0);

// File closed

fout.close();

inventoryFile.close();

}

// If the inventory file does not exist

// and then display the error message.

else

{

cout << "File does not exist!" << endl;

}

return 0;

}

See more about C++ code at brainly.com/question/17544466

#SPJ1

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira