Code a program with functions to search and sort an array

Assignment Help C/C++ Programming
Reference no: EM132109213

Programming Language: C++

Lab - Searching and Sorting

Objectives:

Use a single dimension array

Use a menu to call various functions

Use multiple sorts and searches

Instructions:

Code a program with functions to search and sort an array, along with a print menu function and a dispatch function. Also set up a 100 position integer array and an integer variable, called size, globally (before all methods are coded).

Then the array and size do not have to be passed to any of these functions. (The alternative approach would be to define the array in the dispatch method after reading in a size. Then array name and size would be passed to all methods.)

The menu should look like the following:

0. Exit

1. Get the size needed for today's use of the array.

2. Fill an array with random numbers from 1-100.

3. Print the array with position numbers.

4. Sort the array in ascending sequence

5. Sort the array in descending sequence - use a different sort algorithm from step 4.

6. Sequential search of the array for a target - target should be passed to method and the method returns the found location or -1.

7. Binary search of the array for a target - target should be passed to method and the method returns the found location or -1. Remember that the array must be sorted before calling the binary search function.

Run:

The program should start with a request for a size from the user. (Type in 15.)

the lab in this order:

Ask the user for the size of the array (1)

Fill the array with random values (2)

Print the array (3) (List the position number and the contents of the array position)

Sequentially search the array for a number in the array and then one not in the array, printing the appropriate messages of "Found in position ____" and "Not Found" (6, 6)

Sort the array into ascending sequence (4)

Print the array (3)

Do a binary search of the array for a number in the array and then for a value not in the array, printing the appropriate messages of "Found in position ____" and "Not Found" (7, 7)

Sort the array into descending sequence (5) (Use a different sort algorithm from code 4)

Finally, print the array again (3)

The main method will look like this: (everything else will be done in other functions)

int main ()

{

printMenu();

cout << "Type in a choice " << endl;

cin >> choice;

while (choice != 0)

{

dispatch (choice); // one big switch statement

printMenu();

cout << "Type in a choice " << endl;

cin >> choice;

}

return 0;

}

For the two search methods (choice 6 and 7), the program must ask for the target and then read in a target before calling the search method. After calling the search method, the program must determine if the search returned an integer (print "Found in position ______") or the search returned a -1 (print "Not Found").

Submission: Turn in your source and output file to D2L in a zipped folder.

Reference no: EM132109213

Questions Cloud

Display menus for converting length and calculates results : Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10.
Potential impact on the marketing mix : BSBMKG502 - Establish and adjust the marketing mix - Identify the key characteristics of the products and/or services and their significance to the market
Write a program that prompts the user to input a sequence : A null-return function, outVowels, that outputs a list of each vowel and the number of times that vowel appeared in the input sequence.
Create a method that determines a score for each : Using the helper class and text files described above, load the 20 movie names and the movie ratings from 30 people into two arrays in memory.
Code a program with functions to search and sort an array : Code a program with functions to search and sort an array, along with a print menu function and a dispatch function.
What is a programming language : Answer the following Question : What is a programming language?
Demonstrate the class with a driver program : In a course, a teacher gives the following tests and assignments: A lab activity that is observed by the teacher and assigned a numeric score.
Write an m-file in matlab which can perform a word search : Convey how the program was developed, what issues were encountered, whether the program was successful (and if not, why not), etc.
Create a patron class for the library : The class will have a user's name. library card number, and library fees (if owed). Have functions that access this data, as well as a function to set the fee.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd