1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anon25 [30]
3 years ago
12

Write the method addItemToStock to add an item into the grocery stock array. The method will: • Insert the item with itemName ad

d quantity items to stock. • If itemName is already present in stock, increase the quantity of the item, otherwise add new itemName to stock. • If itemName is not present in stock, insert at the first null position in the stock array. After the insertion all items are adjacent in the array (no null positions between two items). • Additionally, double the capacity of the stock array if itemName is a new item to be inserted and the stock is full.
Computers and Technology
1 answer:
garri49 [273]3 years ago
8 0

Answer:

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

{

   //varible to indicate size of the array

   int size=20;

   //arrays to hold grocery item names and their quantities

   std::string grocery_item[size];

   int item_stock[size];

   //variables to hold user input

   std::string itemName;

   int quantity;

   //variable to check if item is already present

   bool itemPresent=false;

   //variable holding full stock value

   int full_stock=100;

   for(int n=0; n<size; n++)

   {

       grocery_item[n]="";

       item_stock[n]=0;

   }

   do

   {

       std::cout << endl<<"Enter the grocery item to be added(enter q to quit): ";

       cin>>itemName;

       if(itemName=="q")

       {

               cout<<"Program ends..."<<endl; break;

       }

       else

       {

           std::cout << "Enter the grocery item stock to be added: ";

           cin>>quantity;

       }

   for(int n=0; n<size; n++)

   {

       if(grocery_item[n]==itemName)

       {

           itemPresent=true;

           item_stock[n]=item_stock[n]+quantity;

       }

   }

   if(itemPresent==false)

   {

       for(int n=0; n<size; n++)

       {

           if(grocery_item[n]=="")

           {

               itemPresent=true;

               grocery_item[n]=itemName;

               item_stock[n]=item_stock[n]+quantity;

           }

       

           if(item_stock[n]==full_stock)

           {

               item_stock[n]=item_stock[n]*2;

           }

       }

   }

   }while(itemName!="q");

   return 0;

}

OUTPUT

Enter the grocery item to be added(enter q to quit): rice

Enter the grocery item stock to be added: 23

Enter the grocery item to be added(enter q to quit): bread

Enter the grocery item stock to be added: 10

Enter the grocery item to be added(enter q to quit): bread

Enter the grocery item stock to be added: 12

Enter the grocery item to be added(enter q to quit): q

Program ends...

Explanation:

1. The length of the array and the level of full stock has been defined inside the program.

2. Program can be tested for varying values of length of array and full stock level.

3. The variables are declared outside the do-while loop.

4. Inside do-while loop, user input is taken. The loop runs until user opts to quit the program.

5. Inside do-while loop, the logic for adding the item to the array and adding the quantity to the stock has been included. For loops have been used for arrays.

6. The program only takes user input for the item and the respective quantity to be added.

You might be interested in
A group of computers that are interconnected in order to share information or documents is called a _____.
xxMikexx [17]
Computer Network, surely!

"Network" implies combination of all these computers!
7 0
3 years ago
Why have countries requested for the removal of content?
Kipish [7]
These links should help u:
https://support.google.com/transparencyreport/answer/7347744?hl=en

https://searchengineland.com/most-censorship-and-content-takedown-requests-come-from-us-says-google-...
5 0
3 years ago
Peter is a data analyst in a financial firm. He maintains a spreadsheet that contains all employee details. Peter wants to analy
alukav5142 [94]

Answer: filter the data of employees with more than five years of experience

Explanation:

The technique that Peter can use to perform this analysis is to filter the data of employees with more than five years of experience.

Filter in spreadsheets allows one to see the data that is required based on the input that was given. In this case, since Peter wants to analyze the data of all employees that have experience of more than five years, this can be filtered and the employees who have experience of more than 5 years will be shown.

The workers who have experience of less than five years will not b shown in this case.

3 0
3 years ago
question 2 you are using a spreadsheet to organize a list of upcoming home repairs. column a contains the list of repairs, and c
Helga [31]

Since you are using a spreadsheet to organize a list of upcoming home repairs. The spreadsheet tool that can you use to create a drop-down list of priorities for each cell in column b is  Data validation.

<h3>What is the purpose of data validation?</h3>

The use of rows and columns of data, a spreadsheet is a type of computer program that can store, display, and manipulate data. One of the most used tools that can be used with personal computers is a spreadsheet. A spreadsheet is typically made to store numerical data and brief text passages.

Therefore, in the context of the above, before using data for a business operation, it is best to validate it to ensure its accuracy, integrity, and structure. The output of a data validation operation can be used to generate data for business intelligence, data analytics, or training a machine learning model.

Learn more about spreadsheet from

brainly.com/question/4965119
#SPJ1

6 0
1 year ago
Mobile Device Company (MDC) discovers that defamatory statements about its policies and products are being posted in an online f
dexar [7]

Answer:

MDC should process in Court

Explanation:

4 0
3 years ago
Other questions:
  • What can help prevent issues related to downloading content from the internet?
    7·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • All of the following activities may infect your computer with a virus EXCEPT ________.
    6·1 answer
  • Which type of network cover a large geographical area and usually consists of several smaller networks, which might use differen
    12·1 answer
  • At the beginning of a chapter in a book, the first letter often appears larger than the other text on the page. This
    15·1 answer
  • Which can be used to decode a Unicode character encoding into text?
    13·1 answer
  • You company hired you to build a network. List of technical question that you will ask?
    11·1 answer
  • The cameras picture review function allows you to look at the _ you've taken
    8·1 answer
  • Where would you go to access frequently used icons?
    12·2 answers
  • HOWARD!!!!!! THE PHONE IS RINGING!!!!!!!!!
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!