Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I need help with this project that I am doing. It has to be in C language and I don't what to do. This

Hi I need help with this project that I am doing. It has to be in C language and I don't what to do. This is for my Data Structure course. Please it has to be in Language of C.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Programming Assignment #1: Irma Moves Spring 2021 Due: Sunday, February 7, before 11:59 PM 3 4 Table of Contents Programming Assignment #1: IrmaMoves. 1. Overview 2. Important Note: Test Case Files Look Wonky in Notepad. 3. Irma Moves.h The Move Struct. The Location Struct.. The Irma Struct.. 4. Function Requirements 5. Compilation and Testing (CodeBlocks) 6. Compilation and Testing (Linux/Mac Command Line) 7. Getting Started: A Guide for the Overwhelmed 9. Deliverables..... 10. Grading.. Appendix A: Irma Movement. Board Configuration. Denoting Positions on the Board Translating Board Positions to 2D Array Coordinates. Denoting Movement........ Examples 9 10 .12 12 13 13 13 13 14 15 Abstract In this programming assignment, you will implement an interpreter for algebraic notation for recording and describing the burricane Inna moves. In onder to finish this programri, you will need to learn a bit about how hurricane Irma can move on the map board, as well as how those moves are denoted with algebraic notation By completing this assignment, you will gain experience manipulating strinys, 2D arrays, structs, and struct pointers in C. You will also gain experience working with dynamic memory allocation and squashing memory lcaks. On the software engineering side of things, you will lcam to construct programs that use multiple source files and custom header (..) files. This assignment will also help you hone your ability to read technical specifications and implement a reasonably lengthy, non-trivial project with interconnected pieces. 1. Overview The algebraic notation has been used in a few different notation systems to denote the moves made in a game. In our game, we are going to predict the wind speed and wind gusts of hurricane Irina when it starts from a point and moves toward ils destination. The Irma's moves with its initial wind speed and wind gusts, and its destination is recorded as a series of strings that look something like this: h6 15010014 "h6" and "14" are the coordination of start and destination points in a board of 8x8 grid of squares, respectively, while the first integer number denotes the wind speed and the second inleger number denotes the wind gusts of Irma when it starts its movement. For this assignment, you will write a program that parses through a series of algchraic notation strings and prints out what the map board looks like at the end. To do this, you will first have to leam (or brush up on) how Irma moves (see Appendix A in this document). A complete list of the functions you must implement, including their functional prototypes, is given below in Section 4. "Function Requirements". You will submit a single source file named Imatovca.c, that contains all required function definitions, as well as any auxiliary functions you deem necessary. In lowMoves.s, you will have to finclude any beader files necessary for your functions to work, including the custom maoves.n file we have distributed with this assignment (sce Section 3. "Irma Moves.h"). Attachments Irma Moves.lt lesicase 01-05). testcasc{01-05).txt Note: You will not write a main() function in the source file you submit! Rather, we will compile your source file with our own main!) function(s) in order to test your code. We have attached cxample source files that have sair o functions, which you can use to test your code. You can write your own main functions for testing purposes, but the code you submit must not have a main function, We realize this is completely new territory for most of you, so don't panic. We've included instructions for compiling nuultiple source files into a single executable (e.g., mixing your Imamoves.c with our Inaoves. I and testoasexx.c files) in Sections 5 and 6 of this PDF Deliverables Irma Moves.c Although we have included test cases with simple main() functions to get you started with testing the functionality of your code, we encourage you to develop your own test cases, as well. Ours are by no means comprehensive. We will use much more elaborate test cases when grading your submission (Note! Capitalization and spelling of your filename matters!) (This project has been inspired and adopted from Sean Szumlanski's projects) 2. Important Note: Test Case Files Look Wonky in Notepad Included with this assignment are several test cases, along with output files showing exactly what your output should look like when you run those test cases. You will have to refer to those as the gold standard for bow your output should be formatted. Please note that if you open those files in Notepad. they will appear to be one long line of text. That's because Notepad handles end-of-line characters differently from Linux and Unix-based systems. One solution is to view those files in an IDE (like CodeBlocks), or you could use a different text exlitor like Alum or Sublime). 3. Irma Moves.h Some of these fields will be set by your surrenotationstzing!) function. Others cannot be set until you actually go to apply the move to the map board in your predictinaChange!) function, which will call a function to help determine which direction Irma should move. Included with this assignment is a customer header file that includes the struct definitions and functional prototypes for the functions you will be inplcnicnting. You should #include this file from your Imamoves.c filc, like so: The Location Struct #include "Tima Moves. The "quotes" (as opposed to brackets) indicate to the compiler that this header file is found in the same directory as your source, not a system directory. typedef struct Location { char coli // the square's column l'a' through 'h' int TOM // the square's row 10 through 11 1 Location: This struct holds locations on the map board, and is used by the Hove struct defined above. For information on how rows and columns are labeled on a map board, see "Appendix A: Irma Movement". The Irma Struct When working on this program, do not modify Trakoves in any way. Do not copy its struct definitions or functional prototypes into your Tema Hova.c file. Do not send Trnakoves.n to us when you submit your assignment. We will use our own unmodified copy of 1Moves.b when compiling your program. If you write auxiliary functions ("helper functions") in your Trakoveg.c file (which is strongly encouragedi!), you should not add those functional prototypes to Tomakeves, n. Our test case programs will not call your helper functions directly, so they do not need any awareness of the fact that your helper functions even exist. (We only list functional prototypes in a header file if we want multiple source files to be able to call those functions.) So, just put the functional prototypes for any helper functions you write at the top of your nativer.c file. typedef struct Irma 1 int wsi 17 wind speed (MPH) ) int ng // wind gusts (MPH) Ima; This struct holds the information of wind speed gusts of start point. Think of Irma Moves. b as a bridge between source files. It contains struct detinitions that might be used by multiple source files, as well as functional prototypes, but only for functions that might be defined in one source file (such as your TrraMovAS.c file) and called from a different source file (such as the testcasexx.- files we have provided with this assignment). There are three structs defined in Izmailoves.., which you will use to implcnicnt the required functions for this assigninent. They are as follows: 4. Function Requirements In the source file you submit, Ernataves., you must implement the following functions. You may implement auxiliary functions (helper functions) to make these work, as well. Please be sure the spelling, capitalization, and retum types of your functions match these prolotypes exactly The Move Struct In this section, I sometimes refer to nadlce () when talking about dynumic memory allocation, but you're welcome to use calloon or reallock instead, if you're familiar with those functions. typedef struot Move 1 Irma luna: // an instance of Irma L Location Eco_LOCH // location where I 18 moving from Location currere_Luc: // location where Irms is passing over Location to loc: // location where I 18 noviny to | Moves char **ccestepBoard (void); This struct will hold information about Imma moves. Your program will process a string of algebraic notation, such as "h6 150 100 f4", and when it does so, certain pieces of that string will be extracted, interpreted, and used to fill out certain fields in this struct. Description: Dynamically allocate space for a 2D char array with dimensions 8x8, and populate the array with the initial configuration of a map board as described in "Appendix A: Irma Movement" (and as shown in the test casc output files included with this assignment). Essentially, you have to bard code the initial map configuration based on the information given in Appendix A. As an example, after dynamically allocating space for map haard, you can use the following line of code to store proper letter in euch square of map board: atrncpy ihoard10). "FF The irma struct will hold the information of wind speed:gusts of start point. The fron_loc field will hold the location of Irnia whose movenient is being described (a columin and row on the map board; see struct definition below). The current oc field will hold the current location of Irma while moving from its start point to its destination. The to_loc field will hold the column and row of the location to which Irma is moving Output: This function should not print anything to the screen. Return Value: A pointer to the dynamically allocated 2D array(i.c., the base address of the 2D array), or NULL if any calls to mallocli fail. implemented in this function as described in "Appendix A: Inta Movement" char **dert yapboud(che board Description: Free all dynamically allocuted memory associated with board. You muy assume this function receives a dynamically allocated 2D char array with dimensions 8x8. Output: This should print out the map board in the manner described above, with precisely the Samne format shown in the test case output files included with this assignment. Return Value: A pointer to the dynamically allocated 2D array (i.c., the base address of the 2D array) or NULL if any calls to malloon Cail. Output: This function should not print anything to the screen. Return Value: This function must retur NILL. void parseNotatiorString(char* str, Move iraamvel; void pictMapboard chay **board): Description (and Output): This function takes a pointer to an 8x8 char array and prints the map board represented by that array using the format described below. This fornit is also shown explicitly in several of the test case output files included with this assignment, Description: This function receives an algebraic notation string sts, and one Move struct pointer. The function must purse str and extract information about Irma moves encoded there. and populate all corresponding fields in the struct pointed to by 1 zma:Hove. The printout of the map board should be preceded by a line of eight equal symbols (-), and it should also be followed by a line of eight symbols, followed by a blank line. For example: At the very least, it will always be possible to set the fron_loc, current_loc, to_los, and 1r.wa, 1.vg fields in Ira: struct. It is necessary to denote which column and or row the Imma's move is coming from, and also the column and/or row in a move's to_lve field which determine where Irma ends. To initialize rom loc, current 100, to 100 fields, you must initialize that move's from/current/to_loc.col fields to 'x' to indicate that the column is currently unknown. Similarly, the move's from current/t.o_loc.row coordinate must be initialized to -1 FE F X CCD DD After initialization update from_loc, current_100, to_1o, and irma.xs, irma.wg fields through extructing intonation from given algebraic notation string Output: This function should not print unything to the screen. : Return Value: There is no return value. This is a vota function. Note: This is a completely blank line. (No spaces. ) dieuble difficulty at angive id)) Return Value: There is no return value. This is a voia function, Output: This function should not print anything to the screen, . Return Value: A double indicating how difficult you found this assignment on a scale of 1.0 (ridiculously easy) through 5.0 (insanely difficult). char a predictione Charge char str, Hovernadove! double hoursSpant ivoid): Description: This function should start by printing the map board with Irma in its starting position, using the arrangement described in "Appendix A: Imma Movement" and the specific format shown in the test case output files included with this assignment. (You will want to call CresteHapoard() from within this function to create a 2D bay array to represent them board, and then call the printMapBourdt function to print it to the screen. Scc above for the descriptions of both of those functions.) Output: This function should not print anything to the screen. Return value: An estimate (greater than zero) of the number of hours you spent on this assignment After printing the initial map board, this function should parse all of the algebraic notation strinys passed in through making calls to the parselotationString function (described below). The printrapoardo function is called once after the Ima's location has been identified, and another time after the bourd's final configuration bas been processed. Note that this function should print the resulting board (again, with a line of eight equal signs above and below the board cach time, always followed by a blank line). In addition, updating Tema's wind speed gusts and checking Irma directions should he 5. Compilation and Testing (CodeBlocks) 6. Compilation and Testing (Linux/Mac Command Line) To compile multiple source files (.e files) at the comunand line: The key to getting multiple files to compile into a single program in CodeBlocks (or any IDE) is to create a project. Here are the step-by-step instructions for creating a project in CodeBlocks, which involves importing Trakova.n, testoaselll., and the Trovea.e file you've created (even if it's just an empty file so far). goc Irma Moves.c testcase01.c 1. Start CodeBlocks By default, this will produce an executable file called a cut, which you can run by typing: .fa.out 2. Create a New Project (file-> New -> Project). 3. Choose "Empty Project" and click "Go." If you want to name the executable file something else, use: 4. In the Project Wizard that opens, click "Next." goc Irma Movesc testcase01.C - Irma Moves.exe ...and then run the program using 5. Input a title for your project (c.g., "Ina Moves"). 6. Choose a folder (0.8., Desktop) where CodeBlocks can create a subdirectory for the project ./Irma Moves.exe 7. Click "Finish." Now you need to import your files. You have two options: 1. Drag your source and beader files into CodeBlocks. Then right click the tab for each file and choose "Add file to active project." Running the program could potentially dump a lot of output to the screen. If you want to rexdirect your output to a text file in Linux, it's casy. Just run the program using the following command, which will create a file called whatever.Ex: that contains the output from your program- ./Irma Moves.exe > whatever.bxt -or- Linux has a helpful command called d1 for comparing the contents of two files, which is really helpful here since we've provided several sample output files. You can see whether your output matches ours exactly by typing, c.g. 2. Go to Project -> Add Files.... Browse to the directory with the source and header files you want to import. Select the files from the list (using CTRL-click to select multiple tiles). Click "Open." In the dialog box that pops up, click OK." You should now he good to go. Try to build and run the project (F9), diff whatever.txt output01.txt If the contents of whatever.txt und output 01.tx= are exactly the same, die won't have any output. It will just look like this: navid@ubuntu:~$ diff whatever.txt outputo1.txt navid@ubuntu:$ Note that if you import both teetcaze0..c and testcase 12.-, the compiler will complain that you have multiple definitions for maint). You can only have one of those in there at a time. You'll have to swap them out as you test your code. Yes, constantly swapping out the test cases in your project will be a bit annoying. You can avoid this if you're willing to migrate away from an IDE and start compiling at the command line instead. If you're interested in doing that in Windows, please look around online for instructions on how to make that happen . If the files differ, it will spit out some information ubout the lines that aren't the same. For example: navid@ubuntu:$ diff whatever.txt outout01.txt Ici Hooray! navid@ubuntu:$ 7. Once you have your project compiling, go back to the list of required functions (Section 4. "Function Requirements"), and try to implement one function at a time. Always stop to compile and test your code before moving on to another function! 7. Getting Started: A Guide for the Overwhelmed Okay, so, this might all be overwhelming, and you might be thinking, "Where do leven start with this assignment?! I'm in way over my headl!" Don't panic! Here's my general advice on starting the assignment: 1. First and foremost, sturt working on this assignment early. Nothing will be more frustrating thun running into unexpected errors or not heing able to figure out what the assignment is asking you to do on the day that it is due. 2. Secondly, glance through this entire PDF to get a general overview of what the assignment is asking you to do, even if you don't fully understand each section right away, 3. Thirdly, before you even start programming, read through Appendices A lo familiarize yourself with the game of Ima prediction and the algebraic notation you'll be parsing in this assignment 4. Once you have an idea of bow algebraic notation works, open up the test cases and sample output files included with this assignment and trace through a few of them to be sure you have un accurate understanding of bow notation works. 8. You'll probably want to start with the cresteMap oordt: function. As you work on createMapRoard(!, write your own nain) function that calls createtapacard() and then chocks the results. For example, you'll want to ensure that create aproad() is returning a non-NULL pointer to begin with, and that each index in the array it returns is DOU-NULL as well. Then try printing out the board. Finally, look through the text cases provided with this assignment to find one that calls createMapboard() explicitly. Run it and check that your output is correct. If not, go through your code (as well as the test case code) lide-by-line, and see if you can find out why your output isn't matching 9. After writing createMapled(), I would probably work on the destroyMap:Beard) und printkapBoard functions, because they're so closely related. This might require that you spend some time reviewing the course notes on 2D array allocation. 10. Next, I would work on the parsetringactatior) function. This one will be quite lengthy. Start hy writing your own nain) that passes simple strings to parsestringNotation), Check that the results it produces are correct. Then start passing more conplex strings. If you need guidance on how to call this function and determine whether it's producing the correct results, look for a test case that calls paraestringetation, and check whether your progrum produces the correct output with that test cusc. If not, trace through it by hand. 11. If you get stuck while working on this assignment, draw diagrams on paper or a whiteboard. Make boxes for all the variables in your program. If you're dynamically allocating memory, diagrain them out and take up actresses for all your variables. Trace through your code carefully using these diagrams. S. Once you're ready to begin coding, start by creating a skeleton Irmakovaa.c filc. Add a header comment, add some standard Airelude directives, and be sure to include "Izmavesh from your source file. Then copy and paste cach functional prototype from Im Moves.b into Imamoves., and set up all those functions telur dummy values (either NIITT, or nothing at all, as appropriate) 6. Test that your Tralovea.c source file compiles. If you're at the command line on a Mac or in Linux, your source file will need to be in the same directory as Izau/ves.b. and you can test compilation like so: goc-c IrmaMoves.c 12. With so many pointers, you're bound to encounter errors in your code at some point. Use printed statements liberally to verify that your code is producing the results you think it should be producing (rather than making assumptions that certain components are working as intended). You should get in the habit of being immensely skeptical of your own code and using printed to provide yourself with evidence that your code does what you think it does. Alternatively, you can try compiling it with one of the test case source files, like so: goc ImmaMoves.c testcase01.c 13. When looking for a segmentation fault, you sbould always be able to use printe (to track down the exact line you're crashing on 14. You'll need to examine a lot of debugging output. Just be sure to remove your debugging statements before you submit your assignment, so your code is nice and clean and casy for me to read. For more details, see Section 6, "Compilation and Testing (Linux/ Mac Command Line)." If you're using an IDE (ie, you're coding with something other than a plain text editor and the command line), open up your IDE and start a project using the instructions ahove in Section 5, "Compilation and Testing (CodeBlocks). Import Irmakovca.I., teateasca1.c, and your new Istoves.e source file, and get the program compiling and running before you move forward. (Note that CodeBlocks is the only IDE we officially support in this class.) 15. When you find a bug, or if your program is crashing on a huge test case, don't trace through hundreds of lines of code to track down the error. Instead, try to cook up a new nain function with a very small test case (as few lines as possible) that directly calls the function that's crashing. The less code you have to trace through the easier your debugging tasks will be Adapted from Sean Szumlanski 9. Deliverables Appendix A: Irma Movement Submit a single source file, burned Irratoves.c, via Canvus. The source file should contuin definitions for all the required functions (listed above), as well as any auxiliary fanctions you need to make them work Your source file must not contain a main() function. Do not submit additional source files, and do not submit a modified Isleves. header file. Your source file (without a nain function) should compile at the command line using the following command: This appendix describes how each Irina moves on the map. First, however, we give a very brief overview of the game and describe the initial configuration of the bourd. Board Configuration The board is an 8x8 grid of squares, where either a letter is stored on the square or a space character. Esseptially, the location of selective countries, islands, and cities have been shown on the map. In Figure I, the hasic board configuration has heen shown. F 1 GCC-cirma Moves.c 0 F It must also compile at the comniand line if you place it in a directory with enakoves.t. and a test case file (for example, teat.casi01.c) and compile like so: 2 F F 3 3 F gcrc: immaMoves.c testcase01.c 4 4 K Be sure to include your name and ID as a comment at the top of your source file S B 6 C D 10. Grading The tentative scoring breakdown (not set in stone) for this programming assignment is: h 7 D D c d e f g h Figure 1. The initial configuration of un 88 Icard representing Florida pewins and neighbor island. Denoting Positions on the Board 40% 35% 5% 5% 5% 10% correct output for test cases implementation details (manual inspection of your code) difficultyReting t) is implemented correctly hoursSpen: 11 is implemented correctly source file is named correctly (Imamoves.c); spelling and capitalization count adequate comments and whitespace; source includes student name und ID To understand algebruic notation, one must first understund how to refer to a specific square on an 8x8 board. The colurns on a board are labeled a through h, from left to right. The rows are labeled 0 through 7 from top to botton, where the bottom rows (rows 7 and 6) arc where Dominican Republic country has been represented, and the top rows (rows through ?) are where the Florida state has been shown. Note! Your program must be submitted via Canvas, and it must compile and run to receive credit. Progrums that do not compile will receive an automatic zero Your grude will be based largely on your program's ability to compile and produce the exact output cxpected. Even minor deviations (such as capitalization or punctuation errors) in your output will cause your program's output to be marked is incorrect, resulting in severe point deductions. The same is true of bow you name your functions and their perimeters. Please be sure to follow all requirements carefully and test your program thoroughly Coordinates for a particular square in this notation system are given us Columnow, with no space in between is a single letter from 'a' through 'h', denoting which column the hurricane Irma is in, and to 113mpk (110 - 3). Finally, Irmo moves to north one more time to get to W. Since there is no Landon /5 and ima's movement is vertically. Ime's win speelgoes up to 12mph (1 76 + 6), and its wind grus sves up to Imph (3-3) The direction of Irma movement follows the below rules: . First, Irma starts its movement from the given start point toward either east (left) or west (right) depending on the destination coordination. While Irma horizontally passes over either occan or land (which have been identified with letters in our map board), its wind speed and wind gusts changer as follows: If it horizontally passes Over ocean, its wind speed and wind gusts will go up as follows: Irma Wind Speed +-10; Irma. Wind Guests += 5; Before Move: After Move: 2 3 0 FF 1 F 1 1 F 2 F F F F 3 F F 4 K 4 K 5 C BA 5c BI 6 | D 6 cc D 7 DD 7 DD a b c d e f g h a b c d e f g h Example 2: "h7 110 100e5" denotes that Irma moves from h7 to e5. Irma starts its movement with wind speed and wind gusts of 110 mph and 100 mph, respectively at h7. Note that Irma should move to west to get to e7 first, then it can move to north to get to its destination. When Irma moves to g7, our game checks that whether Irma hits the land or not. Since there it hits land on g7, Irma's wind speed goes down to 95mph (110 - 15), and its wind gusts goes down to 90mph (100 - 10). Next, Irma moves to west one more time to get to e7. Since there it hits land on f7, Irma's wind speed goes down to 80mph (95 - 15), and its wind gusts goes down to 80mph (90 - 10). Next, Irma moves to west one more time to get to e7. Since there is no land on el, Irma's wind speed goes up to 90mph (80 + 10), and its wind gusts goes up to 85mph (80 + 5). Next, Irma moves to north to get to e5. The first square that Irma passes over in our example is e6. Again, when Irma moves to eb, our game checks that whether Irma hits the land or not. Since it hits land on eb and Irma's movement is vertically now, Irma's wind speed goes down to 88mph (90 - 2), and its wind gusts goes down to 84mph (85 - 1). Finally, Irma moves to north one more time to get to e5. Since there is no land on e5 and Irma's movement is vertically, Irma's wind speed goes up to 94mph (88 + 6), and its wind gusts goes up to 87mph (84 + 3). Programming Assignment #1: Irma Moves Spring 2021 Due: Sunday, February 7, before 11:59 PM 3 4 Table of Contents Programming Assignment #1: IrmaMoves. 1. Overview 2. Important Note: Test Case Files Look Wonky in Notepad. 3. Irma Moves.h The Move Struct. The Location Struct.. The Irma Struct.. 4. Function Requirements 5. Compilation and Testing (CodeBlocks) 6. Compilation and Testing (Linux/Mac Command Line) 7. Getting Started: A Guide for the Overwhelmed 9. Deliverables..... 10. Grading.. Appendix A: Irma Movement. Board Configuration. Denoting Positions on the Board Translating Board Positions to 2D Array Coordinates. Denoting Movement........ Examples 9 10 .12 12 13 13 13 13 14 15 Abstract In this programming assignment, you will implement an interpreter for algebraic notation for recording and describing the burricane Inna moves. In onder to finish this programri, you will need to learn a bit about how hurricane Irma can move on the map board, as well as how those moves are denoted with algebraic notation By completing this assignment, you will gain experience manipulating strinys, 2D arrays, structs, and struct pointers in C. You will also gain experience working with dynamic memory allocation and squashing memory lcaks. On the software engineering side of things, you will lcam to construct programs that use multiple source files and custom header (..) files. This assignment will also help you hone your ability to read technical specifications and implement a reasonably lengthy, non-trivial project with interconnected pieces. 1. Overview The algebraic notation has been used in a few different notation systems to denote the moves made in a game. In our game, we are going to predict the wind speed and wind gusts of hurricane Irina when it starts from a point and moves toward ils destination. The Irma's moves with its initial wind speed and wind gusts, and its destination is recorded as a series of strings that look something like this: h6 15010014 "h6" and "14" are the coordination of start and destination points in a board of 8x8 grid of squares, respectively, while the first integer number denotes the wind speed and the second inleger number denotes the wind gusts of Irma when it starts its movement. For this assignment, you will write a program that parses through a series of algchraic notation strings and prints out what the map board looks like at the end. To do this, you will first have to leam (or brush up on) how Irma moves (see Appendix A in this document). A complete list of the functions you must implement, including their functional prototypes, is given below in Section 4. "Function Requirements". You will submit a single source file named Imatovca.c, that contains all required function definitions, as well as any auxiliary functions you deem necessary. In lowMoves.s, you will have to finclude any beader files necessary for your functions to work, including the custom maoves.n file we have distributed with this assignment (sce Section 3. "Irma Moves.h"). Attachments Irma Moves.lt lesicase 01-05). testcasc{01-05).txt Note: You will not write a main() function in the source file you submit! Rather, we will compile your source file with our own main!) function(s) in order to test your code. We have attached cxample source files that have sair o functions, which you can use to test your code. You can write your own main functions for testing purposes, but the code you submit must not have a main function, We realize this is completely new territory for most of you, so don't panic. We've included instructions for compiling nuultiple source files into a single executable (e.g., mixing your Imamoves.c with our Inaoves. I and testoasexx.c files) in Sections 5 and 6 of this PDF Deliverables Irma Moves.c Although we have included test cases with simple main() functions to get you started with testing the functionality of your code, we encourage you to develop your own test cases, as well. Ours are by no means comprehensive. We will use much more elaborate test cases when grading your submission (Note! Capitalization and spelling of your filename matters!) (This project has been inspired and adopted from Sean Szumlanski's projects) 2. Important Note: Test Case Files Look Wonky in Notepad Included with this assignment are several test cases, along with output files showing exactly what your output should look like when you run those test cases. You will have to refer to those as the gold standard for bow your output should be formatted. Please note that if you open those files in Notepad. they will appear to be one long line of text. That's because Notepad handles end-of-line characters differently from Linux and Unix-based systems. One solution is to view those files in an IDE (like CodeBlocks), or you could use a different text exlitor like Alum or Sublime). 3. Irma Moves.h Some of these fields will be set by your surrenotationstzing!) function. Others cannot be set until you actually go to apply the move to the map board in your predictinaChange!) function, which will call a function to help determine which direction Irma should move. Included with this assignment is a customer header file that includes the struct definitions and functional prototypes for the functions you will be inplcnicnting. You should #include this file from your Imamoves.c filc, like so: The Location Struct #include "Tima Moves. The "quotes" (as opposed to brackets) indicate to the compiler that this header file is found in the same directory as your source, not a system directory. typedef struct Location { char coli // the square's column l'a' through 'h' int TOM // the square's row 10 through 11 1 Location: This struct holds locations on the map board, and is used by the Hove struct defined above. For information on how rows and columns are labeled on a map board, see "Appendix A: Irma Movement". The Irma Struct When working on this program, do not modify Trakoves in any way. Do not copy its struct definitions or functional prototypes into your Tema Hova.c file. Do not send Trnakoves.n to us when you submit your assignment. We will use our own unmodified copy of 1Moves.b when compiling your program. If you write auxiliary functions ("helper functions") in your Trakoveg.c file (which is strongly encouragedi!), you should not add those functional prototypes to Tomakeves, n. Our test case programs will not call your helper functions directly, so they do not need any awareness of the fact that your helper functions even exist. (We only list functional prototypes in a header file if we want multiple source files to be able to call those functions.) So, just put the functional prototypes for any helper functions you write at the top of your nativer.c file. typedef struct Irma 1 int wsi 17 wind speed (MPH) ) int ng // wind gusts (MPH) Ima; This struct holds the information of wind speed gusts of start point. Think of Irma Moves. b as a bridge between source files. It contains struct detinitions that might be used by multiple source files, as well as functional prototypes, but only for functions that might be defined in one source file (such as your TrraMovAS.c file) and called from a different source file (such as the testcasexx.- files we have provided with this assignment). There are three structs defined in Izmailoves.., which you will use to implcnicnt the required functions for this assigninent. They are as follows: 4. Function Requirements In the source file you submit, Ernataves., you must implement the following functions. You may implement auxiliary functions (helper functions) to make these work, as well. Please be sure the spelling, capitalization, and retum types of your functions match these prolotypes exactly The Move Struct In this section, I sometimes refer to nadlce () when talking about dynumic memory allocation, but you're welcome to use calloon or reallock instead, if you're familiar with those functions. typedef struot Move 1 Irma luna: // an instance of Irma L Location Eco_LOCH // location where I 18 moving from Location currere_Luc: // location where Irms is passing over Location to loc: // location where I 18 noviny to | Moves char **ccestepBoard (void); This struct will hold information about Imma moves. Your program will process a string of algebraic notation, such as "h6 150 100 f4", and when it does so, certain pieces of that string will be extracted, interpreted, and used to fill out certain fields in this struct. Description: Dynamically allocate space for a 2D char array with dimensions 8x8, and populate the array with the initial configuration of a map board as described in "Appendix A: Irma Movement" (and as shown in the test casc output files included with this assignment). Essentially, you have to bard code the initial map configuration based on the information given in Appendix A. As an example, after dynamically allocating space for map haard, you can use the following line of code to store proper letter in euch square of map board: atrncpy ihoard10). "FF The irma struct will hold the information of wind speed:gusts of start point. The fron_loc field will hold the location of Irnia whose movenient is being described (a columin and row on the map board; see struct definition below). The current oc field will hold the current location of Irma while moving from its start point to its destination. The to_loc field will hold the column and row of the location to which Irma is moving Output: This function should not print anything to the screen. Return Value: A pointer to the dynamically allocated 2D array(i.c., the base address of the 2D array), or NULL if any calls to mallocli fail. implemented in this function as described in "Appendix A: Inta Movement" char **dert yapboud(che board Description: Free all dynamically allocuted memory associated with board. You muy assume this function receives a dynamically allocated 2D char array with dimensions 8x8. Output: This should print out the map board in the manner described above, with precisely the Samne format shown in the test case output files included with this assignment. Return Value: A pointer to the dynamically allocated 2D array (i.c., the base address of the 2D array) or NULL if any calls to malloon Cail. Output: This function should not print anything to the screen. Return Value: This function must retur NILL. void parseNotatiorString(char* str, Move iraamvel; void pictMapboard chay **board): Description (and Output): This function takes a pointer to an 8x8 char array and prints the map board represented by that array using the format described below. This fornit is also shown explicitly in several of the test case output files included with this assignment, Description: This function receives an algebraic notation string sts, and one Move struct pointer. The function must purse str and extract information about Irma moves encoded there. and populate all corresponding fields in the struct pointed to by 1 zma:Hove. The printout of the map board should be preceded by a line of eight equal symbols (-), and it should also be followed by a line of eight symbols, followed by a blank line. For example: At the very least, it will always be possible to set the fron_loc, current_loc, to_los, and 1r.wa, 1.vg fields in Ira: struct. It is necessary to denote which column and or row the Imma's move is coming from, and also the column and/or row in a move's to_lve field which determine where Irma ends. To initialize rom loc, current 100, to 100 fields, you must initialize that move's from/current/to_loc.col fields to 'x' to indicate that the column is currently unknown. Similarly, the move's from current/t.o_loc.row coordinate must be initialized to -1 FE F X CCD DD After initialization update from_loc, current_100, to_1o, and irma.xs, irma.wg fields through extructing intonation from given algebraic notation string Output: This function should not print unything to the screen. : Return Value: There is no return value. This is a vota function. Note: This is a completely blank line. (No spaces. ) dieuble difficulty at angive id)) Return Value: There is no return value. This is a voia function, Output: This function should not print anything to the screen, . Return Value: A double indicating how difficult you found this assignment on a scale of 1.0 (ridiculously easy) through 5.0 (insanely difficult). char a predictione Charge char str, Hovernadove! double hoursSpant ivoid): Description: This function should start by printing the map board with Irma in its starting position, using the arrangement described in "Appendix A: Imma Movement" and the specific format shown in the test case output files included with this assignment. (You will want to call CresteHapoard() from within this function to create a 2D bay array to represent them board, and then call the printMapBourdt function to print it to the screen. Scc above for the descriptions of both of those functions.) Output: This function should not print anything to the screen. Return value: An estimate (greater than zero) of the number of hours you spent on this assignment After printing the initial map board, this function should parse all of the algebraic notation strinys passed in through making calls to the parselotationString function (described below). The printrapoardo function is called once after the Ima's location has been identified, and another time after the bourd's final configuration bas been processed. Note that this function should print the resulting board (again, with a line of eight equal signs above and below the board cach time, always followed by a blank line). In addition, updating Tema's wind speed gusts and checking Irma directions should he 5. Compilation and Testing (CodeBlocks) 6. Compilation and Testing (Linux/Mac Command Line) To compile multiple source files (.e files) at the comunand line: The key to getting multiple files to compile into a single program in CodeBlocks (or any IDE) is to create a project. Here are the step-by-step instructions for creating a project in CodeBlocks, which involves importing Trakova.n, testoaselll., and the Trovea.e file you've created (even if it's just an empty file so far). goc Irma Moves.c testcase01.c 1. Start CodeBlocks By default, this will produce an executable file called a cut, which you can run by typing: .fa.out 2. Create a New Project (file-> New -> Project). 3. Choose "Empty Project" and click "Go." If you want to name the executable file something else, use: 4. In the Project Wizard that opens, click "Next." goc Irma Movesc testcase01.C - Irma Moves.exe ...and then run the program using 5. Input a title for your project (c.g., "Ina Moves"). 6. Choose a folder (0.8., Desktop) where CodeBlocks can create a subdirectory for the project ./Irma Moves.exe 7. Click "Finish." Now you need to import your files. You have two options: 1. Drag your source and beader files into CodeBlocks. Then right click the tab for each file and choose "Add file to active project." Running the program could potentially dump a lot of output to the screen. If you want to rexdirect your output to a text file in Linux, it's casy. Just run the program using the following command, which will create a file called whatever.Ex: that contains the output from your program- ./Irma Moves.exe > whatever.bxt -or- Linux has a helpful command called d1 for comparing the contents of two files, which is really helpful here since we've provided several sample output files. You can see whether your output matches ours exactly by typing, c.g. 2. Go to Project -> Add Files.... Browse to the directory with the source and header files you want to import. Select the files from the list (using CTRL-click to select multiple tiles). Click "Open." In the dialog box that pops up, click OK." You should now he good to go. Try to build and run the project (F9), diff whatever.txt output01.txt If the contents of whatever.txt und output 01.tx= are exactly the same, die won't have any output. It will just look like this: navid@ubuntu:~$ diff whatever.txt outputo1.txt navid@ubuntu:$ Note that if you import both teetcaze0..c and testcase 12.-, the compiler will complain that you have multiple definitions for maint). You can only have one of those in there at a time. You'll have to swap them out as you test your code. Yes, constantly swapping out the test cases in your project will be a bit annoying. You can avoid this if you're willing to migrate away from an IDE and start compiling at the command line instead. If you're interested in doing that in Windows, please look around online for instructions on how to make that happen . If the files differ, it will spit out some information ubout the lines that aren't the same. For example: navid@ubuntu:$ diff whatever.txt outout01.txt Ici Hooray! navid@ubuntu:$ 7. Once you have your project compiling, go back to the list of required functions (Section 4. "Function Requirements"), and try to implement one function at a time. Always stop to compile and test your code before moving on to another function! 7. Getting Started: A Guide for the Overwhelmed Okay, so, this might all be overwhelming, and you might be thinking, "Where do leven start with this assignment?! I'm in way over my headl!" Don't panic! Here's my general advice on starting the assignment: 1. First and foremost, sturt working on this assignment early. Nothing will be more frustrating thun running into unexpected errors or not heing able to figure out what the assignment is asking you to do on the day that it is due. 2. Secondly, glance through this entire PDF to get a general overview of what the assignment is asking you to do, even if you don't fully understand each section right away, 3. Thirdly, before you even start programming, read through Appendices A lo familiarize yourself with the game of Ima prediction and the algebraic notation you'll be parsing in this assignment 4. Once you have an idea of bow algebraic notation works, open up the test cases and sample output files included with this assignment and trace through a few of them to be sure you have un accurate understanding of bow notation works. 8. You'll probably want to start with the cresteMap oordt: function. As you work on createMapRoard(!, write your own nain) function that calls createtapacard() and then chocks the results. For example, you'll want to ensure that create aproad() is returning a non-NULL pointer to begin with, and that each index in the array it returns is DOU-NULL as well. Then try printing out the board. Finally, look through the text cases provided with this assignment to find one that calls createMapboard() explicitly. Run it and check that your output is correct. If not, go through your code (as well as the test case code) lide-by-line, and see if you can find out why your output isn't matching 9. After writing createMapled(), I would probably work on the destroyMap:Beard) und printkapBoard functions, because they're so closely related. This might require that you spend some time reviewing the course notes on 2D array allocation. 10. Next, I would work on the parsetringactatior) function. This one will be quite lengthy. Start hy writing your own nain) that passes simple strings to parsestringNotation), Check that the results it produces are correct. Then start passing more conplex strings. If you need guidance on how to call this function and determine whether it's producing the correct results, look for a test case that calls paraestringetation, and check whether your progrum produces the correct output with that test cusc. If not, trace through it by hand. 11. If you get stuck while working on this assignment, draw diagrams on paper or a whiteboard. Make boxes for all the variables in your program. If you're dynamically allocating memory, diagrain them out and take up actresses for all your variables. Trace through your code carefully using these diagrams. S. Once you're ready to begin coding, start by creating a skeleton Irmakovaa.c filc. Add a header comment, add some standard Airelude directives, and be sure to include "Izmavesh from your source file. Then copy and paste cach functional prototype from Im Moves.b into Imamoves., and set up all those functions telur dummy values (either NIITT, or nothing at all, as appropriate) 6. Test that your Tralovea.c source file compiles. If you're at the command line on a Mac or in Linux, your source file will need to be in the same directory as Izau/ves.b. and you can test compilation like so: goc-c IrmaMoves.c 12. With so many pointers, you're bound to encounter errors in your code at some point. Use printed statements liberally to verify that your code is producing the results you think it should be producing (rather than making assumptions that certain components are working as intended). You should get in the habit of being immensely skeptical of your own code and using printed to provide yourself with evidence that your code does what you think it does. Alternatively, you can try compiling it with one of the test case source files, like so: goc ImmaMoves.c testcase01.c 13. When looking for a segmentation fault, you sbould always be able to use printe (to track down the exact line you're crashing on 14. You'll need to examine a lot of debugging output. Just be sure to remove your debugging statements before you submit your assignment, so your code is nice and clean and casy for me to read. For more details, see Section 6, "Compilation and Testing (Linux/ Mac Command Line)." If you're using an IDE (ie, you're coding with something other than a plain text editor and the command line), open up your IDE and start a project using the instructions ahove in Section 5, "Compilation and Testing (CodeBlocks). Import Irmakovca.I., teateasca1.c, and your new Istoves.e source file, and get the program compiling and running before you move forward. (Note that CodeBlocks is the only IDE we officially support in this class.) 15. When you find a bug, or if your program is crashing on a huge test case, don't trace through hundreds of lines of code to track down the error. Instead, try to cook up a new nain function with a very small test case (as few lines as possible) that directly calls the function that's crashing. The less code you have to trace through the easier your debugging tasks will be Adapted from Sean Szumlanski 9. Deliverables Appendix A: Irma Movement Submit a single source file, burned Irratoves.c, via Canvus. The source file should contuin definitions for all the required functions (listed above), as well as any auxiliary fanctions you need to make them work Your source file must not contain a main() function. Do not submit additional source files, and do not submit a modified Isleves. header file. Your source file (without a nain function) should compile at the command line using the following command: This appendix describes how each Irina moves on the map. First, however, we give a very brief overview of the game and describe the initial configuration of the bourd. Board Configuration The board is an 8x8 grid of squares, where either a letter is stored on the square or a space character. Esseptially, the location of selective countries, islands, and cities have been shown on the map. In Figure I, the hasic board configuration has heen shown. F 1 GCC-cirma Moves.c 0 F It must also compile at the comniand line if you place it in a directory with enakoves.t. and a test case file (for example, teat.casi01.c) and compile like so: 2 F F 3 3 F gcrc: immaMoves.c testcase01.c 4 4 K Be sure to include your name and ID as a comment at the top of your source file S B 6 C D 10. Grading The tentative scoring breakdown (not set in stone) for this programming assignment is: h 7 D D c d e f g h Figure 1. The initial configuration of un 88 Icard representing Florida pewins and neighbor island. Denoting Positions on the Board 40% 35% 5% 5% 5% 10% correct output for test cases implementation details (manual inspection of your code) difficultyReting t) is implemented correctly hoursSpen: 11 is implemented correctly source file is named correctly (Imamoves.c); spelling and capitalization count adequate comments and whitespace; source includes student name und ID To understand algebruic notation, one must first understund how to refer to a specific square on an 8x8 board. The colurns on a board are labeled a through h, from left to right. The rows are labeled 0 through 7 from top to botton, where the bottom rows (rows 7 and 6) arc where Dominican Republic country has been represented, and the top rows (rows through ?) are where the Florida state has been shown. Note! Your program must be submitted via Canvas, and it must compile and run to receive credit. Progrums that do not compile will receive an automatic zero Your grude will be based largely on your program's ability to compile and produce the exact output cxpected. Even minor deviations (such as capitalization or punctuation errors) in your output will cause your program's output to be marked is incorrect, resulting in severe point deductions. The same is true of bow you name your functions and their perimeters. Please be sure to follow all requirements carefully and test your program thoroughly Coordinates for a particular square in this notation system are given us Columnow, with no space in between is a single letter from 'a' through 'h', denoting which column the hurricane Irma is in, and to 113mpk (110 - 3). Finally, Irmo moves to north one more time to get to W. Since there is no Landon /5 and ima's movement is vertically. Ime's win speelgoes up to 12mph (1 76 + 6), and its wind grus sves up to Imph (3-3) The direction of Irma movement follows the below rules: . First, Irma starts its movement from the given start point toward either east (left) or west (right) depending on the destination coordination. While Irma horizontally passes over either occan or land (which have been identified with letters in our map board), its wind speed and wind gusts changer as follows: If it horizontally passes Over ocean, its wind speed and wind gusts will go up as follows: Irma Wind Speed +-10; Irma. Wind Guests += 5; Before Move: After Move: 2 3 0 FF 1 F 1 1 F 2 F F F F 3 F F 4 K 4 K 5 C BA 5c BI 6 | D 6 cc D 7 DD 7 DD a b c d e f g h a b c d e f g h Example 2: "h7 110 100e5" denotes that Irma moves from h7 to e5. Irma starts its movement with wind speed and wind gusts of 110 mph and 100 mph, respectively at h7. Note that Irma should move to west to get to e7 first, then it can move to north to get to its destination. When Irma moves to g7, our game checks that whether Irma hits the land or not. Since there it hits land on g7, Irma's wind speed goes down to 95mph (110 - 15), and its wind gusts goes down to 90mph (100 - 10). Next, Irma moves to west one more time to get to e7. Since there it hits land on f7, Irma's wind speed goes down to 80mph (95 - 15)

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

Students also viewed these Databases questions