Thread: C question
View Single Post

  #1 (permalink)  
Old 03-05-2006, 04:33 AM
TOP TOP is offline
Junior Member
 
Join Date: Feb 2006
Posts: 4
Rep Power: 0
TOP
Default C question

In this program, you try to simulate some concepts in C++. There are
several steps. The first step is to implement the quicksort function, which takes an
abstract array (in the sense that the program does not know what the data type is for the
elements in the array before running time), the size of the array, and the function to do
the comparisons between the elements in the array in the sorting. In addition to these
parameters, quicksort may need some other parameters.
The general idea is that the abstract array may be implemented as a dynamic twodimension
array, while the comparison function can be passed into quicksort function
using a function pointer. You might want to review the class notes and text book (Page
120) on dynamic two-dimension arrays and function pointers. You can also use
$man qsort
to take a look at the library function called qsort.
The second step is to create a function stringcmp for doing the comparisons between
ASCII strings and a function intcmp for doing the comparisons between integers.
The third step is to read data from an input file for students. The format of each student
record is:
Student’s First Name:Student’s Last Name:Years in U of L:GPA
Each line can contain multiple records (separated by *) for several students. For instance,
the following is a sample of the input file.
John:Smith:3:3.24*William:Smith:4:3.8*Bill:Clinton :3:2.34
Jeremy:Hill:4:3.50*Amy:Wood:4:3.90
Your program has a loop, with each iteration prompting a user to select which column to
be sorted. The user can choose to sort either on the students’ first names, students’ last
names, years in U of L or GPAs. The result is displayed on the screen. Since GPAs could
be floating-point numbers, you also need to create a comparison function (called
floatcmp) for comparing two such numbers.
Assume that the user always wants to see the elements in a column to be sorted in the
ascending order.
You can assume that there is no error in the input file and there is no error in the
command-line parameters.
The format for executing your executable is
$sorting indata
Reply With Quote