Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * * * CSC A 4 8 - Intro to Computer Science II * * This is the program file where you will implement
CSC A Intro to Computer Science II
This is the program file where you will implement your solution for
assignment 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 CSCA
c Mustafa Quraish
#include "imgUtils.c
This lets the driver code override the image size if it needs to Make sure
you don't hardcode these values anywhere!
#ifndef SIZEX
#define SIZEX
#define SIZEY
#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 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
char cmd;
int val;
struct cmdnode next;
CmdNode;
CmdNode newCmdNodechar cmd 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.
ifstrcmpcmd "backward"strcmpcmd "forward"strcmpcmd "pendown"
strcmpcmd "colour"strcmpcmd "penup"strcmpcmd "right"strcmpcmd "left"
CmdNode new CmdNodecalloc sizeofCmdNode;
strcpynewcmd cmd;
new val val;
new next NULL;
return new;
printfInvalid command.
;
return NULL;
void printCommandListCmdNode 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"
printfd: s d
; With a value
printfd: 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.
ifhead NULL
return;
CmdNode p head;
forint i ; p NULL; p pnext, i
ifstrcmppcmd"penup" strcmppcmd"pendown"
printfd: s
i pcmd;
else
printfd: s d
i pcmd pval;
TODO
void queryByCommandCmdNode head char cmd
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
: penup
: forward
: right
: forward
Then, if this function is called with the same list and cmd "forward",
then your output here should be
: forward
: forward
TODO: Implement this function
return;
int coun
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started