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 county collects property taxes on the assessed value of property, which is 60 percent of its actual value. For example, if a h
Zolol [24]

Answer:

actual_value = float(input("Enter the actual value of a piece of property: "))

tax_rate = float(input("Enter the current tax rate for each $100.00 of assessed value: "))

assessed_value = actual_value * 0.6

tax = (assessed_value * tax_rate) / 100

print("The annual property tax is $" + str(tax))

Explanation:

*The code is in Python.

Ask the user to enter the actual value and the tax rate

Calculate the assessed value, multiply the actual value by 0.6

Calculate the tax, multiply the assessed value by the tax rate and divide result by 100

Print the tax

7 0
4 years ago
What CPU extensions are a prerequisite for installing the Hyper-V role when using an Intel or AMD processor?
malfutka [58]

Answer:

Search for the Intel Virtualization Technology (Intel-VT) branding on Intel processors, and search for AMD-V on the AMD processors.

Explanation:

  • Streaming SIMD Extensions (SSE) seems to be a standardized instruction, data from multiple guidance collection enhancement to the x86 architecture, developed by Intel and released immediately after the introduction of Advanced Micro Devices 3DNow in their Pentium III range of CP Units in 1999.
  • Hyper-V requires different requirements of hardware for running virtual machines in a safe, efficient manner. Minimum 4 Gb of storage. You might need more RAM on the Hyper-V Server for either the virtual servers.

Therefor, it's the right answer.

3 0
4 years ago
Describe artificial intelligence, and contrast the human mind and the computer as information processors
marin [14]
Robots can think better than humans can and they also can’t feel emotion like us. Also, unlike humans, they can predict what will happen next
8 0
4 years ago
When I try to make an account, it always says that they are not able to complete the registration at this time. And I didn't alr
Anastasy [175]
Maybe just wait a day and try again
7 0
3 years ago
4. Together, what do the divisions of the DHSMV do? A. Make sure lines are long B. Use more money than other government organiza
iren2701 [21]

The answer is C, "keep Florida highways safe". DHSMV stands for "Department of Highway Safety and Motor Vehicles".

5 0
3 years ago
Other questions:
  • Which sentences in the passage show the preventive measures to avoid data breach?
    9·1 answer
  • Which of the following is NOT one of the responsibilities of the Federal Reserve?
    10·1 answer
  • What type of organism forms the base of food webs?
    9·1 answer
  • Briefly explain five measures you have undertaken to protect your confidential
    12·1 answer
  • Which of the following sets of data would be represented best in a histogram
    10·1 answer
  • Do most web queries have fully meets results
    11·1 answer
  • Should-the-government-allow-illegal-immigrants-to-become-citizens
    12·1 answer
  • Gina, an IT professional, noticed that the servers were running very slowly. She evaluated the system and made a recommendation
    9·2 answers
  • Pls help
    13·1 answer
  • you're building a new network for a small financial services startup company. security is paramount, so each organization within
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!