/*------------------------------------------------------------------------- // AUTHOR: your name // FILENAME: Lab10.cpp // SPECIFICATION: // FOR: CSE 100- Lab #10 // TIME SPENT: how long it took you...

Please do what the pdf says and follow instructions on cpp. Open cpp in visual studio and complete assignment.



/*------------------------------------------------------------------------- // AUTHOR: your name // FILENAME: Lab10.cpp // SPECIFICATION: // FOR: CSE 100- Lab #10 // TIME SPENT: how long it took you to complete the assignment //----------------------------------------------------------------------*/ #include using namespace std; int main() { // ============================================================ // Declare some variables. You might need // // - an integer for the array size, // - a int for the exchange element, and // - a cin for requesting input // // --> // ============================================================ // Request array size from the user // // - Print this message "How many elements in the array?" // - Request an integer from the user using cin and save it // // --> // Declare a int array by the size you received above // --> // ============================================================ // Fill in the Array int numOfElements = -1; for (int i = 0; i < numofelements;="" i++)="" {="" display="" the="" message:="" "please="" enter="" the="" next="" value:"="" --=""> // Request the next element (int) from the user, // save it to the ith element of the array // --> } // ============================================================ // Sort the array's elements in increasing order // // Here we will use Selection Sort like algorithm. // The first for loop iterates all elements as element_i for (int i = 0; i < numofelements;="" i++)="" {="" the="" second="" for="" loop="" finds="" the="" right="" position="" of="" element_i="" for="" (int="" j="i" +="" 1;="" j="">< numofelements;="" j++)="" {="" compare="" ith="" value="" and="" jth="" value,="" -="" if="" array[i]="">= array[j], swap these two values // // For example, let array[i] = 10, array[j] = 20, to swap // array[i] and array[j] means array[i] will become 20 // and array[j] will have 10. // // To swap the values in two position, you would need an // extra variable to temporarily hold the value. For example, // // temp = array[i]; // array[i] = array[j]; // array[j] = temp; // // --> } } // ============================================================ // Display the sorted array on the same line cout < "the="" array="" after="" sorting"="">< endl;="" for="" (int="" i="0;" i="">< numofelements;="" i++)="" {="" print="" ith="" element,="" do="" not="" include="" line="" break="" --=""> } // Print a line break // --> // ============================================================ // Remove the minimum in the sorted array // // As our array is sorted in the increasing order, to remove the // minimum, we just remove the first element in the array. It is like // shifting the array to the left by one element. // Because we are doing shifting, in each iteration, we use two // values, one at index i, the other at index i+1. // To prevent us from going over the boundary of array, the following // offset variable should be set as the correct value. int offset = -1; // In this for loop, we move the element at i + 1 to the position i for (int i = 0; i < numofelements="" -="" offset;="" i++)="" {="" move="" array[i="" +="" 1]="" to="" array[i]="" }="" the="" last="" element="" will="" be="" set="" as="" zero.="" remember="" the="" greatest="" index="" should="" be="" array's="" length="" -="" 1.="" --=""> // ============================================================ // Display the Array after removing the first element cout < "the="" array="" with="" the="" minimum="" removed"="">< endl;="" for="" (int="" i="0;" i="">< numofelements;="" i++)="" {="" print="" ith="" element,="" do="" not="" include="" line="" break="" --=""> } // Print a line break // --> // ============================================================ // Search for an element and remove it // Ask the user which element to remove cout < "enter="" the="" value="" to="" search="" and="" remove:"="">< endl;="" use="" cin="" to="" get="" a="" value="" for="" search="" int="" valuetoremove="//" to="" search,="" we="" can="" iterate="" all="" values,="" record="" the="" index="" of="" target="" (t),="" and="" then="" shift="" to="" the="" left="" values="" from="" t="" to="" the="" end.="" boolean="" isfound="false;" for="" (int="" i="0;" i="">< numofelements;="" i++)="" {="" if="" ith="" element="=" valuetoremove,="" set="" a="" flag="" isfound="" if="" isfound,="" if="" i="" +="" 1="" is="" available="" move="" element="" i="" +="" 1="" to="" index="" i="" if="" i="" +="" 1="" is="" not="" available="" set="" element="" i="" as="" zero="" }="" if="" (isfound)="" {="" cout="">< "search="" element="">< endl;="" }="" else="" {="" cout="">< "search="" element="" not="" found"="">< endl;="" }="" =="==========================================================" display="" the="" final="" array="" cout="">< "\nthe="" final="" array"="">< endl;="" for="" (int="" i="0;" i="">< numofelements;="" i++)="" {="" print="" ith="" element,="" do="" not="" include="" line="" break="" --=""> } // Print a line break // --> } CSE 100 - Lab 10 What this Lab Is About: • Use of the arrays • Sorting a group of numbers and shifting the array Use the following Coding Guidelines: • When declaring a variable, you usually want to initialize it. • Remember you cannot initialize a number with a string. • Remember variable names are case sensitive. • Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. • Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem Description For this lab, you will create a basic array of numbers, fill in the elements of the array by prompting the user for input, sort the elements of array and display the sorted elements to the user. Step 1: Create a file called Lab10.cpp At the beginning of each programming assignment you must have a comment block with the following information: 1. /*------------------------------------------------------------- 2. // AUTHOR: your name. 3. // FILENAME: title of the source file. 4. // SPECIFICATION: your own description of the program.
Apr 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here