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
Which of the acronyms listed below refers to a series of basic hardware diagnostic tests performed by the startup BIOS after the
Morgarella [4.7K]

Answer:

POST

Explanation:

  • POST stands for Power On Self test.
  • The process of booting the system involves performing the self test POST.
  • POST involves testing the computer hardware which are required for proper functioning of the computer.
  • If the POST test fails, the computer performs the necessary action required for the proper functioning of the computer.It immediately raises alarm ( beeps ) . Different number of beeps represents different devices which are having trouble.
  • So, option (D) is correct option.
  • Option (A) IDE is not the test. So, option (A) is wrong option.
  • Option (B) POTS is not the test.So, option (B) is wrong option.
  • Option (C) QoS is not the test. So, option (C) is wrong option.
7 0
3 years ago
What is the most recent version of Microsoft Windows?
yuradex [85]

Answer:

I believe it is windows 8

7 0
3 years ago
Read 2 more answers
What Is What is the difference between system software and application software?<br>​
inna [77]

Answer:

Hope it helps have a nice day..

4 0
2 years ago
K
ollegr [7]
True??????????????????????????
7 0
3 years ago
Read 2 more answers
The WorkOrders table contains a foreign key, ClientNum, which must match the primary key of the Client table. What type of updat
OlgaM077 [116]

Answer:

Changing the customer number on a record in the Orders table to a number that does not match a customer number in the customer table would violate referential integrity.

If deletes do not cascade, deleting a customer that has orders would violate referential integrity.

If deletes cascade, customer can be deleted and all orders for that customer will automatically be deleted.

8 0
3 years ago
Other questions:
  • Why is it so important that you know how much traffic dfs replication requires?
    13·2 answers
  • PLEASE HELP, True or False: The term whitespace speaks to the design of a website
    8·2 answers
  • Molly, a technician, has been tasked with researching an emulator for the software developers to test cross-platform application
    13·2 answers
  • Explain why an IT department and a user support group may disagree about the responsibility for the development of end-user appl
    8·1 answer
  • Refer to the exhibit. The PC is connected to the console port of the switch. All the other connections are made through FastEthe
    6·1 answer
  • A business letter is not written:
    6·1 answer
  • Seneca has just applied conditional formatting and realizes that she has made a mistake. Which action should she take to fix the
    12·2 answers
  • X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with
    7·1 answer
  • The computer stores currently used programs and data in ________.
    9·2 answers
  • Which statement best describes what happens when a computer starts?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!