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]
2 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]2 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
When was microsoft word for windows invented?
Dahasolnce [82]
1981 fue inventado por Bill gates y paul allen
4 0
3 years ago
Select the correct answer from each drop-down menu.
mylen [45]

Answer:

"In a VPN, a computer connects to a server and then changes the Internet Protocol of your computer" -urgurlmarie

Source: brainly.com/question/19665457, -urgurlmarie

Opinion: You're answer is correct, I'll take this step by step but by connecting your PC to an server like OpenVPN, or a paid VPN service such as Nord VPN. You are changing your Internet Protocol of your PC to that servers I.P. Address.

7 0
2 years ago
A specialized storage device or group of storage devices that provides centralized fault-tolerant data storage for a network____
gogolik [260]

Answer: NAS(Network-attached storage)

Explanation:

NAS(Network-attached storage) is the file storage in computer server which links to computer network. It is used by heterogeneous client or group of other various users to access files data.

  • It can retrieve data from shared folder storage in network.It can provide serving file feature through standard, hardware,configuration or  software.
  • It provides high speed service of sharing and serving files, continuous work in faulty situation, easy configuration, simple accessing of data etc.

5 0
3 years ago
Where should you endorse a check
yKpoI14uk [10]
This is done by signing your name on the back of the left end of thecheck<span>. </span>You<span> can also limit who can cash it by specifying in your </span>endorsement<span> that it is only to be deposited into your specified account at Provident.</span>
5 0
3 years ago
Read 2 more answers
Python Activity:
Ksivusya [100]

Answer:

Explanation:

def indexOfMax(lis):

   m = max(lis)

   indx=0

   for i in range(len(lis)):

       if lis[i]==m:

           indx=i

           break

   return indx

print(indexOfMax([1,5,8,23,78,22,0]))

3 0
2 years ago
Other questions:
  • What is an embedded system. Give examples
    12·1 answer
  • Q10: Putting it all together (0.75 points) Here, we'll update the values in dictionary, storing the output in a dictionary calle
    5·1 answer
  • What is a strictly layered pattern, provide an example of its usage.
    13·1 answer
  • Your company runs several databases on a single MySQL instance. They need to take backups of a specific database at regular inte
    12·1 answer
  • Different uses of quick access toolbar
    11·1 answer
  • How an operating system allocates system resources in a computer​
    15·1 answer
  • Assume that the message M has to be transmitted. Given the generator function G for the CRC scheme, calculate CRC. What will be
    15·1 answer
  • Which is the first computer brought in nepal for the census of 2028 B.S​
    6·1 answer
  • You are the administrator for the ABC Company. You are looking to install Windows Server 2016, and you need to decide which vers
    13·1 answer
  • Bank Account Postings While reviewing your checking account balance online, you notice that debit card purchases have not posted
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!