n program that inserts an element IT ar Array) for the following data. (Siz 1000,2000,5000,4000

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter6: Using Arrays
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question
Q No.1: Write down program that inserts an element ITEM into the LOC (2nd position) in
LA (Linear Array) for the following data. (Size of the array is 5).
1000,2000,5000,4000
Transcribed Image Text:Q No.1: Write down program that inserts an element ITEM into the LOC (2nd position) in LA (Linear Array) for the following data. (Size of the array is 5). 1000,2000,5000,4000
Expert Solution
Step 1

Here is the documented code to solve this assignment:

chegg.cpp:

#include <iostream>

#define SIZE 10

void show(const int (&A)[SIZE],
          const int N) {
    for(int i = 0; i < N; ++i) {
        std::cout << A[i] << ", ";
    }
    std::cout << "\b\b " << std::endl;
}

int Find_Location_To_Insert(const int (&A)[SIZE],
                            const int N,
                            int &K,
                            const int ITEM) {
    int LB = 0, UB = N - 1;
    for(K = LB; K <= UB; ++K) {
        if(A[K] > ITEM) {
            // insert at front or in middle
            return K;
        }
    }

    // insert at the end of array
    return K;
}

void INSERT(int (&A)[SIZE],
            int &N,
            int K,
            const int ITEM) {
    // initialize counter
    int J = N - 1;

    while(J >= K) {
        // move the Jth element downward
        A[J + 1] = A[J];

        // decrease counter
        J = J - 1;
    }

    // insert element
    A[K] = ITEM;

    // reset N
    N = N + 1;
}

int main() {
    int A[SIZE];
    int N = 0;
    int ITEM;
    int K;

    while(true) {
        show(A, N);

        // overflow check
        if(N == SIZE) {
            std::cout << "Overflow, Array is Full." << std::endl;
            break;
        }


       



steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage