Question

Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory...

Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory of a store. The program must have a menu that allow to perform the following three actions:

Add a new item

Remove an item

Replicate n times and existing item

The program must have two dynamic arrays: one for store the name of the product and other to store the price of the product. The size of each array must be of the same number as products in the store. Each action must be performed by a function that receives the corresponding parameter to execute each action.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the implementation of the problem in C++:

#include <iostream>
using namespace std;
int size=0;//size of both arrays initially
string *name = new string[size]; //dynamic array to store product name
float *price=new float[size]; //dynamic array to store product price

//fuction to display/ replicate the data
void display()
{
cout<<"\n______Displaying Data_________\n";
cout<<"\nProduct Name\t Price\n---------------------";
for(int i=0;i<size;i++)
cout<<"\n"<<name[i]<<" \t:\t"<<price[i];
}

//fuction to add an item. n is name and p is price
//we used temporary arrays inorder to increase the size dynamically
void addItem(string n, float p)
{
size=size+1; //increase the size by 1
string *nm = new string[size]; //temporary array to store names
float *cost=new float[size]; //temporary array to store prices
int i=0;
//copy data into temporary arrays
for( i=0;i<size-1;i++)
{
nm[i]=name[i];
cost[i]=price[i];
}
nm[i]=n; //assign new name and price at the end of the array
cost[i]=p;
delete [] name; //delete original array as there are of size : size-1
delete [] price;
name = new string[size];
price = new float[size];

//store again the newly created array into old one
for( i=0;i<size;i++)
{
name[i]=nm[i];
price[i]=cost[i];
}

delete [] nm; //delete temporary arrays
delete [] cost;
}

//fuction that removes specific element from array by it's name
void removeItem(string nm)
{
int index=-9; //index of element to be deleted
for(int i=0;i<size;i++)
if(name[i]==nm) //element found
index=i; //mark index

if(index==-9) //not found
cout<<"\nData not found!!";
else //found
{
//if element is not at the last positon then
//shift all the element at i+1 locaion to ith locaion
if(index!=(size-1))
{ for(int i=index;i<size-1;i++)//
{
name[i]=name[i+1];
price[i]=price[i+1];
}
}
//last location is to be deleted
size=size-1;//reduce the size
string *nm1 = new string[size];//temporary arrays
float *cost1=new float[size];
int i=0;
//copy elements into temporary arrays
for( i=0;i<size;i++)
{
nm1[i]=name[i];
cost1[i]=price[i];
}
  
delete [] name;// delete old sized arrays
delete [] price;
  
name = new string[size];//create new size arrays
price = new float[size];
//copy elements into original arrays
for( int i=0;i<size;i++)
{
name[i]=nm1[i];
price[i]=cost1[i];
}
delete [] nm1; //delete temporary arrays
delete [] cost1;

}

}
int main()
{
int ch=1;
string nm;
float p;
while(ch>0&&ch<4)
{
//menu display
cout<<"\n______MENU________\n1. Add item\n2.Remove Item\n3.Display items\n4.Close Application";
cout<<"\n enter your choice: ";
cin>>ch;
int nsize;
switch(ch)
{
case 1: //case to add item
cout<<"enter item name: ";
cin>>nm;
cout<<"Enter price: ";
cin>>p;
addItem(nm,p);
break;
case 2://remove the item
cout<<"enter the item name you want to remove: ";
cin>>nm;
removeItem(nm);
break;
case 3:display(); //display choice
break;
case 4: //exit Application
break;
default:cout<<"\n You entered wrong choice!!";
break;
}
}
return 0;
}

Below is the screenshot of the code:

Screenshot of output:

Note: code is taking input from standard I/O. Press 'enter' key after each input.

Add a comment
Know the answer?
Add Answer to:
Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help with this. You must create a sales tracking program named SalesTracking.java. This program must...

    please help with this. You must create a sales tracking program named SalesTracking.java. This program must track monthly sales as well as compute average yearly sales, total sales for the year, and which month had the highest sales and which month had the lowest sales. The program should prompt the user for the sales for each month starting with January. After all the monthly sales have been entered, your program should have methods that do the following. getSales(): This method...

  • This project will allow you to practice with one dimensional arrays, function and the same time...

    This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

  • Create a C++ program that fulfills the requirements of the following prompt: This program will create...

    Create a C++ program that fulfills the requirements of the following prompt: This program will create a text-based squad versus squad battling game. The game will be set up so that two players can play and each player will control a squad. Each member of the squad will have basic and special abilities. When one squad has been fully defeated, that player will be declared the loser. The program will then exit. The basis of this program will require the...

  • In this lab, you will create a program to help travelers book flights and hotel stays that will b...

    In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • Java Inventory Management Code Question

    Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...

  • The XYZ Company needs you to write a program that will allow them to enter the...

    The XYZ Company needs you to write a program that will allow them to enter the weekly sales for a salesperson and then the program will calculate things such as most sales (and what day on which they happened), least sales (and day on which they happened), total sales, and daily average. The program will need to do the following: • Validate the user input to ensure that it is not less than 0.0 (0.0 will be acceptable if there...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT