Facebook Page
Twitter
RSS
+ Reply to Thread
Results 1 to 5 of 5
  1. MHB Craftsman
    FallArk's Avatar
    Status
    Offline
    Join Date
    Feb 2016
    Location
    State College, PA
    Posts
    127
    Thanks
    42 times
    Thanked
    49 times
    #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. # ADS
    Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many
     

  3. vBorg Coder
    squidsk's Avatar
    Status
    Offline
    Join Date
    Apr 2016
    Posts
    23
    Thanks
    1 time
    Thanked
    42 times
    #2
    Quote Originally Posted by FallArk View Post
    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 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?
    Last edited by squidsk; April 6th, 2016 at 16:31.

  4. MHB Craftsman
    FallArk's Avatar
    Status
    Offline
    Join Date
    Feb 2016
    Location
    State College, PA
    Posts
    127
    Thanks
    42 times
    Thanked
    49 times
    #3 Thread Author
    Quote Originally Posted by squidsk View Post
    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

  5. MHB Craftsman
    FallArk's Avatar
    Status
    Offline
    Join Date
    Feb 2016
    Location
    State College, PA
    Posts
    127
    Thanks
    42 times
    Thanked
    49 times
    #4 Thread Author
    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. vBorg Coder
    squidsk's Avatar
    Status
    Offline
    Join Date
    Apr 2016
    Posts
    23
    Thanks
    1 time
    Thanked
    42 times
    #5
    Quote Originally Posted by FallArk View Post
    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.

Similar Threads

  1. Simple question of interpretation - D&F Ch 10 - Proposition 30
    By Peter in forum Linear and Abstract Algebra
    Replies: 4
    Last Post: May 20th, 2014, 21:19
  2. Replies: 4
    Last Post: April 25th, 2014, 22:02
  3. Interpretation of question
    By Jameson in forum Chat Room
    Replies: 5
    Last Post: March 29th, 2013, 01:04
  4. Find a closed form interpretation for the integral :
    By ZaidAlyafey in forum Analysis
    Replies: 2
    Last Post: March 20th, 2013, 16:54
  5. Interpretation of estimated coefficients
    By Usagi in forum Basic Probability and Statistics
    Replies: 3
    Last Post: August 31st, 2012, 06:04

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Math Help Boards