Exercise 2- Repetitive Equation Structures

1 Using the for-Loop

Write a class Repetitive, with an array rep, with 7 Integer values. The class should set all values in the array to 15, using a for-loop.



1.1


1.1.1 Simulation of Repetitive


2 Exercise without using the for-Loop

Write the class RepetitiveWithoutFor, doing the same thing as Repetitive above, though not using a for-loop.



2.1


2.1.1 Simulation of RepetitiveWithoutFor


3 Another Exercise Using the for-Loop

This time write a class Repeat, with an array repeater containing 4 Real values. The values in the array shall be set to 1, 4, 7, 10, using a for-loop.



3.1


3.1.1 Simulation of Repeat


4 Function with for-loop

Write a function, Rapper, which calculates the sum of the values in the array.




Write an instance, where the values of that array shall be set. Then simulate the instance class and plot the result.



4.1



4.1.1 Simulation of Rapper




5 Question

Why is it better not to have the same name on the variable in the iteration expression as a variable inside the for-clause in an equation?


5.1

It is not good from the programmers point of view. The variable inside the for-clause is hidden, which is all right, but they are by the programmer easily mixed together.