(The answer orginally listed is not complete no linked list) write a C++ program
ID: 3684104 • Letter: #
Question
(The answer orginally listed is not complete no linked list)
write a C++ program (in classes) that takes the numbers 38, 5, 2, 70, 39, 14, 27, 3, and 100 and does the following: asks the user to select the preferred data structure (array or linked list) asks the user to select the preferred algorithm (search or sort) asks the user to select the preferred search or sorting algorithm, depending on the previous selection sorting algorithms: selection sort, bubble sort, merge sort, quicksort, insertion sort searching algorithms: selection search (linear search), binary search carries out the user-selected searching or sorting algorithm and asks the user if they would like to continue - the program continues executing until the user indicates that they wish to exit the program
Explanation / Answer
sample code to read array of integers
#include <iostream>
using namespace std;
int main()
{
int a[10],i,b=0;
cout<<"enter the array elements ";
for(i=0;i<10;i++)
{
cin>>a[i];
}
}
Sample code to prompt user for an input
main()
{
int choice;
while (1)
{
cout<<endl<<"---------------------------------"<<endl;
cout<<endl<<"Operations to be performed on elements"<<endl;
cout<<endl<<"---------------------------------"<<endl;
cout<<"1.linearSearching"<<endl;
cout<<"2.binarySearching"<<endl;
cout<<"3.Insertionsort"<<endl;
cout<<"4.Selectionsort"<<endl;
cout<<"5.quicksort"<<endl;
cout<<"6.mergesort"<<endl;
cout<<"7.bubblesort"<<endl;
cout<<"8.Exit "<<endl;
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"LinearSearch "<<endl;
ENTER LINEAR SEARCH CODE LOGIC HERE
cout<<endl;
break;
case 2:
cout<<"BinarySearch: "<<endl;
ENTER BINARY SEARCH CODE LOGIC HERE
cout<<endl;
break;
case 3:
cout<<"InsertionSort:"<<endl;
ENTER INSERTIONSORT CODE LOGIC HERE
cout<<endl;
break;
case 4:
cout<<"SelectionSort: "<<endl;
ENTER SELECTIONSORT CODE LOGIC HERE
cout<<endl;
break;
case 5:
cout<<"QuickSort: "<<endl;
ENTER QUICKSORT CODE LOGIC HERE
break;
case 6:
cout<<"MergeSort:"<<endl;
ENTER MERGESORT CODE LOGIC HERE
cout<<endl;
break;
case 7:
cout<<"BubbleSort: "<<endl;
ENTER BUBBLESORT CODE LOGIC HERE
cout<<endl;
break;
case 8:
cout<<"Exiting..."<<endl;
exit(1);
break;
default:
cout<<"Wrong choice"<<endl;
}
}
}
Sample code logic for linear search
int num;
cout<<"Enter number to search: ";
cin>>num;
for(i=0;i<10;i++)
{
if(num==a[i])
{
cout<<"Found at index number: "<<i;
break;
}
else
{
cout<<"Sorry your search returned NO results. :(";
}
Sample code logic for binary search
int beg=0,mid,end=9,num,i;
cout<<“nEnter Elements of Array in Accending ordern”;
for(i=0;i<10;++i)
{
cin>>a[i];
}
cout<<“nEnter element to search:”;
cin>>num;
while(beg<=end)
{
mid=(beg+end)/2;
if(a[mid]==num)
cout<<“nElement is Founded at “<<mid+1;
else if(num>a[mid])
beg=mid+1;
else if(num<a[mid])
end=mid-1;
}
cout<<“nElement is not found….!!!”;
note-by adding the related code logics at the switch case and by modifying or by using all the above sample codes the given question can be answered.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.