Coders Packet

C++ code for all operation in an array

By Harsh Kumar jha

In this code, the user can perform all possible operations related to an array in the c++ programming language.

In this code, firstly user will be asked to insert the size of your array. After inserting the size of your array, the user will be asked to insert the number of elements. After inserting the numbers in the array, the user will be asked to choose between three options which are as follows  

1)Sorting
2)Searching
3) Other operation

If the user enters 1 for the first option i.e. sorting option then again the user will be asked to choose between six options which are as follows :

1)Bubble Sort
2)Insertion Sort
3)Selection Sort
4)Quick Sort
5)Merge Sort
6)Count Sort

Now the user has to choose between 1 to 6 to perform the sorting in correspondence to the chosen option. If the user enters a number from 1 to 6, then sorting will be done by use of that sorting algorithm in correspondence to the chosen option and a sorted array will be displayed. If the user enters any number apart from 1 to 6, "Wrong choice..!!" will be displayed on the screen. The screen will also display "You want to perform again another operation..!!(y/n): ", now user have to enter "y" or "Y" if he wants to continue or "n" or "N" if he doesn't want to continue. If the user enters "Y" or "y" to continue the program then again he will be asked to enter the size of a new array. After inserting the size of your new array and its element the user will be asked again the three options which are as follows :

1)Sorting
2)Searching
3) Other operation

Now, if the user enters 2 for searching an element in an array and its position then the user will be asked again to choose between two options which are as follows:

1)Linear Search
2)Binary Search

Now the user has to choose an option between these two to perform the searching operation with the help of the correspondence searching algorithm. If the user enters 1 or 2 he will be asked to enter the number from the inserted array to perform the searching operation. If the number user has entered is present in the array, the index of that number will be printed on the screen or else it will print, the number is not present in the array. Or if the user enters the number apart from 1 or 2, "Wrong choice..!!" will be displayed on the screen. The screen will also display "You want to perform again another operation..!!(y/n): ", now user have to enter "y" or "Y" if he wants to continue or "n" or "N" if he doesn't want to continue. If the user enters "Y" or "y" to continue the program then again he will be asked to enter the size of a new array. After inserting the size of your new array and its element the user will be asked again the three options which are as follows :

1)Sorting
2)Searching
3) Other operation

Now, if the user enters 3 to perform other operation in an array, then the user will be asked again to choose between two options which are as follows:

1)Deletion
2)Insertion
3)Maximum and minimum element in an array

If the user enters 1 to perform deletion operation, he will be asked to enter the number from the array to delete. If the number is present in the array it will be deleted and the new array will be printed on the screen or else it will print entered number is not present in the array. If the user enters 2 to perform the insertion operation, he will be asked to enter the number and its index number where he has to insert that number. Entered number will be inserted into the array and a new array will be printed on the screen. If the user enters option 3, the maximum and minimum number present in the entered array will be printed on the screen. If the user enters the number apart from 1 to 3, "Wrong choice..!!" will be displayed on the screen. The screen will also display "You want to perform again another operation..!!(y/n): ", now user have to enter "y" or "Y" if he wants to continue or "n" or "N" if he doesn't want to continue. If the user enters "Y" or "y" to continue the program then again he will be asked to enter the size of a new array. After inserting the size of your new array and its element the user will be asked again the three options which are as follows :

1)Sorting
2)Searching
3) Other operation

Now, if the user enters the number apart from 1 to 3, "Wrong choice..!!" will be displayed on the screen. The screen will also display "You want to perform again another operation..!!(y/n): ", now user have to enter "y" or "Y" if he wants to continue or "n" or "N" if he doesn't want to continue. If the user enters "Y" or "y" to continue the program then again he will be asked to enter the size of a new array. After inserting the size of your new array and its element the user will be asked again the three options which are as follows :

1)Sorting
2)Searching
3) Other operation

and it will go so on.

Download Complete Code

Comments

No comments yet