Performs a binary search instead of a linear search.

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

Modify the following program so it performs a binary search instead of a linear search. Use the selection sort algorithm to sort the array before the binary search is performed.

#include <iostream>
using namespace std;

// Function prototype
bool searchList(const long [], int, long);

// Constant for array size
const int SIZE = 10;

int main()
{
    // Array of numbers that are always played
    long ticket[SIZE] = {13579,26791,26792,33445,55555,
62483,77777,79422,85647,93121};
                         
    // This variable will hold the winning number.
    long winningNum;

    // Get this week's winning number.
    cout << "\nPlease enter this week's 5-digit "
        << "winning lottery number: ";
    cin >> winningNum;

    // Search for the winning number.
    if (searchList(ticket, SIZE, winningNum))
    {
        // If searchList returned true, then
        // the player has a winning ticket.
        cout << "You have a winning ticket.\n";
    }
    else
    {
        cout << "You did not win this week." << endl;
    }

    return 0;
}

// The searchList function determines if the number to
// search for is in the set of stored numbers using a
// linear search.

bool searchList(const long list[], int numElems, long value)
{
    bool found = false;

    for (int count = 0; count < numElems && !found; count++)
    {
        if (list[count] == value)
            found = true;
    }

    return found;
}

Reference no: EM13165976

Questions Cloud

State significant difference between bacteria and eukaryotes : There are significant differences between Bacteria and Eukaryotes in the manner in which genetic information becomes functional gene product
What is the predicted freezing point of solution : A skyscraper in Pittsburg, built in the early 1970's, is supported by water filled columns. Potassium carbonate was added to the water to precent freezing during cold weather. If the solution is 40.0% K2CO3 by mass, what is the predicted freezing ..
Culture and society has influenced eating disorders : Discuscribe the way culture and society has influenced eating disorders. Discuss why eating disorders are more prevalent in western civilization than in other cultures. Use specific examples to support your answer.
Describe an example of a base : Describe an example of a base and a derived class that shows base-class functions that are overridden in the derived class. Provide the syntax, showing the class definitions of both classes.
Performs a binary search instead of a linear search. : Modify the following program so it performs a binary search instead of a linear search. Use the selection sort algorithm to sort the array before the binary search is performed.
The calcium ion create a procedure for preparing solution : For the calcium ion create a procedure for preparing a 0.100 M solution from the solid, Anyhydrous Calcium Chloride, CaCl2. Make sure to include amounts and equipment you will use for the preparation.
Marketing and technology : Assess all of the issues discussed in Chapter 7 to determine the extent to which you believe the U.S. consumer is being manipulated by marketing and technology, as well as what steps should be taken (if any) to address possible manipulation. Provide ..
What is the vapor pressure of the stored mixture : The solvent for an organic reaction is prepared by mixing 60.0 mL of acetone with 45.0 mL of ethyl acetate. This mixture is stored at 25.0C. The vapor pressure and the densities for the two pure components at 25.0C. What is the vapor pressure of t..
Find out the amount of iron chloride hexahrdrate : The solution of iron (III) chloride used in this experiment is 0.02M. Determine the amount of iron (III) chloride hexahrdrate

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