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 };
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
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc0e52a8c-1926-4339-ae9d-a149f6cb71a7%2Fe396b805-4404-4972-b58d-0abcea520f5d%2Fqc0hlm8_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education