CSCI 203 Project #1

Getting Started

 

 

Purpose: This project is a warmup to get you back into the swing of programming, and to make sure you are familiar with the environment that we will be using.

 

You are to write a program that takes a single command line parameter, which is the name of a data file.  This data file contains an integer on the first line, which is the count for the number of integers in the rest of the file, and then that many integers, one per line.  Your program is to read the first integer, allocate a dynamic array to hold the rest of the data, and read the data into the array you allocated.  You should then sort the array in place (ie don’t use a second array).  Finally, you should prompt the user to input an integer, and then should use binary search to determine if the integer the user typed is in the array or not.  Your program should terminate if the user inputs a negative number.  To help you with your testing, here is a sample data file.

 

 

Turnin: You should print out your code, with sample output appended at the end of it as comments, and turn that in.

 

Hints:  Right now we aren’t concerned with efficiency.  You should be able (perhaps by referring to your 116 notes) to write a bubble sort routine to sort the data, and then to write a binary search routine to search the sorted data.  If you need additional help, check the blackboard discussion area.

 

Here is some sample output:

 

Reading from file dat1a.txt

Read 1000 numbers

Data sorted

Enter number to look for:

387

387 was not found in the data

Enter number to look for:

388

388 was found in the data

Enter number to look for:

-1

Exiting...

Press any key to continue