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
lorasvet [3.4K]
3 years ago
12

Write a function, insertAt, that takes four parameters: an array of integers, the number of elements in the array, an integer (s

ay, insertItem), and an integer (say, index). The function should insert insertItem in the array provided at the position specified by index. If index is out of range, output the following: Position of the item to be inserted is out of range or if the index is negative: Position of the item to be inserted must be nonnegative (Note that index must be between 0 and the number of elements in the array; that is, 0 <= index < the number of elements in the array.) Assume that the array is unsorted.
Chemistry
1 answer:
zimovet [89]3 years ago
6 0

Answer:

Implemented the program using C++ below

Explanation:

#include <iostream>

#include <iomanip>

using namespace std;

void printIt (int numbers[],int length);

int removeAt (int numbers[], int length, int index);

void insertAt (int numbers[], int length, int insertItem, int index);

int main()

{

int numbers[] = {4,23,65,34,82,37,12,17,24,36,82,51};

int length;

int index;

int insertItem;

cout<<"Removing an item from the list..."<<endl;

cout<<endl;

printIt(numbers,12);

removeAt(numbers,12,index);

insertAt(numbers,12,insertItem,index);

system ("PAUSE");

return 0;

}

void printIt (int numbers[],int length)

{

cout<<"The current array..."<<endl;

for (int i = 0; i<length; i++)

{

cout<<numbers[i]<<" ";

}

cout<<endl;

}

int removeAt (int numbers[], int length, int index)

{

int item;

cout<<endl;

cout<<"There are "<<length<<" item(s) in the list (position 0 through 11)"<<endl;

cout<<"Enter the position of the item to be removed."<<endl;

cout<<"Enter 0 for the first item and so on: ";

cin>>item;

if (item > length)

{

cout<<endl;

cout<<"!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!"<<endl;

cout<<endl;

cout<<"The current array..."<<endl;

for (int i = 0; i<length; i++)

{

cout<<numbers[i]<<" ";

}

cout<<endl;

cout<<endl;

cout<<"!!!! Index out of Range !!!!"<<endl;

cout<<"There are "<<length<<" item(s) in the list (position 0 through 11)"<<endl;

cout<<"You entered position "<<item<<", which is OUT OF RANGE."<<endl;

cout<<"Enter the position of the item to be removed."<<endl;

cout<<"Enter 0 for the first item and so on: ";

cin>>item;

cout<<endl;

cout<<"After removing the item at position "<<item<<", array is..."<<endl;

cout<<endl;

cout<<"The current array..."<<endl;

}

for (int i = 0; i < length; i++)

{

if (i != item)

{

cout<<numbers[i]<<" ";

}

}

cout<<endl;

cout<<endl;

cout<<"************************************************************";

cout<<endl;

cout<<endl;

}

void insertAt (int numbers[], int length, int insertItem, int index)

{

int item;

cout<<"Inserting an item in the list..."<<endl;

cout<<endl;

cout<<"The current array..."<<endl;

for (int i = 0; i < length; i++)

{

if (i != item)

{

cout<<numbers[i]<<" ";

}

}

cout<<endl;

cout<<"There are 10 items(s) in the list (position 0 through 11)"<<endl;

cout<<"Enter item to be inserted and its position"<<endl;

cout<<"Position of the first element is 0,"<<endl;

cout<<"so if you want the #5 at the front type in: "<<endl;

cout<<"5 (space) 0 "<<endl;

cin>>insertItem;

cin>>index;

if (index > length)

{

cout<<endl;

cout<<"!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!"<<endl;

cout<<endl;

cout<<"The current array..."<<endl;

for (int i = 0; i < length; i++)

{

if (i != item)

{

cout<<numbers[i]<<" ";

}

}

cout<<endl;

cout<<endl;

cout<<"!!!! Index out of Range !!!!"<<endl;

cout<<"There are "<<length<<" item(s) in the list (position 0 through 11)"<<endl;

cout<<"You entered position "<<index<<", which is OUT OF RANGE. Please try again."<<endl;

cout<<endl;

cout<<"Enter item to be inserted and its position"<<endl;

cout<<"Position of the first element is 0,"<<endl;

cout<<"so if you want the #5 at the front type in: "<<endl;

cout<<"5 (space) 0 "<<endl;

cin>>insertItem;

cin>>index;

}

cout<<endl;

cout<<"After inserting the item at position "<<insertItem<<", array is..."<<endl;

cout<<endl;

cout<<"The current array..."<<endl;

numbers[insertItem-1] = insertItem;

cout<<numbers[insertItem-1]<<" ";

for (int i = 0; i < length; i++)

{

if (i != item)

{

cout<<numbers[i]<<" ";

}

}

cout<<endl;

}

You might be interested in
Which of the following means a natural occurring solid that has a specific chemical makeup?
wolverine [178]
The answer is: A rock
8 0
3 years ago
Read 2 more answers
A hypothetical main group element E reacts with chlorine to form an ionic compound with the formula ECl. The element is a member
Ronch [10]
It would be 1A bc then the +1 charge will cancel out chlorine’s -1 charge
7 0
3 years ago
Suppose there was a release of 1 mole of Alpha emission particle and 1 mole of Beta emission particles and both particles are ac
Vitek1552 [10]

Answer:

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

Explanation:

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

DT the best and they I'm on to work use as some help new thread so this communication contains you would appreciate everything about getting started using some new version from here or email the day car rental house has come home today was automatically and your company based website has anyone that a big hugs bhi to

6 0
3 years ago
Which of the following types of rocks are likely to be formed due to compacting and cementing? Sedimentary rocks only Igneous ro
bezimeni [28]
The answer is only sedimentary rocks
7 0
3 years ago
Read 2 more answers
PLZ HELP IM CONFUSED
Marina CMI [18]

Answer:

9.1 mol

Explanation:

The balanced chemical equation of the reaction is:

CO (g) + 2H2 (g) → CH3OH (l)

According to the above balanced equation, 2 moles of hydrogen gas (H2) are needed to produce 1 mole of methanol (CH3OH).

To convert 36.7 g of hydrogen gas to moles, we use the formula;

mole = mass/molar mass

Molar mass of H2 = 2.02g/mol

mole = 36.7/2.02

mole = 18.17mol

This means that if;

2 moles of H2 reacts to produce 1 mole of CH3OH

18.17mol of H2 will react to produce;

18.17 × 1 / 2

= 18.17/2

= 9.085

Approximately to 1 d.p = 9.1 mol of methanol (CH3OH).

6 0
3 years ago
Other questions:
  • Chao is thinking about doing a project on plate tectonics for the school science fair. Which design would best relate to how the
    9·2 answers
  • What mass (in g) of NH3 must be dissolved in 475 g of methanol to make a 0.250 m solution?
    7·1 answer
  • A student using this technique finds that when putting a hot piece of metal into a calorimeter which contains 35.070g of water,
    7·1 answer
  • A line in the lyman series of hydrogen has a wavelength of 122 nm. from what state did the electron originate?
    11·1 answer
  • Name two air pollutants that bioaccumulate
    8·1 answer
  • Which of the following statements accurately describes enzymes?
    15·1 answer
  • Arrange the following solution in the increasing order of their H+ ion concentration?
    6·1 answer
  • Balance the reaction and determine which of the following coefficients
    7·1 answer
  • How are Distilled water and tap water alike?​
    5·2 answers
  • Ryan just joined the track team. He runs the 40 yard dash in 6.4 seconds. Explain three human body systems that work together to
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!