Computer Science 1 Problem Solving and Program Design using C++

computer science

Description


Mathematical Science Division

Computer Science 1 Problem Solving and Program Design using C++

You are to read in two sets of numbers both of known size.  The first set of numbers will be numbers the search will be searching into.  The second set of numbers will be the numbers to be searched.  Numbers are real numbers.  You will declare as float for the first set of numbers, as double for the second set.

 

In both sets of numbers, the format is defined as follows.

·         The beginning line is a number indicating how many numbers there are in this set, followed by

·         numbers in this set one per line.

 

In your program, those two sets of numbers will be stored in two dynamically created arrays.  In this assignment, you are to do the following.

 

1.      Search each number in the second set to see if it is in the first set, print the index, and obtain the comparison count by using the linear search algorithm.

2.      Sort the first set by using a selection sort algorithm.

3.      Search each number in the second set to see if it is in the first set, print the index, and obtain the comparison count by using the binary search algorithm.  For the binary search, calculate Mid as (Low + High) / 2.

 

In the first three lines of the output, print your name, section, and assignment number.

 

In every program file (.cpp and/or .h) you turn in, use comment lines to show the following:

            //Your name

            //Section

            //Assignment number

 

You design your own output format.

 

Submissions with no name, section, and assignment number will be asked to resubmit.

 

Turn in the following for credit.

            all .cpp files

            output file


 

 

Sample Input

Sample Output

16

    6.96

   54.62

   74.57

  222.68

  177.01

  146.39

  113.77

    9.60

  197.13

   72.67

   88.93

   41.87

  273.77

  165.25

  247.15

  274.70

20

    6.96

   54.62

   74.57

  222.68

  177.01

  146.39

  113.77

    9.60

  197.13

   72.67

   88.93

   41.87

  273.77

  165.25

  247.15

  274.70

  254.10

  269.72

  105.24

  245.47

John Smith

Section 0112

Assignment #7

 

Linear Search:

 

          Searched   Index  Comparisons

              6.96       0     1

             54.62       1     2

             74.57       2     3

            222.68       3     4

            177.01       4     5

            146.39       5     6

            113.77       6     7

              9.60       7     8

            197.13       8     9

             72.67       9     10

             88.93      10     11

             41.87      11     12

            273.77      12     13

            165.25      13     14

            247.15      14     15

            274.70      15     16

            254.10      -1     16

            269.72      -1     16

            105.24      -1     16

            245.47      -1     16

 

Binary Search:

 

          Searched   Index  Comparisons

              6.96       0     4

             54.62       3     2

             74.57       5     3

            222.68      12     4

            177.01      10     4

            146.39       8     4

            113.77       7     1

              9.60       1     3

            197.13      11     2

             72.67       4     4

             88.93       6     4

             41.87       2     4

            273.77      14     4

            165.25       9     3

            247.15      13     3

            274.70      15     5

            254.10      -1     4

            269.72      -1     4

            105.24      -1     4

            245.47      -1     4

 


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.