Answer to Question #266607 in C++ for tutorial

Question #266607

You’ve been asked to write a small menu driven inventory management system for a small convenient

store. Your application shall maintain the following information regarding an item.

Item ID – unsigned long

Item name – string

Item cost – float

Quantity - int

Following are the list of administrative functionalities your application shall support:

1.Add new item to the inventory. This function will be used to add a single new item into the inventory management system.

2.Print all item information in the store - This function will be used to display all items in the inventory. When this option is selected system shall print Item ID, Item name, Item cost and quantity.

3.Find item by ID – This function will be used to search item using an ID. If item exist print item information. If not display an error indicating item not found.


Here is a sample menu.

Inventory Management System Menu

1.Add new item

2.Print item list

3.Find item by ID

4.Find item by name

5.Sort by name

6.Quit







1
Expert's answer
2021-11-16T00:47:15-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


#include<iostream>
using namespace std;


int main()
{


long item_id[3] = {01, 02};
string item_names[3] = {"pen","book"};
float item_cost[3] = {15.0, 40.0};
int item_quantity[3] = {4, 3};
cout<<"Inventory Management System Menu"<<endl;
cout<<"Enter the operation you want to perform "<<endl;
cout<<"1.Add new item"<<endl;
cout<<"2.Print item list"<<endl;
cout<<"3.Find item by ID"<<endl;
cout<<"4.Quit"<<endl;
int option;
cout<<"\nEnter your option: ";
cin>>option;


if(option == 1)
{
	//Prompt the user to enter the attributes adding them to the arrays
	long item_to_add_id;
	string item_to_add_name;
	float item_to_add_cost;
	int item_to_add_quantity;
	
	cout<<"Enter the item id: ";
	cin>>item_to_add_id;
	item_id[2]=item_to_add_id;
	
	cout<<"Enter the item name: ";
	cin>>item_to_add_name;
	item_names[2]=item_to_add_name;
	
	cout<<"Enter the item cost: ";
	cin>>item_to_add_cost;
	item_cost[2]=item_to_add_cost;
	
	cout<<"Enter the item quantity: ";
	cin>>item_to_add_quantity;
	item_quantity[2]=item_to_add_quantity;
	
}


else if(option == 2)
{
	cout<<"Item ID  Item name  Item cost and quantity."<<endl;
	int array_length = sizeof(item_id);
	for(int i = 0; i < array_length; i++)
	{
		cout<<"   "<<item_id[i]<<"          "<<item_names[i]<<"          "<<item_cost[i]<<"          "<<item_quantity[i]<<endl;
	}
	
}
else if(option == 3)
{
	int array_length = sizeof(item_id);
	long my_search_item_id;
	cout<<"Enter the item ID to search: ";
	cin>>my_search_item_id;
	int index;
	int found = 0;
	for(int i = 0; i < array_length; i++ )
	{
		if(my_search_item_id==item_id[i])
		{
			found = 1;
			index = i;
			break;
		}
	}
	
	if(found == 0)
	{
		cout<<"The item with the item id you have entred does not exist"<<endl;
	}
	else
	{
		cout<<"Item ID  Item name  Item cost and quantity."<<endl;
		cout<<"   "<<item_id[index]<<"          "<<item_names[index]<<"          "<<item_cost[index]<<"          "<<item_quantity[index]<<endl;
	}
	
}
else if(option == 4)
{
	cout<<"The program has been exited succesfully."<<endl;
}
else
{
	cout<<"You have entered an invalid option , please try again.";
}


return 0;
		
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS