Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the code needs to be in C language. and the code needs to follow the specific instructions provided. thanks March 1 Abstract: Due Often computing

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
the code needs to be in C language.
and the code needs to follow the specific instructions provided. thanks
March 1 Abstract: Due Often computing involves 10 directly at some point. This is in essence a given unless the processor is generating its own values to compute on Algorithes for processing data are good to know, and their implementation is useful. however in early any case where you need to compute on Some data you will also need to read it from or write it to somewhere -Comphe only with gre tiresort.c Introduction: You will write some code to read in data fron t e, sort and output the sorted values In this case while the representation will be the same for all Files, the data way be different. This is to say all Files will be ASCII character files, however some will hold numeric data and one will hold strings. Your code will need to decide which type of information it is dealing with and select an appropriately typed sorting function for the task. keep in mind that the sorting function is not the same as the sorthing algorithm one is an implementation, the other is a theoretical ordering of operations and partitioning of information. The user is allowed to select which sorting algorithm to use at Anti 50 You will need to implement as the first parameter to your code in order to select which sorting algori tholementation on your code should apply. Your code must also take in as yoru second command line parameter a single file name, open it, read in all tokens from it and determine s represeng integer's omstrings. You are guaranteed that the tokens will be ASCII character data and that they all will be com separated. You should however ignore all other separations (newlines, spaces, tabs, etc.) Once all data has been sorted, your code should output the entire sorted contents to STDOUT with each value on its own line in increasing order. (you might find it beneficial then to sort tokens in the same manner). Methodology: A. Comparator In order to implement this behavior you will first need to write to sorts; Sequential Sort and Quick Sort. They may not use any built-in sorting functions. They need to be type-arnositic, as they might need to sort either numeric or string data. The prototype for your sorts must be: int sequentialSort( void" toort, int ("comparator) (void", void) ) int quickSort( void" toSort, int (") comparator (void", void)) Both require a comparator function that is passed in as a function pointer that you will have to write as well. The comparator takes two things of any type and based on the version of the comparator function, should typesets arguments and compare them in a way that makes sense for the kind of information they represent. You will need to write a comparator for numeric data and a Comparator fostrine data that can be used by either your sequential sort or your quick sort. Please have your quick sort select the first element of any list it is to sort as the pivot. The user should select the sort they want with either -1' for Insertion Sort or - for Quick Sort as the first command line parameter. If there is no sort selected that is a fatal error. The first command line parameter should be the sort selection flag, and the second the file nane containing data to sort (see Example below). (Warning!: You may not use built-in sorting functions! Be careful, strcmp() is off the table, however, things that allow you to classify characters as either alphabetic or numeric are okay because they aren't sortine)) (Note: You may notice that the prototypes for both functions are the same, so it ought to be possible to make them one function with a parameter to select the sort type. Please do not do so, but use the prototypes as stated above.) (Note: You are dealing with a user users are unfortuately humans, as humans are sadly quite buggy (re: fallible). Be sure to check for error in all cases. Do not expect that all inputs wil be correctly formatted, or present.) 8. Error: You have three general levels of error: Warnings: dont stop fung these are things that seem like they may be incorrect or night result in unexpected results that you ought to print out a message about, however they aren't a reason to stop running. 16 the file given is empty, for instance, you should print out a warning Errors: dont Stop tung these are things that go wrong that you can fix/react to. You should print out a message and let the user know they happened, but you don't have to stop running because you have a way to deal with it. If a malloc call returns NULL, for instance, you should print out an C C (Note: errors are UNexpected - so do not declare an error if read() comes back with less than the requested bytes, that is expected (and normal) operation) Fatal Errors: these are things that go wrong that you can not fix/react to. You should definitely print out a message and stop running because you have no way to proceed. If the filename you are given does not exist, for instance, there is no way for you to perform your function, so you will need to let the user know and stop running. (Note: this includes the user being a human, i.e. making mistakes. If they do not select a sort by specifying a command line parameter, that is a fatal error since you can not fix the issue or react appropriately) (Note: stopping running doesn't mean you get to not play by the rules - make sure you still deallocate a dynamically-allocated memory and close any open( file descriptors) cFile read As discussed in lecture, 10 is often fairly slow, and file to is almost the slowest thing there is. You may well see non-blocking to effects while reading from the file. You also will not know a-priori how long the file is, how long the individual strings or integers are, or how many there will be. Do not use any of the f. commands (fopen, fread, fwrite, etc.). Only the basic file desciptor.based commands are legal (open, close, read, write). Be sure that you read in your data carefully: - check for EOF (end of file) as you go - make sure you handle nonblocking-reads make sure you find/drop spaces, tabs, newlines and other breaks in the token sequences nake sure you can read in your tokens with no presumption on token length nake sure you can read in your tokens with no presumption on total number of tokens (Note: Given there are a number of aspects that you do not know at compile time, you will need to do a lot of memory allocation at runtime. Be sure you free() any and all dynamically- allocated nenory before your code ends.) Requirements: You must submit the following: a compressed file, Asste.tar.g2, containing: - FileSort.c source code with your main() inplementing the above behavior 2- testplan.txt dochent detailing how you tested your code - what tests did you do and, in a sentence (or two), what were you testing for readme.pdf nent meant for a user detailing how your code operates and how to use it - like the man pages Make sure your code compiles in the following fashion: gcc fileSort.c (Note: You are not allowed to make use of any gec flags: not fsanitize, not 099, (Note: Do not package your code with a Makefile your Makefile will not be run) Today Conclusion: You can segment this work in to a series of modules, which in the end may ease the developement path considerably. You can break the code into the following functional elements: - read from a file open it (and error states) - read in one char up to a coma multiple comma-separated tokens, multiple tokens with interspersed noise (spaces, newlines..) read on char at a time (optionally, read in n chars and extract tokens from the buffer) sorts - code linked lists - code sequential sort first (it is simple) - write sorts on linked lists of numbers - duplicate code and change type/functions to work on linked lists of numbers function pointers - write an integer and a string comparator generalize the input types to be void", but cast then inside the function - copy/paste sort code and modify it to accept your comparators Each of these modules can be written - and tested - in isolation (Note: Keep in mind the way you output the tokens will depend on what they represent . don't forget to select the printf() fornat code appropriately at the end.) (Note: Keep in mind you should free() anything you nalloc(), and close() anything you open()) Example: (Addendun e) > /filesort - /sone file If "./sone file contains: hi, there, every output should be: every o ne one there o ne > ./filesort - -/sonefile If "./sonefile contains: hi, there, every output should be: every hi one there o ne > ./fileSort / some file If "./sonefile contains: hi, there, every output should be: Fatal error: expected two arguments, had one >./fileSort / Somefile - If ./ some file contains: hi, there, every o ne output should be: Fatal error: "./somefile" is not a valid sort flag Fatal error: file -q" does not exist 1 > ./FileSort -./ someotherfile If / someother file contains 123, 14, 510 output should be: 510 March 1 Abstract: Due Often computing involves 10 directly at some point. This is in essence a given unless the processor is generating its own values to compute on Algorithes for processing data are good to know, and their implementation is useful. however in early any case where you need to compute on Some data you will also need to read it from or write it to somewhere -Comphe only with gre tiresort.c Introduction: You will write some code to read in data fron t e, sort and output the sorted values In this case while the representation will be the same for all Files, the data way be different. This is to say all Files will be ASCII character files, however some will hold numeric data and one will hold strings. Your code will need to decide which type of information it is dealing with and select an appropriately typed sorting function for the task. keep in mind that the sorting function is not the same as the sorthing algorithm one is an implementation, the other is a theoretical ordering of operations and partitioning of information. The user is allowed to select which sorting algorithm to use at Anti 50 You will need to implement as the first parameter to your code in order to select which sorting algori tholementation on your code should apply. Your code must also take in as yoru second command line parameter a single file name, open it, read in all tokens from it and determine s represeng integer's omstrings. You are guaranteed that the tokens will be ASCII character data and that they all will be com separated. You should however ignore all other separations (newlines, spaces, tabs, etc.) Once all data has been sorted, your code should output the entire sorted contents to STDOUT with each value on its own line in increasing order. (you might find it beneficial then to sort tokens in the same manner). Methodology: A. Comparator In order to implement this behavior you will first need to write to sorts; Sequential Sort and Quick Sort. They may not use any built-in sorting functions. They need to be type-arnositic, as they might need to sort either numeric or string data. The prototype for your sorts must be: int sequentialSort( void" toort, int ("comparator) (void", void) ) int quickSort( void" toSort, int (") comparator (void", void)) Both require a comparator function that is passed in as a function pointer that you will have to write as well. The comparator takes two things of any type and based on the version of the comparator function, should typesets arguments and compare them in a way that makes sense for the kind of information they represent. You will need to write a comparator for numeric data and a Comparator fostrine data that can be used by either your sequential sort or your quick sort. Please have your quick sort select the first element of any list it is to sort as the pivot. The user should select the sort they want with either -1' for Insertion Sort or - for Quick Sort as the first command line parameter. If there is no sort selected that is a fatal error. The first command line parameter should be the sort selection flag, and the second the file nane containing data to sort (see Example below). (Warning!: You may not use built-in sorting functions! Be careful, strcmp() is off the table, however, things that allow you to classify characters as either alphabetic or numeric are okay because they aren't sortine)) (Note: You may notice that the prototypes for both functions are the same, so it ought to be possible to make them one function with a parameter to select the sort type. Please do not do so, but use the prototypes as stated above.) (Note: You are dealing with a user users are unfortuately humans, as humans are sadly quite buggy (re: fallible). Be sure to check for error in all cases. Do not expect that all inputs wil be correctly formatted, or present.) 8. Error: You have three general levels of error: Warnings: dont stop fung these are things that seem like they may be incorrect or night result in unexpected results that you ought to print out a message about, however they aren't a reason to stop running. 16 the file given is empty, for instance, you should print out a warning Errors: dont Stop tung these are things that go wrong that you can fix/react to. You should print out a message and let the user know they happened, but you don't have to stop running because you have a way to deal with it. If a malloc call returns NULL, for instance, you should print out an C C (Note: errors are UNexpected - so do not declare an error if read() comes back with less than the requested bytes, that is expected (and normal) operation) Fatal Errors: these are things that go wrong that you can not fix/react to. You should definitely print out a message and stop running because you have no way to proceed. If the filename you are given does not exist, for instance, there is no way for you to perform your function, so you will need to let the user know and stop running. (Note: this includes the user being a human, i.e. making mistakes. If they do not select a sort by specifying a command line parameter, that is a fatal error since you can not fix the issue or react appropriately) (Note: stopping running doesn't mean you get to not play by the rules - make sure you still deallocate a dynamically-allocated memory and close any open( file descriptors) cFile read As discussed in lecture, 10 is often fairly slow, and file to is almost the slowest thing there is. You may well see non-blocking to effects while reading from the file. You also will not know a-priori how long the file is, how long the individual strings or integers are, or how many there will be. Do not use any of the f. commands (fopen, fread, fwrite, etc.). Only the basic file desciptor.based commands are legal (open, close, read, write). Be sure that you read in your data carefully: - check for EOF (end of file) as you go - make sure you handle nonblocking-reads make sure you find/drop spaces, tabs, newlines and other breaks in the token sequences nake sure you can read in your tokens with no presumption on token length nake sure you can read in your tokens with no presumption on total number of tokens (Note: Given there are a number of aspects that you do not know at compile time, you will need to do a lot of memory allocation at runtime. Be sure you free() any and all dynamically- allocated nenory before your code ends.) Requirements: You must submit the following: a compressed file, Asste.tar.g2, containing: - FileSort.c source code with your main() inplementing the above behavior 2- testplan.txt dochent detailing how you tested your code - what tests did you do and, in a sentence (or two), what were you testing for readme.pdf nent meant for a user detailing how your code operates and how to use it - like the man pages Make sure your code compiles in the following fashion: gcc fileSort.c (Note: You are not allowed to make use of any gec flags: not fsanitize, not 099, (Note: Do not package your code with a Makefile your Makefile will not be run) Today Conclusion: You can segment this work in to a series of modules, which in the end may ease the developement path considerably. You can break the code into the following functional elements: - read from a file open it (and error states) - read in one char up to a coma multiple comma-separated tokens, multiple tokens with interspersed noise (spaces, newlines..) read on char at a time (optionally, read in n chars and extract tokens from the buffer) sorts - code linked lists - code sequential sort first (it is simple) - write sorts on linked lists of numbers - duplicate code and change type/functions to work on linked lists of numbers function pointers - write an integer and a string comparator generalize the input types to be void", but cast then inside the function - copy/paste sort code and modify it to accept your comparators Each of these modules can be written - and tested - in isolation (Note: Keep in mind the way you output the tokens will depend on what they represent . don't forget to select the printf() fornat code appropriately at the end.) (Note: Keep in mind you should free() anything you nalloc(), and close() anything you open()) Example: (Addendun e) > /filesort - /sone file If "./sone file contains: hi, there, every output should be: every o ne one there o ne > ./filesort - -/sonefile If "./sonefile contains: hi, there, every output should be: every hi one there o ne > ./fileSort / some file If "./sonefile contains: hi, there, every output should be: Fatal error: expected two arguments, had one >./fileSort / Somefile - If ./ some file contains: hi, there, every o ne output should be: Fatal error: "./somefile" is not a valid sort flag Fatal error: file -q" does not exist 1 > ./FileSort -./ someotherfile If / someother file contains 123, 14, 510 output should be: 510

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

Complete Inventory Table B for the total retail value.

Answered: 1 week ago

Question

PLEASE SOLVE ASAP AND I WILL UPVOTE!!

Answered: 1 week ago