Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a simple function in C++ to insert an element in an array. Given an array with const int CAPACITY = 10 and the following

Write a simple function in C++ to insert an element in an array.

Given an array with const int CAPACITY = 10 and the following parameters: the array, the number of elements in the array, the element to insert, and the index where the element needs to be inserted. You can use a FOR loop.

Example:

Initial Array: 8 4 2 6 7 8 2

Insert 80 at idx 7... Modified array: 8 4 2 6 7 8 2 80

or

Initial Array: 7 4 6 2 Insert 50 at idx 2... Modified array: 7 4 50 6 2

If the array is full, use cerr to output the following error message "Array is full.

- If the index is larger than the number of elements in the array (for example, the array contains 10 elements and the index is 11 or larger), output the error message using cerr "You can only insert contiguous elements in the array.")

- If the index exceeds the capacity, output the error message "The array cannot have more than number of elements."

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions