can any1 plz make this assignment
can any one plz make this assignment for me as i have no idea about programming but i to pass this subject i dont know why.......
TSD Laboratory 5
page 1• Understand and implement a non-trivial algorithm.
Random File I/O - Abstract Data Types and Modules
• Practice using random file I/O.
• Further experience using abstract data types (ADTs) and modules in applications.
• Further practice using arrays and dynamic memory allocation.
• Experience using the standard C qsort array sorting function.
• A first encounter with the void pointer and the C function pointer.
We will start with an existing binary file
containing Robot data.
The aim is to write a new robot data file containing
the same Robot data from the original file, but randomly
The startup material contains the RobotFile case study program examined in lecture module 4.
Build the RobotFile program using the provided robotFile[robotFile.exe].PRJ Quincy
project. Using RobotFile.exe, produce a binary file binbots.data containing 2 or 3 extra robots in
addition to the robots hard-coded into the program source (a total of 7 or 8 robots).
You will start a new project fileShuffle reusing most of the source files of the RobotFile program,
including the libUtil.a library. Both the Robot abstract data type and the util library will be re-used
unchanged. Some of the functions within robotFile.c are also reusable without change.
It is recommended to create a fileShuffle directory under …/Lab5/ and to copy all source code and
the newly created data file binbots.data into the new subdirectory.
2 - Understand The Task:
The aim is to write the same Robot instances contained in file binbots.data into a new file
shuflbots.data, but in a random order.
Randomly shuffling data is a task that involves a lot of processing.
Here is a common algorithm to shuffle an array of data:
1. Associate a random integer with each of the elements in the array.
2. Sort the array based on an (increasing or decreasing) value of the random numbers using an
efficient array sorting algorithm.
The array is now randomly shuffled. We will use this algorithm to shuffle the robots.
To better understand the shuffling algorithm and its implementation in C, refer to the
Shuffling Problem document on Blackboard.
TSD Laboratory 5
Steps to the Solution:
1. Create new ADT DataKey (data and key pair) composed of:
struct DataKey with two elements:
data - an integer
key - an integer.
Function dk_init() Initialises a DataKey ( a type of function sometimes called a constructor):
DataKey dk_init(int data);
It takes the integer data to store into the pair as a parameter, generates a random integer between 0
and RAND_MAX, and returns a DataKey.
This constructor can be used the following way to create a DataKey instance conatining integer val:
DataKey pair1 = dk_init(val);
Function dk_compare() - to be used by qsort() to sort an array of DataKey pairs:
int dk_compare(void *dk1, void *dk2);
Compares the values of the keys at addresses dk1 and dtk2. It returns the integer difference between
the values of keys at addresses dk1 and dk2. Note that the void * parameters will have to be
converted to DataKey * types inside the dk_compare() function code.
The new abstract data type is written in files DataKey.h for the interface (struct declaration and
function prototypes) and DataKey.c for its implementation (function bodies).
2. Main program:
The steps in the main program fileShuffle.c are as follows:
• Use fseek to seek to end of file and ftell to obtain the size (in bytes) of file binbots.data.
• Compute the number of Robot instances numRobots in the file by dividing by the size of the
• Dynamically create an array of numRobots DataKey elements each containing the array index as
data, and a random number as key.
• Sort the DataKey array based on the key values using the C qsort() function. The array indexes
inside the array are now randomly shuffled. See the hint on using qsort below.
• In a loop, read the Robot instances from binbots.data one by one, using the shuffled array indexes
stored in the DataKey array, and save each Robot as it is read, sequentially into file
• The robots will be randomly shuffled in the new file.
• Load and display the contents of both files to demonstrate the effect of file shuffling.
Although this program remains only a short time in memory, make it a point to free all memory
allocated by malloc when it is no longer used by the program. Ask your tutor to check your work to
make sure that there is no potential memory leak.
Use functions to subdivide the problem and keep all functions small !
Backup all your work!
if u think u can do this plz post ya email address ill send the related files......
plz help me.........................