This is about nested loop generation at run time. At run time you will be reading lines each of which define a loop variable (which is a single letter), a start value integer, an end value integer and a step size integer. The first line is the outermost loop and the last line is the inner most.
The nested loops will function as you would expect and after every innermost loop change a function with the name executed() will be called. executed() is a function that will be provided at evaluation-time by us (the evaluators).
So, you will let the compiler know about it by including a header file we provide as addendum to this the description. Here is a possible input (a very simple one):
X 10 18 3 r -3 2 1 Y 0 -2 -1
The oute rmost loop is defined in the first line. X will go through the values 10,13,16. For each value of X, r will go through the values -3,-2,-1,0,1,2. The inner most loop is the last line. Y will go through the values 0,-1,-2. So,unlessanalternationtakesplace(whatthismeanswillbeexplainedbelow),loop execute() will be called 3×6×3 = 54 times.
executed() will have access to the values of the so called loop variables. For this purpose a function that you will name as value() and implement will serve. For example value(’r’) will return the current value of the loop variable ’r’ (considering the example given above).
Now comes a tough part: It will also be possible to continue with the next value of any loop variable. In that case, as expected, all inner loops will be reset to start. For this purpose a function that you will name as contin() and implement will serve. Similar value(), contin() will also take a variable letter as argument. So, if the variables are at X:10, r:-2, Y:-1 and inside executed() a call to contin(’r’) is performed then the next executed() will see X:10, r:-1, Y:0.
SPECIFICATIONS
. • Sinceyourprogramsaregradedusingsomeautomatedi/oDONOToutputANYTHING.
The content of loop.h is as follows:
extern void executed(void);
int value(char c);
void contin(char c);
You are expected to implement value() and contin() but not executed(). In your code that you will submit, you shall make sure to call executed(). In the evaluation process,your code will be compiled. executed() will be coded by the evaluators and compiled separately. Then both will be linked together and run on test data. Here is a executed() definition which you can use to test your program for the example input above. DO NOT FORGET TO REMOVE IT WHEN YOU SUBMIT. ALSO DO NOT FORGET TO INCLUDE loop.h IN THE CODE YOU SUBMIT.
executed() definition that you can use for testing.
Void executed(void)
{ printf("X:%d r:%d Y:%d\n", value(’X’), value(’r’), value(’Y’)); }
AN EXAMPLE RUN: This is the out put that would be generated with the example input and the example executed() definition:
X:10 r:-3 Y:0
X:10 r:-3 Y:-1
X:10 r:-3 Y:-2
X:10 r:-2 Y:0
X:10 r:-2 Y:-1
X:10 r:-2 Y:-2
X:10 r:-1 Y:0
X:10 r:-1 Y:-1
X:10 r:-1 Y:-2
X:10 r:0 Y:0
X:10 r:0 Y:-1
X:10 r:0 Y:-2
X:10 r:1 Y:0
X:10 r:1 Y:-1
X:10 r:1 Y:-2
X:10 r:2 Y:0
X:10 r:2 Y:-1
X:10 r:2 Y:-2
X:13 r:-3 Y:0
X:13 r:-3 Y:-1
X:13 r:-3 Y:-2
X:13 r:-2 Y:0
X:13 r:-2 Y:-1
X:13 r:-2 Y:-2
X:13 r:-1 Y:0
X:13 r:-1 Y:-1
X:13 r:-1 Y:-2
X:13 r:0 Y:0
X:13 r:0 Y:-1
X:13 r:0 Y:-2
X:13 r:1 Y:0
X:13 r:1 Y:-1
X:13 r:1 Y:-2
X:13 r:2 Y:0
X:13 r:2 Y:-1
X:13 r:2 Y:-2
X:16 r:-3 Y:0
X:16 r:-3 Y:-1
X:16 r:-3 Y:-2
X:16 r:-2 Y:0
X:16 r:-2 Y:-1
X:16 r:-2 Y:-2
X:16 r:-1 Y:0
X:16 r:-1 Y:-1
X:16 r:-1 Y:-2
X:16 r:0 Y:0
X:16 r:0 Y:-1
X:16 r:0 Y:-2
X:16 r:1 Y:0
X:16 r:1 Y:-1
X:16 r:1 Y:-2
X:16 r:2 Y:0
X:16 r:2 Y:-1
X:16 r:2 Y:-2
Here is a another executed() which makes use of contin():
void executed(void) { printf("X:%d r:%d Y:%d\n",value(’X’), value(’r’),value(’Y’));
if ((value(’X’)+value(’r’)+alue(’Y’)) % 5 == 0) {
printf("JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.\n"); contin(’r’); } }
And here is the output:
X:10 r:-3 Y:0
X:10 r:-3 Y:-1
X:10 r:-3 Y:-2
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:10 r:-2 Y:0
X:10 r:-2 Y:-1
X:10 r:-2 Y:-2
X:10 r:-1 Y:0
X:10 r:-1 Y:-1
X:10 r:-1 Y:-2
X:10 r:0 Y:0
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:10 r:1 Y:0 X:10 r:1 Y:-1
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:10 r:2 Y:0
X:10 r:2 Y:-1
X:10 r:2 Y:-2
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:13 r:-3 Y:0
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:13 r:-2 Y:0
X:13 r:-2 Y:-1
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:13 r:-1 Y:0
X:13 r:-1 Y:-1
X:13 r:-1 Y:-2
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:13 r:0 Y:0
X:13 r:0 Y:-1
X:13 r:0 Y:-2
X:13 r:1 Y:0
X:13 r:1 Y:-1
X:13 r:1 Y:-2
X:13 r:2 Y:0
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:16 r:-3 Y:0
X:16 r:-3 Y:-1
X:16 r:-3 Y:-2
X:16 r:-2 Y:0
X:16 r:-2 Y:-1
X:16 r:-2 Y:-2
X:16 r:-1 Y:0
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:16 r:0 Y:0
X:16 r:0 Y:-1
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:16 r:1 Y:0
X:16 r:1 Y:-1
X:16 r:1 Y:-2
JUST MAGIC OF FIVE HAPPENED!...Continuing with next ’r’ value.
X:16 r:2 Y:0
X:16 r:2 Y:-1
X:16 r:2 Y:-2
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme