Question
Program 1 - Array Operations Squilliam Fancyson has heard of the fancy calculator that Squidward (supposedly) made for the Krusty Krabs Cash Register. Determined to
Program 1 - Array Operations
Squilliam Fancyson has heard of the fancy calculator that Squidward (supposedly) made for the Krusty Krabs Cash Register. Determined to prove that he is the best programmer in town, he has challenged Squidward to a series of programming challenges. If Squilliam wins, Squidward has to hand over his clarinet and never paint again. If Squidward wins, Squilliam will work Squidwards shift at the Krusty Krabs cash register for a week. Squidward is determined to win, except he is not really a programmer. He has left no stone (pioneer transport or otherwise) unturned. He has even tried asking Karen, who was unable to help. He realizes that instead of working off Mr. Krabs old computer (the one Patrick smashed while painting the house), he could just pay you off to do the challenges for him. Your task today is to help Squidward retain his sanity and dignity (whatever is left of it).
The first challenge is array operations. For this program, were going to perform a range of standard array operations to show Squilliam once and for all, that Squidward is familiar with arrays and how they work. Youre required to write functions to insert and delete elements from an array and sort the array. Were also going to write a command line menu to do these tasks repeatedly. For this problem, you can assume that the array size will never drop below 1 and will never rise above 99.
Please make sure you conform to the following requirements:
1. Create a global constant integer called CAPACITY and set it to 100 (5 points)
2. 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 of the array as parameters. Insert the number at the given position. (10 points)
4. Write a function called remove that takes the array, a number and the current size of the array, and removes the first instance of the number from the array. (10 points)
5. Write a function called sort that takes the array and its current size as parameters and sorts the array in ascending order. You need to use insertion sort, which is given below. (10 points)
6. In the main function, have the user initialize the array. Then, write a command line menu with the following options:
Insert
Remove
Sort
Exit
Call the appropriate functions when the user chooses a particular option. Print an 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 loop i from 1 to Length(A)
x = A[i]
j = i - 1
loop as long as j >= 0 and A[j] > x
A[j+1] = A[j]
j = j - 1
end loop
A[j+1] = x
end loop
Sample Runs:
Enter the number of elements you want to enter (Max 100): 5
Enter 5 numbers
2.5 6 -7 10.7 0.8
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 1
Enter the number: 3.1
Enter the position: 2
Element Inserted.
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 3
The array is:
2.5 6 3.1 -7 10.7 0.8
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 4
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 3
The array is: -7 0.8 2.5 3.1 6 10.7
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 2
Enter the element: 0.8
Element deleted.
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 3
The array is: -7 2.5 3.1 6 10.7
1. Insert an element
2. Remove an element
3. Print the array
4. Sort the array
5. Exit
Enter your option: 5
Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started