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

I have main function and output and i can\'t change anything in the main.just ha

ID: 3634543 • Letter: I

Question

I have main function and output and i can't change anything in the main.just have to write function to call them

#include <iostream>
using namespace std;
int main()
{
int a[6], size = 0;
char op;

cout << "Welcome to the Array Handler! ";
cout << "Important Note: Maximum array size is 6!! ";
op = minu();
while(op != 'q')
{
switch (op)
{
case '1': readArray(a, size);
break;
case '2': displayArray(a, size);
break;
case '3': addElement(a, size);
break;
case '4': sortArray(a, size);
break;
case '5': deleteByValue(a, size);
break;
case '6': deleteByLocation(a, size);
break;
case '7': change(a, size);
break;
default: cout << "Wrong operation number! Try again!! ";
break;
}
op = minu();
}

cout << "Thank you for using this program!! ";
return 0;
}
===============================
the out put must be:
Welcome to the Array Handler!

Important Note: Maximum array size is 6!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 1


Enter array size: 4
a[0] = 5
a[1] = 4
a[2] = 89
a[3] = 65
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 5
a[1] = 4
a[2] = 89
a[3] = 65


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 3
Enter location (0 to 4): 2
a[2] = 99
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 5
a[1] = 4
a[2] = 99
a[3] = 89
a[4] = 65


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 4
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 4
a[1] = 5
a[2] = 65
a[3] = 89
a[4] = 99


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 5
Eneter value of element to be deleted: 34
0 numbers were deleted.
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 5
Eneter value of element to be deleted: 65
1 numbers were deleted.
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 3
Enter location (0 to 4): 4
a[4] = 23
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 3
Enter location (0 to 5): 5
a[5] = 23
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 4
a[1] = 5
a[2] = 89
a[3] = 99
a[4] = 23
a[5] = 23


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 3
Sorry, array is full!
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 5
Eneter value of element to be deleted: 23
2 numbers were deleted.
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 4
a[1] = 5
a[2] = 89
a[3] = 99


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 6
Enter location to be deleted: 5
Invalid input!
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 6
Enter location to be deleted: 2
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 4
a[1] = 5
a[2] = 99


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 7
Enter location to be changed: 5
Invalid input!
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 7
Enter location to be changed: 1
a[1] = 54
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 4
a[1] = 54
a[2] = 99


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 1


Enter array size: 9
Sorry, too big for me
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 1


Enter array size: 6
a[0] = 3
a[1] = 43
a[2] = 1
a[3] = 6
a[4] = 1
a[5] = 1
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 5
Eneter value of element to be deleted: 1
3 numbers were deleted.
Done!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 2
a[0] = 3
a[1] = 43
a[2] = 6


1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: 8
Wrong operation number! Try again!!

1. Read array
2. Display array
3. Add element to the array
4. Sort the array
5. Delete element by value
6. Delete element by location
7. Change location value
Enter operation number or 'q' to quit: q
Thank you for using this program!!

press any key to continue

Explanation / Answer

Dear,



#include <iostream>
using namespace std;

char minu()
{
    char choise;
    cout << " 1. Read array"
        <<    " 2. Display array"
        << " 3. Add element to the array"
        << " 4. Sort the array"
        << " 5. Delete element by value"
        << " 6. Delete element by location"
        << " 7. Change location value"
        << " Enter operation number or 'q' to quit: ";
    cin >> choise;
    return choise;
}

void readArray(int a[], int &size)
{
    cout << " Enter array size: ";
    cin >> size;
    for(int i=0; i<size; i++)
    {
        cout << "a[" << i << "] = ";
        cin >> a[i];
    }
    cout << "Done!!" << endl;
}

void displayArray(int a[], int size)
{
    for(int i=0; i<size; i++)
    {
        cout << "a[" << i << "] = ";
        cout << a[i] << endl;
    }
}

void addElement(int a[], int &size)
{
    int location, value;
    cout << "Enter location (0 to " << size << "): ";
    cin >> location;   
   
    if(location >= 0 && location < size)
    {
        cout << "a[" << location << "] = ";
        cin >> value;   
               
        int *b = new int[size];

        for(int i=0; i < size; i++)
            b[i] = a[i];

        for(int i=0; i < location; i++)
            a[i] = b[i];

        a[location] = value;

        for(int i=location; i < size; i++)
            a[i+1] = b[i];

        size++;
    }
    else
        cout << "Invalid input" << endl;
    cout << "Done!!" << endl;
}

void sortArray(int a[], int size)
{
    for(int i=0; i < size-1; i++)
        for(int j = i+1; j < size; j++)
            if(a[i] > a[j])
            {
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }

            cout << "Done!!" << endl;
}

void deleteByValue(int a[], int &size)
{
    int value;
    cout << "Eneter value of element to be deleted: ";
    cin >> value;

    int count = 0;

    for(int i=0; i<size; i++)
        if(a[i] == value)
        {
            for(int j=i; j<size-1; j++)
                a[j] = a[j+1];

            count++;
            size--;
            i--;
        }

        cout << count << " numbers were deleted." << endl;
        cout << "Done!!" << endl;
}

void deleteByLocation(int a[], int &size)
{
    int location;
    cout << "Enter location to be deleted: ";
    cin >> location;

    if(location >= 0 && location < size)
    {
        for(int i = location; i < size-1; i++)
            a[i] = a[i+1];
        size--;
    }
    else
        cout << "Invalid input" << endl;
    cout << "Done!!" << endl;
}

void change(int a[], int size)
{
    int location;
    cout << "Enter location to be changed: ";
    cin >> location;

    if(location >= 0 && location < size)
    {
        cout << "a[" << location << "] = ";
        cin >> a[location];
    }
    else
        cout << "Invalid input" << endl;
    cout << "Done!!" << endl;
}

int main()
{
    int a[6], size = 0;
    char op;

    cout << "Welcome to the Array Handler! ";
    cout << "Important Note: Maximum array size is 6!! ";
    op = minu();
    while(op != 'q')
    {
        switch (op)
        {
        case '1': readArray(a, size);
            break;
        case '2': displayArray(a, size);
            break;
        case '3': addElement(a, size);
            break;
        case '4': sortArray(a, size);
            break;
        case '5': deleteByValue(a, size);
            break;
        case '6': deleteByLocation(a, size);
            break;
        case '7': change(a, size);
            break;
        default: cout << "Wrong operation number! Try again!! ";
            break;
        }
        op = minu();
    }

    cout << "Thank you for using this program!! ";
    return 0;
}

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