Question: C language. please implement following three functions correctly after constructing the data. /** * CSC A48 - Intro to Computer Science II, Summer 2020 *
C language. please implement following three functions correctly after constructing the data.
/** * CSC A48 - Intro to Computer Science II, Summer 2020 * * This is the program file where you will implement your solution for * assignment 1. Please make sure you read through this file carefully * and that you understand what is provided and what you need to complete. * * You will need to have read the handout carefully. Parts where you have to * implement functionality are clearly labeled TODO. * * Be sure to test your work thoroughly, our testing will be extensive and will * check that your solution is *correct*, not only that it provides * functionality. * * Developed by Mustafa Quraish for CSCA48 * (c) Mustafa Quraish 2020 */ #include "imgUtils.c"
// This lets the driver code override the image size if it needs to. Make sure // you don't hard-code these values anywhere! #ifndef SIZEX #define SIZEX 512 #define SIZEY 512 #endif
/*---------------------------------------------------------------------------*/
/** * This struct contains one node of the linked list, which represents a single * command to the Turtle. It's field should include: * * - cmd : A char array of size 10 holding the command name * * - val : An integer that stores a parameter for the command (like forward, * backward and colour). * * - next : A pointer to a struct of the same type, this is used for the * linked list * * TODO: Complete this struct definition ****/
typedef struct cmdnode {
} CmdNode;
/*---------------------------------------------------------------------------*/
CmdNode *newCmdNode(char cmd[10], int val) { /** * This function allocates a new CmdNode struct and initializes it's values * based on the input paramaters given. The next pointer is always * initialized to NULL. * * If the 'cmd' parameter is not a correct command, then print * "Invalid command. " and return NULL. * * Note that we will always pass in a value here, even if the * command doesn't need one. In this case, we can just ignore * it. It saves us from having to make separate functions to * deal with this. * * TODO: Implement this function */
return NULL; }
/*---------------------------------------------------------------------------*/
void printCommandList(CmdNode *head) { /** * This function prints out each command in the linked list one after the * other. Each command MUST also have a line number printed before it, this * is what you will be using to modify / delete them. To do this, initialize * a counter and then increment it for each command. * * Depending on whether or not the command needs an additional value * (like forward, backward and colour), use one of the following statements * to print out the information for each node: * [ The format is "linenumber: command value" ] * * printf("%3d: %s %d ", ... ); [With a value] * * printf("%3d: %s ", ... ); [Without a value] * * Obviously, you also need to pass in the correct parameters to the print * function yourself, this is just so you have the correct format. * * TODO: Implement this function */
return; }
/*---------------------------------------------------------------------------*/
void queryByCommand(CmdNode *head, char cmd[10]) { /** * This function looks for commands in the linked list that match the input * query. It prints them out in the same format as the printCommandList() * function. * * Make sure that the line number of the commands that match is the same as * the line number that would be printed by the printCommandList() function. * * -------------------------------------------------------------------------- * * For instance, if your printCommandList function outputs * * 0: penup * 1: forward 200 * 2: right * 3: forward 50 * * Then, if this function is called with the same list and cmd = "forward", * then your output here should be * * 1: forward 200 * 3: forward 50 * * TODO: Implement this function */
return; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
