1. The way the classes and functions are named confuses me. What is the program trying to do?

The first 20 random numbers are:

11527,4365,19738,9290,29090,29206,21427,28828,21650,14538,23366,
18453,32723,11594,31040,24829,11476,20054,28717,30531

2.

3. Originally Posted by FallArk
The way the classes and functions are named confuses me.
That's the point. It's supposed to confuse you. The two main reasons that's done. First, so that you learn to name your variables/functions/classes intelligently so you can look at the code and have it be easily understandable. Second so that you learn to correctly trace code without relying on names to help you figure out what's going on, because when you look at someone elses code, or even your own from the past, it won't be guaranteed to be nicely written.

Quote:
What is the program trying to do?

The first 20 random numbers are:

11527,4365,19738,9290,29090,29206,21427,28828,21650,14538,23366,
18453,32723,11594,31040,24829,11476,20054,28717,30531
Before dealing with anything else those are not the first twenty random numbers, the first 20 random numbers, as returned by rand() in the code will be different each and every time the program is run because they're (pseudo)random. If you wanted them to be the same every time the code was run, for testing purposes, then you'd need to have a call to srand() with some number as the parameter before the for loop (i.e. srand(10); ).

As for what the code is doing you'd need to start by looking at main and drawing a memory diagram for all the variables that get created. For example after the first line you'd have a variable named q of type X in your memory diagram, and since it's a class inside of it you'd have places for all the variables that X contains and if any of those are classes you repeat the process. Then follow the code line by line. What does the body of the for loop do? What kind of values get passed into the function? What happens to that value in the function?

Originally Posted by squidsk
That's the point. It's supposed to confuse you. The two main reasons that's done. First, so that you learn to name your variables/functions/classes intelligently so you can look at the code and have it be easily understandable. Second so that you learn to correctly trace code without relying on names to help you figure out what's going on, because when you look at someone elses code, or even your own from the past, it won't be guaranteed to be nicely written.

Before dealing with anything else those are not the first twenty random numbers, the first 20 random numbers, as returned by rand() in the code will be different each and every time the program is run because they're (pseudo)random. If you wanted them to be the same every time the code was run, for testing purposes, then you'd need to have a call to srand() with some number as the parameter before the for loop (i.e. srand(10).

As for what the code is doing you'd need to start by looking at main and drawing a memory diagram for all the variables that get created. For example after the first line you'd have a variable named q of type X in your memory diagram, and since it's a class inside of it you'd have places for all the variables that X contains and if any of those are classes you repeat the process. Then follow the code line by line. What does the body of the for loop do? What kind of values get passed into the function? What happens to that value in the function?
Okay, I guess I need to try to get use to it then.
Btw, the 20 random numbers are given, then we trace it. I'm gonna try tracing it now

One question:
Does the program stores the previous values calculated from the for loop, or does it simply runs the loop once then discard the data and starts again?

6. Originally Posted by FallArk
One question:
Does the program stores the previous values calculated from the for loop, or does it simply runs the loop once then discard the data and starts again?
Depends what you asking. If you asking if the values calculated in the loop are kept for the next time the program starts up then no. Each time you start a program it starts fresh. If you're asking if each iteration of the loop stores it values, then the answer is "it depends". It depends what code actually happens inside the loop as to what values if any from the code within the loop are kept for the next iteration.