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
The expression that is tested by a switch statement must have a(n) __________ value.
Hitman42 [59]

The answer is relational.

6 0
3 years ago
Nicole is in a study group to prepare for a test on plant biology, a subject she knows a lot about. During their meetings, she a
Anestetic [448]

Answer:

b

Explanation:

i pretty sure it b , yep it is b

4 0
2 years ago
Read 2 more answers
In Criminal justice, the type of evidence which contradicts a given theory is known as?​
irina [24]

Answer:

In general, scientific evidence are the results of scientific tests used to prove or disprove a theory or hypothesis. In criminal cases, scientific evidence is used to help jurors understand and determine the facts of a case. Explanation:

3 0
2 years ago
Write Python code to save the data to a MongoDB collection:Import json module to parse JSON dataImport MongoClient from pymongo
Zigmanuir [339]

Answer:

Explanation:

The objective of this task is to compute a program that involves the usage of Python code to save the data to MongoDB and to query  the database.

Due to the error that occur which makes me to be unable to submit this answer, I've created a word document instead and the attached file can be found below.

Thanks!

Download docx
8 0
2 years ago
Read the following scenario, and then answer the question below.
shtirl [24]
Establish what skills are required to reach his goal
8 0
3 years ago
Read 2 more answers
Other questions:
  • ___ is the branch of computer science that explores techniques for incorporating aspects of intelligence into computer systems.
    5·1 answer
  • Write a program that will predict the size of a population of organisms. The program // should ask the user for the starting num
    6·1 answer
  • Many companies use software to scan resumes and search for _____________.
    10·1 answer
  • Suppose your parents are planning to take you
    8·1 answer
  • How are engineers are related to technology
    13·1 answer
  • According to the "multiple-selves" theory, of an online DVD rental service could offer same-day deliveries, so that people who o
    9·1 answer
  • Explain what happens if you try to open a file for reading that does not exist.
    10·1 answer
  • Why might reading a product review be a good idea before purchasing a product?
    5·2 answers
  • Help me to solve please​
    8·2 answers
  • What is the remainder obtained by dividing x 7 + x 5 + 1 by the generator polynomial x 3 + 1?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!