(5/5)

Hire Me
(5/5)

Hire Me
(5/5)

Hire Me
(5/5)

Hire Me

# This is about nested loop generation at run time. At run time you will be reading lines each of which deﬁne a loop variable (which is a single letter), a start value integer, an end value integer and a step size integer.

INSTRUCTIONS TO CANDIDATES

This is about nested loop generation at run time. At run time you will be reading lines each of which deﬁne a loop variable (which is a single letter), a start value integer, an end value integer and a step size integer. The ﬁrst 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 ﬁle 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 deﬁned in the ﬁrst 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

• The type of the numbers in the input complies with int. They will be separated by one or more blanks. There will be at least one line of loop deﬁnition.
• Do not even think about nesting (2 ×hletter count in alphabeti) real for loops in your program. Your program will receive a straight zero.
• It is possible that for a loop the given values are such that start value > end value with a positive step size. (or the other way around for a negative step size). In this case neither that loop nor those that are ‘inside’ it will have a chance to be executed. Since loop execute() is in the innermost loop, loop execute() will not be executed even once (and the program will terminate).
• If loop execute() contains loop continues() (possibly at multiple positions) it is guarantied that no call to loop variable value() is performed after any execution of the loop continues().
• You can assume that the input is error free and complies with the input deﬁnition above

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() deﬁnition 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() deﬁnition 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() deﬁnition:

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

## Related Questions

##### . The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

##### . Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

##### . The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

##### . Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

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

##### . The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

345 Experts Online