Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program language is C Sorry there is a lot of text most of it is just explaining what is needed to be coded and

The program language is C

Sorry there is a lot of text most of it is just explaining what is needed to be coded and setup to help with coding

//Code starts here

#include #include #include

/** * 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 * ****/

typedef struct cmdnode { char cmd[10]; int val; struct cmdnode *next; } 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

* Proper commands are as follows...

*penup, pendown, colour, forward, backward, left, right */ 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. *

* The commands are the same as the previous function (penup, pendown, colour, forward, backward, left, right) * 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 *

* * The commands are the same as the previous function (penup, pendown, colour, forward, backward, left, right) * TODO: Implement this function */

return; }

//End of Code

I did not include a main function as this is part of some other files that have the main function

Do NOT include any other c libraries

Do NOT use any built in functions other than ones that are related to searching and manipulating strings such as strcpy() and strcmp()

Thank you :)

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

What is the correlation between EXPERIENCE and PERFORMANCE RATING?

Answered: 1 week ago

Question

Write messages that build relationships and networks

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago