im designing a program where it calls a function that uses the linear search algorithm to locate one of the values.
function must keep a count of the comparisons it makes until it finds the value. the program then calls the binary search (a sep. function) to locate the same value-and it should keep a count of the comparisons as well. all of this should be displayed on the screen

sample output:
Original Array: (show 36 random values between 0 and 4999 inclusive-cannot be duplicates)
3224 1903 286
2660 2122 1310
667 789 503 etc.....

Test values:
3234 2660 667 1501 1201

Linear Search Version -Before Sort:
Test Value Result Number of Comparisons
3234 found 1
2660 found 13
667 found 25

//Show average number of comparisons for successfuls searches
//Show average number of comparisons for unsuccessfuls searches

Sorted Array
//show sorted array

Linear Search - AFTER sort:
//show AFTER sort

Binary Search
//show

i wrote a layout for my functions and this is what i have:

//function prototypes

void fillMainList(int list[]);
//this will fill main list array with random numbers from 0 to 4999 inclusive-there will be NO duplicates  (so i must get a rand number and check if it is not in the array already and insert and increment-if it is-i should loop again and test a new number

void TestArray(const int list[], int test[]);
//take main list and put some values in the test array and fill test array with additional random numbers. this will take every 12th element from main list and put it into test value array (ex 0, 12, 24, 36, etc) rest of the array will be filled with random numbers from 0 to 4999 so there are no duplicates in the test value

void PrintArray(const int ary[], int size);
//will print an array on the screen with 12 numbers per row [use setw(6)]. function should know the size of the array before it can print both the main list and the test value

void selectionSort(int list[], int size);
//sort main list array with selection sort

int LinearSearch(const int list[], int value, int& comps);
//searches array for the value with linear search and counts number of comparisons. position of value is found or -1 is returned.

int BinarySearch(const int list[], int value, int& comps);
//searches for value using binary search and counts the number of comparisons. postition of value is found or -1 is returned.

i am able to write a plan for this program but now i dont know how to convert all this writing to code. i need help-so i dont confuse or make it complicated even more so i could use some pointers to guide me. and i also cant find the sorting code in the book-does anyone happen to know it?

thanks! :)

Do it the old fashioned way. Write one functon at a time. Test the function to make sure it works in addition to it being able to compile. Then move on to the next function. If you have no idea what a selection sort and a binary search are then you have no chance of doing this project. If you can't find any information on the topics in the book you are using, which is supposedly where you got the project from, then you must be in one of those advanced classes where they toss out a problem and say solve it. Students in these classes know that there are a number of sources of information they can go to, such as here. Since you have access to this board I know you have access to the internet and I know you know you can search it for lots of different types of information, including information on selection sort and binary serach and a host of other informaton if you don't know how to convert your plans into code. So, get on the internet and search for information you are looking for when you run up against a road block. If you want to learn as you go along then take the information you find and do with it what you can. When you run into a specific problem you can post here with appropriate code, error messages, questions about specific code, etc. If you don't want to learn and just want to have someone give you the code, then I'm sure you can find examples of the code on the internet, too. I hope you take the first route, but the choice is yours.

ok-ill try the first route-and see how far i can get without trouble.

Great. There are lots of people here who know more than I do who routinely help, but you have to demostrate effort if you want them to do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.