Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

ASAP please image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Based on the new code posted ("CodeNew2_linClass.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. 21:05 LTE CodeNew2_1inClass.txt // Example program for oop coding for Bubble-sort 1/ UDC OOP Class 2021 Spring // This is a new version of the sample code for myArray class 2/2/2021 #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 arrt], int length); // will be coded outside; here is just a declarision void mysort() {std::cout0;-){ // this is bubble- sort; for(j=n-1;j>0;j--){ Il sizeof(array) is the number of bytes; // could use sizeof(A)/sizeof(A[0]) for length of array A //std::coutn-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[1]A[i+1]; // this assignment will erase original Ali). A[i+1]-temp; } 21:06 ll LTE CodeNew2_1inclass.txt // Alg of Bubble-sort // Step (1): Let i=0, go through the array by comparing its right-neighbor 17 swap them (A[i], A[i+1]) if (A[i]> A[i+1]). will get the biggeset # on the right (last element). 1/ 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 0;1--){ // 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 0;1--){ // this is not a full- bubble-sort; can be improved for (i=0;i A[i+1]) { // swap them int temp=A[i]: 1/ swap needs a place to save a + A[1]=A[i+1]; // this assignment will erase original A[i]. A 1+1]-temp: } oneArr.setLength(56); std::cout #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 arrt], int length); // will be coded outside; here is just a declarision void mysort() {std::cout0;-){ // this is bubble- sort; for(j=n-1;j>0;j--){ Il sizeof(array) is the number of bytes; // could use sizeof(A)/sizeof(A[0]) for length of array A //std::coutn-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[1]A[i+1]; // this assignment will erase original Ali). A[i+1]-temp; } 21:06 ll LTE CodeNew2_1inclass.txt // Alg of Bubble-sort // Step (1): Let i=0, go through the array by comparing its right-neighbor 17 swap them (A[i], A[i+1]) if (A[i]> A[i+1]). will get the biggeset # on the right (last element). 1/ 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 0;1--){ // 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 0;1--){ // this is not a full- bubble-sort; can be improved for (i=0;i A[i+1]) { // swap them int temp=A[i]: 1/ swap needs a place to save a + A[1]=A[i+1]; // this assignment will erase original A[i]. A 1+1]-temp: } oneArr.setLength(56); std::cout <-1><-1><-1><-1>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

A comparison of the numbers of keys carried by males and females

Answered: 1 week ago