Write a program that initializes an array with ten numbers (given below). Then let the player enter his or her lottery number. The program should ask the user if he/she wants to perform a linear search or binary search. (If the user chooses binary search, using one of the sorting algorithms we learned in the class, sort the array). Based on the searching algorithm payer chooses, it should print out the number of searching comparisons performed and if it was a winning number. int ticket[] = { 85647, 62483, 13579, 26792, 52551, 33445, 79422, 76172, 93121, 26791 };

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Part 1 & 2) Lottery Winners
Write a program that initializes an array with ten numbers (given below). Then let the
player enter his or her lottery number. The program should ask the user if he/she
wants to perform a linear search or binary search. (If the user chooses binary
search, using one of the sorting algorithms we learned in the class, sort the array).
Based on the searching algorithm payer chooses, it should print out the number of
searching comparisons performed and if it was a winning number.
int ticket[] = {85647, 62483, 13579, 26792, 52551, 33445,
79422, 76172, 93121, 26791 };\
Microsoft Visual Studio Debug Console
Enter your 5-digit lottery number: 12345
Press 1 to perform linear search, 2 for binary search: 1
Original values: 85647 62483 13579 26792 52551 33445 79422 76172 93121 26791
Number of comparisons made: 10
You did not win.
Microsoft Visual Studio Debug Console
Enter your 5-digit lottery number: 12345
Press 1 to perform linear search, 2 for binary search: 2
Original values: 85647 62483 13579 26792 52551 33445 79422 76172 93121 26791
Sorted values: 13579 26791 26792 33445 52551 62483 76172 79422 85647 93121
Number of comparisons made: 3
You did not win.
Microsoft Visual Studio Debug Console
Enter your 5-digit lottery number: 79422
Press 1 to perform linear search, 2 for binary search: 1
Original values: 85647 62483 13579 26792 52551 33445
Number of comparisons made: 7
You have a winning ticket.
Microsoft Visual Studio Debug Console
Enter your 5-digit lottery number: 79422
Press 1 to perform linear search, 2 for binary search: 2
D
Original values:
Sorted values: 13579 26791
Number of comparisons made: 2
You have a winning ticket.
79422 76172 93121 26791
85647 62483 13579 26792 52551 33445 79422 76172 93121 26791
26792 33445 52551 62483 76172 79422 85647 93121
X
Transcribed Image Text:Part 1 & 2) Lottery Winners Write a program that initializes an array with ten numbers (given below). Then let the player enter his or her lottery number. The program should ask the user if he/she wants to perform a linear search or binary search. (If the user chooses binary search, using one of the sorting algorithms we learned in the class, sort the array). Based on the searching algorithm payer chooses, it should print out the number of searching comparisons performed and if it was a winning number. int ticket[] = {85647, 62483, 13579, 26792, 52551, 33445, 79422, 76172, 93121, 26791 };\ Microsoft Visual Studio Debug Console Enter your 5-digit lottery number: 12345 Press 1 to perform linear search, 2 for binary search: 1 Original values: 85647 62483 13579 26792 52551 33445 79422 76172 93121 26791 Number of comparisons made: 10 You did not win. Microsoft Visual Studio Debug Console Enter your 5-digit lottery number: 12345 Press 1 to perform linear search, 2 for binary search: 2 Original values: 85647 62483 13579 26792 52551 33445 79422 76172 93121 26791 Sorted values: 13579 26791 26792 33445 52551 62483 76172 79422 85647 93121 Number of comparisons made: 3 You did not win. Microsoft Visual Studio Debug Console Enter your 5-digit lottery number: 79422 Press 1 to perform linear search, 2 for binary search: 1 Original values: 85647 62483 13579 26792 52551 33445 Number of comparisons made: 7 You have a winning ticket. Microsoft Visual Studio Debug Console Enter your 5-digit lottery number: 79422 Press 1 to perform linear search, 2 for binary search: 2 D Original values: Sorted values: 13579 26791 Number of comparisons made: 2 You have a winning ticket. 79422 76172 93121 26791 85647 62483 13579 26792 52551 33445 79422 76172 93121 26791 26792 33445 52551 62483 76172 79422 85647 93121 X
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education