[Solved] Programming Assignment #3: Linked List Strings COP 3502

$25

File Name: Programming_Assignment_#3:_Linked_List_Strings_COP_3502.zip
File Size: 518.1 KB

SKU: [Solved] Programming Assignment #3: Linked List Strings COP 3502 Category: Tag:
5/5 - (1 vote)

Programming Assignment #3: Linked List StringsCOP 3502,

AbstractIn this programming assignment, you will use linked lists to represent strings. You will implement functions that manipulate these linked lists to transmute the strings they represent. In doing so, you will master the craft of linked list manipulation!By completing this assignment, you will also gain experience with file I/O in C and processing command line arguments.AttachmentsListString.h, input{01-03}.txt, output{01-03}.txtDeliverablesListString.c^ Note: Capitalization of your filename matters!1. Overview1.1. Array Representation of Strings in CWe have seen that strings in C are simply char arrays that use the null terminator (the character ) to mark the end of a string. For example, the word dwindle is represented as follows:d w i n d l e x fNotice the unused portion of the array may contain garbage data.1.2. A Linked List Representation of StringsIn this assignment, we will use linked lists to represent strings. Each node will contain a single character of the string. The null terminator () will not be afforded its own node in the linked list.Instead, we will know that we have reached the end of a string when we encounter a NULL pointer.For example, the word dwindle is represented as follows:1.3. String TransformationsYou will implement two key string transformations: a replace character function that replaces all instances of a particular character with a specified string, and a reverse string function that reverses a linked list. These are described in detail in Section 4, Function Requirements, on page 6.1.4. Linked List Node Struct (ListString.h)You must use the linked list node struct we have specified in ListString.h without any modifications. You should #include the header file from ListString.c like so:#include ListString.hThe node struct is defined in ListString.h as follows:typedef struct node{char data;struct node *next;} node;d w i n d l e NULL2. Guide to Command Line Arguments2.1. Capturing Command Line Arguments in a C ProgramWhen we run your program, we will use a command line argument to specify the name of an input file that your program will read. For example:./a.out input01.txtWe will always give the name of a valid input file as a command line argument when running your program.Its super easy to get command line arguments (like the string input01.txt in this example) into your program. You just have to change the function signature for main(). Whereas we have typically seen main() defined using int main(void), you will now use the following function signature instead:int main(int argc, char **argv)Within main(), argc is now an integer representing the number of command line arguments passed to the program (including the name of the executable itself). argv is an array of strings that stores all those command line arguments. argv[0] stores the name of the program being executed. Heres a simple program to print out all the command line arguments passed to a program:#include <stdio.h>int main(int argc, char **argv){int i;for (i = 0; i < argc; i++)printf(argv[%d]: %s
, i, argv[i]);return 0;}If we compiled this code into an executable file called a.out and ran it from the command line by typing ./a.out input01.txt lol hi, we would see the following output:argv[0]: ./a.outargv[1]: input01.txtargv[2]: lolargv[3]: hi2.2. Passing Command Line Arguments in CodeBlocksYou can set up CodeBlocks to automatically pass command line arguments to your program every time you hit Build and run (F9) within the IDE. Simply go to Project Set programs arguments, and in the box labeled Program arguments, type your desired command line arguments.For example, the following setup passes input01.txt lol hi as command line arguments to the program when compiled and run within CodeBlocks. (I dont think you need to check off the box next to This target provides. CodeBlocks seems to take care of that automatically after you hit OK.) If you compile your program like this in CodeBlocks and later run your executable from the command line, you will still need to supply fresh arguments at the command line. At any rate, dont forget to test your code on Eustis before submitting, even if you do most of your development in CodeBlocks.3. Input Files3.1. Input File FormatThe input file will begin with a single string that contains at least 1 character and no more than 1023 characters, and no spaces. Read in the string and convert it to a linked list. That will become your working string, and you will manipulate it according to the remaining commands in the input file.Each of the remaining lines in the file will correspond to one of the following string manipulationcommands:Command Description@ key str key is a single character. str is a string. In your working string, replace allinstances of key with str.Note: key and str are guaranteed to contain alphanumeric characters only(A-Z, a-z, and 0-9). str can range from 1 to 1023 characters (inclusively). key key is a single character. Delete all instances of key (if any) from your working string.~ Reverse the working string.! Print the working string.For more concrete examples of how these commands work, see the attached input/output files and check out the function descriptions below in Section 4, Function Requirements (page 6).3.2. Sample Input/Output FilesWe have attached a few sample input and output files so you can check that your program is working as intended. Be sure to use diff on Eustis to make sure your output matches ours exactly. We also encourage you to develop your own test cases; ours are by no means comprehensive.Function requirements are listed on the following page.4. Function RequirementsYou have a lot of leeway with how to approach this assignment. There are only five required functions, and there are lots of different ways to implement them. How you structure the rest of your program is up to you. You may write helper functions as you see fit.int main(int argc, char **argv);Description: You have to write a main() function for this program.Returns: 0 (zero)node *stringToList(char *str);Description: Convert the string str to a linked list. If str is NULL or an empty string (),simply return NULL.Returns: The head of the new linked list.node *replaceChar(node *head, char key, char *str);Description: Takes a linked list (head) and replaces all instances of a certain character (key) with the specified string (str). If str is NULL or the empty string (), this function simply acts o delete all instances of key from the linked list. If key does not occur anywhere in the linked list, the list remains unchanged.Returns: The head of the modified linked list.node *reverseList(node *head);Description: Reverse the linked list.Returns: The head of the reversed list.void printList(node *head);Description: Print the string stored in the linked list, followed by a newline character,
. If head is NULL, simply print (empty string) (without the quotes), follow by a newline character,
.Returns: Nothing. Its a void function.5. Compilation and Testing (Linux/Mac Command Line)To compile at the command line:gcc ListString.cBy default, this will produce an executable file called a.out that you can run by typing, e.g.:./a.out input01.txtIf you want to name the executable something else, use:gcc ListString.c -o ListString.exeand then run the program using:./ListString.exe input01.txtRunning the program could potentially dump a lot of output to the screen. If you want to redirect your output to a text file in Linux, its easy. Just run the program using the following:./ListString.exe input01.txt > whatever.txtThis will create a file called whatever.txt that contains the output from your program. Linux has a helpful command called diff for comparing the contents of two files, which is really helpful here since weve provided sample output files. You can see whether your output matches ours exactly by typing, e.g.:diff whatever.txt output01.txtIf the contents of whatever.txt and output01.txt are exactly the same, diff wont have any output.It will just look like this:[email protected]:~$ diff whatever.txt output01.txt[email protected]:~$ _If the files differ, it will spit out some information about the lines that arent the same. For example:[email protected]:~$ diff whatever.txt output01.txt3c3< riddlee> riddle[email protected]:~$ _6. Grading Criteria and Submission6.1. DeliverablesSubmit a single source file, named ListString.c, through [email protected] The source file should contain definitions for all the required functions (listed above), as well as any auxiliary functions you need to make them work. Dont forget to #include ListString.h in your source code. We will compile your program using:gcc ListString.cBe sure to include your name and PID as a comment at the top of your source file.6.2. Additional Restrictions: Use Linked Lists; Do Not Use Global VariablesYou must use linked lists to receive credit for this assignment. Also, please do not use global variables in this program. Doing so may result in a huge loss of points.6.3. GradingThe expected scoring breakdown for this programming assignment is:45% Correct Output for Test Cases45% Unit Testing (see details below)10% Comments and WhitespaceYour program must compile and run on Eustis to receive credit. Programs that do not compilewill receive an automatic zero.Your grade will be based primarily on your programs ability to compile and produce the exact output expected. Even minor deviations (such as capitalization, punctuation, or whitespace errors) in your output will cause your programs output to be marked as incorrect, resulting in severe point deductions.The same is true of how you name your functions and their parameters. Please be sure to follow all requirements carefully and test your program thoroughly.For this program, we will also be unit testing your code. That means we will devise tests that determine not only whether your programs overall output is correct, but also whether each function does exactly what it is required to do. So, for example, if your program produces correct output but your stringToList() function is simply a skeleton that returns NULL no matter what parameters you pass to it, your program will fail the unit tests.6.4. Closing RemarksStart early. Work hard. Ask questions. Good luck!

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Programming Assignment #3: Linked List Strings COP 3502
$25