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
Difference between entropy and enthalpy is
olchik [2.2K]

Answer:

Explanation:

Enthalpy is the measure of total heat present in the thermodynamic system where the pressure is constant. Entropy is the measure of disorder in a thermodynamic system.

3 0
2 years ago
HELP!!!
aleksley [76]

Answer:

The detail answer of this question is given in explanation section.

The simple answer is option B

Explanation:

Let took at each option:

A) an html tag

An html tag is used to start and end html document. It does not have anything to do with rendering.

B) a doctype declaration

The document type declaration is necessary because it tell the browser which version of html should be rendered.

C)Body tag tell the browser. it is the visible area of website.

D) A hear tag is used to clear meta data about website.

3 0
2 years ago
Read 2 more answers
How did technology change the world
Crank

Answer:

Technology has changed the world for the better.

Explanation:

Without technology, many of the things we take for advantage, such as, credit cards, calling people from far distances, heck even being able to call to across the world from where you are right now. Technology has revolutionized many things we use commonly on a day-to-day basis.

3 0
2 years ago
Read 2 more answers
What is destination email address​
Ronch [10]

Answer:

Explanation:

The E-mail Destination allows you to send data from your forms in text format to various different email addresses.

8 0
2 years ago
To provide for unobtrusive validation, you can install the ____________________ package for unobtrusive validation.
NARA [144]

Answer:

AspNet.ScriptManager.jQuery?

Explanation:

Unobtrusive validation means we can perform a simple client-side validation without writing a lot of validation code by adding suitable attributes and also by including the suitable script files.

One of the benefits of using a unobtrusive validation is that it help to reduce the amount of the Java script that is generated. We can install the AspNet.ScriptManager.jQuery? for the unobtrusive validation.

When the unobtrusive validation is used, validation of the client is being performed by using a JavaScript library.

4 0
2 years ago
Other questions:
  • A ____ is a circuit board that contains most of a server.
    8·1 answer
  • Your license can be canceled if you __________
    14·2 answers
  • 14. Convert 11110111 from binary to denary<br> (1 Point)
    12·2 answers
  • What is the purpose of citations?
    13·1 answer
  • All web page urls begin with the letters ____.
    6·1 answer
  • Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 3
    5·1 answer
  • if a user has one column in a table and would like to make it into two columns which command should be used
    13·1 answer
  • Write a program that will read two floating point numbers (the first read into a variable called first and the second read into
    13·1 answer
  • Which of the following are NOT possible using the RANDOM(a, b) and DISPLAY(expression) abstractions?
    10·1 answer
  • your manager asked you to set up a secure network connection at a remote site to move over some back ups. what protocol what do
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!