Question: ASAP PLEASE! Based on the new code posted (CodeNew2_1inClass.txt), you need to do the following two tasks: (1) Modify the code to decide if an

ASAP PLEASE!

Based on the new code posted ("CodeNew2_1inClass.txt"), you need to do the following two tasks:

(1) Modify the code to decide if an input number 160 is in the array A? Display your result using "std::cout."

(2) To find if a number in an array is called the search algorithm. So (1) is a search. This search is usually called the sequential search.

Create a function called mySearch() in myClass to complete the job as described in (1). ( Just like the instructor did for bubble-sort())

(3) Use your name initial to replace myClass to be "yourNameInitial"Class. For instance, LiChen's myClass willl be LCClass.

--------------------------------------------------------------------------------------------------------------------------

//CodeNew2_1inClass.txt

#include  #include  int A[]={3,1,-2,5,9,-100,6,7,35,20}; class myArray{ private: int length; public: void setLength(int n) { length=n;} int getLength(){return length;} myArray(int n){ length=n; // constructor 1 return;} myArray(){ return;} // overloading use the same name but different parameters void mysort(int arr[],int length); // will be coded outside; here is just a declarision void mysort() {std::cout<<"Overloading : just a test"<<" ";}// overloading for functions }; void myArray::mysort(int arr[],int length){ int i,j; int n=length; //for (j=n-1;j>0;j--){ // this is bubble-sort; for (j=n-1;j>0;j--){ // sizeof(array) is the number of bytes; // could use sizeof(A)/sizeof(A[0]) for length of array A //std::cout<< "j="<n-1 are already fixed (larger ones) if (A[i] > A[i+1]) { // swap them int temp=A[i]; // swap needs a place to save a # A[i]=A[i+1]; // this assignment will erase original A[i]. A[i+1]=temp; } } } } // Alg of Bubble-sort // Step (1): Let i=0, go through the array by comparing its right-neighbor // swap them (A[i] , A[i+1]) if (A[i] > A[i+1]). will get the biggeset # on the right (last element). // Step (2): i go back to 0; start over Step 1, we will get the second largest #. // repeat agian and again, until no one left in the array that is not sorted. // How many for-loops do we need? 2 // int main() { int i; int n=10; myArray oneArr(n); myArray secArr; oneArr.mysort(A,n); secArr.setLength(120); secArr.mysort(); std::cout << "SecArr length = "<0;j--){ // this is not a full-bubble-sort; can be improved for (i=0;i A[i+1]) { // swap them int temp=A[i]; // swap needs a place to save a # A[i]=A[i+1]; // this assignment will erase original A[i]. A[i+1]=temp; } } } */ oneArr.setLength(56); std::cout << "length = "<                        

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!