logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 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

  • 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 definition.
  • 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 definition above

. • Sinceyourprogramsaregradedusingsomeautomatedi/oDONOToutputANYTHING.

  • Your code shall start with #include "loop.h"

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

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. 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. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

710 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

558 Answers

Hire Me
expert
Husnain SaeedComputer science

666 Answers

Hire Me
expert
Atharva PatilComputer science

592 Answers

Hire Me