Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Needs to be in C++ coding. Please make sure you conform to the following require

ID: 3607277 • Letter: N

Question

Needs to be in C++ coding.

Please make sure you conform to the following requirements: 1. Create a global constant integer called CAPACITY and set it to 100 (5 points) Use the class examples and exercises to write functions to initialize the array by reading values from the user, and to print the array. These functions take the array and its current size as parameters. You can use the code in the examples. (5 points) 3. Write a function called insert that takes the array, a number, a position and the current size 4. Write a function called remove that takes the array, a number and the current size of the 5. Write a function called sort that takes the array and its current size as parameters and sorts 6. In the main function, have the user initialize the array. Then, write a command line menu of the array as parameters. Insert the number at the given position. (15 points) array, and removes the first instance of the number from the array. (15 points) the array in ascending order. You need to use insertion sort, which is given below. (15 points) with the following options: e Print » Insert » Remove » Sort » Exit Call the appropriate functions when the user chooses a particular option. Print and error message and continue if the user enters a wrong option. (15 points) 7. Please make sure your code is appropriately commented. (5 points) Algorithm for insertion sort

Explanation / Answer

#include<iostream>
using namespace std;
/***declared global constant**/
const int CAPACITY = 100;
/**to print user given array*/
void print(int a[],int size){
    for(int i=0;i<size;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
/**insert element at given position*/
void insert(int a[],int number,int position,int size){
    a[position]=number;
}
/**remove element from first index***/
void remove(int a[],int size){
    for(int i=1;i<size;i++){
        a[i-1]=a[i];
    }
}
/**sort using insertion sort by checking each iteration*/
void sort(int arr[],int size){
    for(int i=1;i<size;i++){
     int j=i-1,si=arr[i];
    while(j>=0){    
        if(si<arr[j]){
          arr[j+1]=arr[j];
        }else{
          break;
        }   
       j--;
    }
    arr[j+1]=si;
}
}
int main(){
    int a[CAPACITY],size,choice;
    /**taking size and array from user**/
    cin>>size;
    for(int i=0;i<size;i++){
        cin>>a[i];
    }
    /***select choice from user continuously**/
    while(true){
        cin>>choice;
        switch(choice){
            case 0:
               print(a,size);
               break;
            case 1:
               insert(a,6,0,5);
               break;
            case 2:
               remove(a,5);
               break;
            case 3:
               sort(a,5);
               break;
            default:
               cout<<"wrong choice"<<endl;
               break;
        }
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote