Question: ASAP PLEASE! This is c++ Based on the new code posted (CodeNew2_1inClass.txt), you need to do the following two tasks: (1) Modify the code to
ASAP PLEASE! This is c++
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; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
