1. Engineering
  2. Computer Science
  3. todo write your name and a short description about...

Question: todo write your name and a short description about...

Question details

/ TODO: Write your name and a short description about the program.
//
//
//

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

const int SIZE = 10;

// Function Prototypes
void showMenu();
void loadArr(int arr[], int size);
void clearArr(int arr[], int size);
void printArr(int arr[], int size);
bool isSorted(int arr[], int size);
void selectionSort(int arr[], int size);
bool sequentialSearch(int arr[], int size, int searchTerm);
int getSum(int arr[], int size);

int main()
{
   int arr[SIZE];
   int userMenuChoice;
   int searchTerm;
   srand(static_cast<unsigned int>(time(NULL)));
   loadArr(arr, SIZE);

   while (true)
   {
       showMenu();
       cin >> userMenuChoice;

       switch (userMenuChoice)
       {
       case 1:
           loadArr(arr, SIZE);
           break;
       case 2:
           clearArr(arr, SIZE);
           break;
       case 3:
           printArr(arr, SIZE);
           break;
       case 4:
           if (isSorted(arr, SIZE))
               cout << "The array is sorted in descending (non-increasing) order.\n";
           else
               cout << "The array is NOT sorted in descending (non-increasing) order.\n";
           break;
       case 5:
           selectionSort(arr, SIZE);
           break;
       case 6:
           cout << "Please enter an integer to search for: ";
           cin >> searchTerm;
           if (sequentialSearch(arr, SIZE, searchTerm))
               cout << searchTerm << " was found!\n";
           else
               cout << searchTerm << " was NOT found!\n";
           break;
       case 7:
           cout << "The sum of the current array elements is: "
               << getSum(arr, SIZE) << endl;
           break;
       case 8:
           cout << "Thank you for using our CSC 2111 program.\n";
           return 0;
       default:
           cout << userMenuChoice << " is not a menu choice. Please try again.\n\n";
       }
   }
}

// Function to output the menu choices on screen
void showMenu()
{
   cout << endl;
   cout << "1. Load New Random Values" << endl;
   cout << "2. Set All Values to Zero" << endl;
   cout << "3. Print the Array" << endl;
   cout << "4. Check whether the Array is Sorted" << endl;
   cout << "5. Sort the Array in Descending Order" << endl;
   cout << "6. Search the Array." << endl;
   cout << "7. Calculate the Sum." << endl;
   cout << "8. Exit the Program." << endl << endl;

   cout << "Please make your selection: " << endl;
}

// Function to load the array with random numbers between 1 and 100
void loadArr(int arr[], int size)
{
   // TODO: Implement the loadArr function here. HINT: This same function
   // was given on the in-class lab. Feel free to use that code.
}

// Function to set every element in the array to zero
void clearArr(int arr[], int size)
{
   // TODO: Implement the clearArr function here. This is very similar to
   // the loadArr function (except every element is being assigned the value
   // zero).
}

// Function to print each element of the array
void printArr(int arr[], int size)
{
   // TODO: Implement the printArr function here.
}

bool isSorted(int arr[], int size)
{
   // TODO: Implement the isSorted function here. HINT: This is not the function
   // that sorts the array. This function just looks through the array to check
   // whether it is sorted in descending (non-increasing) order. If the array is
   // already sorted, this function returns true. Else it returns false.
}

// Function to sort the array using selection sort
void selectionSort(int arr[], int size)
{
   // TODO: Implement the selectionSort algorithm here. This is the function that
   // actually sorts the array in descending (non-increasing) order. HINT: The
   // textbook gives an example of selection sort in which an array is sorted
   // in ascending (non-decreasing) order. Changing the sort algorithm from
   // ascending to descending only requires a minor adjustment.
}

bool sequentialSearch(int arr[], int size, int searchTerm)
{
   // TODO: Implement the sequential search algorithm here. This function compares
   // the searchTerm passed in the parameter to elements in the array. If the
   // searchTerm matches an array element, the function returns true. Else it
   // returns false.
}

int getSum(int arr[], int size)
{
   // TODO: Implement the getSum function here. This function loops through the
   // array, calculates, and returns the sum of all the elements.
}

assigment

CSC 2111 Lab 04 DUE Tuesday 01/29/2019 before 10:00am Objectives: • Learning to populate an array with randomly generated numbers. • Learning to search an array for a specified item. • Understanding and Implementing the Selection Sort algorithm. • More practice performing operations on arrays. Instructions: Download the file Lab04.cpp from Canvas and copy it into an empty project in Visual Studio. Read and understand the code that is given. Take note of the parameters and return types specified in the function prototypes. // Function Prototypes void showMenu(); void loadArr(int arr[], int size); void clearArr(int arr[], int size); void printArr(int arr[], int size); bool isSorted(int arr[], int size); void selectionSort(int arr[], int size); bool sequentialSearch(int arr[], int size, int searchTerm); int getSum(int arr[], int size); The entire main() function and the showMenu() function are provided for you. Implement these remaining functions to conform to the above prototypes. • The loadArr function was given in the in-class lab. The function populates the array passed in the parameter with random values. Feel free to use the code from the in-class lab. • The clearArr function is very similar to the loadArr function (except every element is being assigned the value zero). • The printArr function loops through the array passed in the parameter and outputs each element to screen. • The isSorted function is not the function that sorts the array. This function just looks through the array to check whether it is sorted [in descending (non-increasing) order]. If the array is already sorted, this function returns true. Else it returns false. • The selectionSort function sorts the array in descending (non-increasing) order. The textbook gives an example of selection sort in which the array is sorted in ascending (non-decreasing) order. Changing the sort algorithm from ascending to descending only requires a minor adjustment. 2 | P a g e • The sequentialSearch function compares the searchTerm passed in the parameter to elements in the array. If the searchTerm matches an array element, the function returns true. Else it returns false. • The getSum function loops through the array, calculates, and returns the sum of all the elements. Testing, Commenting, and Submission: • Please test your code thoroughly. Test all the menu options several times and in different orders. • Since the numbers are random, your output will not match the sample output exactly. Sample Output: C:\Users\jlate\Source\Repos\Lab\Debug>Lab.exe 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 3 Array Elements: 90 82 62 50 20 95 46 52 59 31 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 2 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 3 | P a g e 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 3 Array Elements: 0 0 0 0 0 0 0 0 0 0 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 1 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 3 Array Elements: 44 3 89 56 38 61 62 87 10 96 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4. Check whether the Array is Sorted 5. Sort the Array in Descending Order 6. Search the Array. 7. Calculate the Sum. 8. Exit the Program. Please make your selection: 4 The array is NOT sorted in descending (non-increasing) order. 1. Load New Random Values 2. Set All Values to Zero 3. Print the Array 4 | P a g e 4. Check whether the Array is

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution