need help plz

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bigj0410
    New Member
    • Feb 2007
    • 25

    need help plz

    i've been trying to figure out these questions and i can't seem to understand them...can anyone help?

    1)Write a full program in C++ that creates the two-dimensional randomArray
    array with 10 rows and 10 columns, and fills it with random numbers
    respectively: the first row with random number in range [1, 100), the second
    row with random number in range [100, 200), …, the 10th row with random
    number in range [900, 1000), The program then displays the array elements
    on-screen 10 in each row.

    2) Create two arrays with 10 elements averageRows and averageColums.
    Calculate the average value for each row of randomArray and assign them
    respectively to elements of averageRows array. (The average of the first row
    of randomArray to the first element of averageRows, … the average of the
    last row of randomArray to the last element of averageRows). Fill in the
    same way the averageColums array but this time with average values of
    columns of randomArray. Calculate the average of the diagonal of array
    averageRows (e00, e11, …, e99) and the average of elements of the second
    diagonal of averageRows (e90, e81, …, e09). Display all the results on screen.


    thx in advance ;)
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by Bigj0410
    i've been trying to figure out these questions and i can't seem to understand them...can anyone help?

    1)Write a full program in C++ that creates the two-dimensional randomArray
    array with 10 rows and 10 columns, and fills it with random numbers
    respectively: the first row with random number in range [1, 100), the second
    row with random number in range [100, 200), …, the 10th row with random
    number in range [900, 1000), The program then displays the array elements
    on-screen 10 in each row.

    2) Create two arrays with 10 elements averageRows and averageColums.
    Calculate the average value for each row of randomArray and assign them
    respectively to elements of averageRows array. (The average of the first row
    of randomArray to the first element of averageRows, … the average of the
    last row of randomArray to the last element of averageRows). Fill in the
    same way the averageColums array but this time with average values of
    columns of randomArray. Calculate the average of the diagonal of array
    averageRows (e00, e11, …, e99) and the average of elements of the second
    diagonal of averageRows (e90, e81, …, e09). Display all the results on screen.


    thx in advance ;)
    What don't you understand? Is it the data creation, the manipulation... ?

    Comment

    • Bigj0410
      New Member
      • Feb 2007
      • 25

      #3
      both of them...its so frustrating...b tw...i'm a rookie to programming

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by Bigj0410
        both of them...its so frustrating...b tw...i'm a rookie to programming
        Ok, so you need help with the algorithm - let's take them one at a time.

        Can you tell me the steps you would take to solve the first one, without a computer?

        Comment

        • Bigj0410
          New Member
          • Feb 2007
          • 25

          #5
          basically..make 10 rows with random numbers in them starting in the 1-100 range on the first row....100,200 on da second and so on til the 10th row....i really suck at this

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by Bigj0410
            basically..make 10 rows with random numbers in them starting in the 1-100 range on the first row....100,200 on da second and so on til the 10th row....i really suck at this
            Nah, you're just starting out. Nobody's amazing when they start out - but we can get you there ;)

            So - to refine your algorithm a bit:

            create array[10][10]
            for each i in array[1][i]
            input random number between 1 and 100
            for each i in array[2][i]
            input random number between 100 and 200
            for each i in array[3][i]
            input random number between 200 and 300
            for each i in array[4][i]
            input random number between 300 and 400
            and so on until 10

            does that look right?

            If so, how familiar are you with the rand() function?

            Comment

            • Bigj0410
              New Member
              • Feb 2007
              • 25

              #7
              yea it looks right...and yea i'm a bit familiar wit ran()..etc :)

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Originally posted by Bigj0410
                yea it looks right...and yea i'm a bit familiar wit ran()..etc :)
                Ok, so are you starting to see how (from the algorithm) this is going to come together?

                I'm sure you can create the headers and main declaration - then you just need to follow your algorithm.

                Comment

                • Bigj0410
                  New Member
                  • Feb 2007
                  • 25

                  #9
                  Originally posted by sicarie
                  Ok, so are you starting to see how (from the algorithm) this is going to come together?

                  I'm sure you can create the headers and main declaration - then you just need to follow your algorithm.


                  yea i'm starting to see it :)

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    Originally posted by Bigj0410
                    yea i'm starting to see it :)
                    Ok, so you have your basic structure, and your arrays declared, right?

                    Then you just need to figure out how to get the random number in between 1 and 100.

                    I think this link will give you a good idea of how to do that - but definitely post if you get confused.

                    (Anyone else have a good link to show this?)

                    Comment

                    • Bigj0410
                      New Member
                      • Feb 2007
                      • 25

                      #11
                      Originally posted by sicarie
                      Ok, so you have your basic structure, and your arrays declared, right?

                      Then you just need to figure out how to get the random number in between 1 and 100.

                      I think this link will give you a good idea of how to do that - but definitely post if you get confused.

                      (Anyone else have a good link to show this?)

                      yea i'm startting to understand this..a bit...i'm a slow learner too

                      Comment

                      • sicarie
                        Recognized Expert Specialist
                        • Nov 2006
                        • 4677

                        #12
                        Originally posted by Bigj0410
                        yea i'm startting to understand this..a bit...i'm a slow learner too
                        Hey, as long as you're learning. I just made a jackass of myself in another thread. It's all about keeping with it and learning something from it.

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #13
                          Posted from users PM:
                          Originally posted by Bigj0410
                          so far this is wut i got...
                          Code:
                          #include <iostream>
                          using namespace std;
                          
                          int main()
                          {
                          int rand[10];
                          int i;
                          for ( i = 1; i < 10; i++)
                          cin >> random[i]=1;
                          is this right so far?
                          You're getting the idea, but there are a few comment's I'd like to make.

                          1) naming variables. Once you get into larger programs, it's good practice to name variables with descriptive names. You did this, but you are also going to be using the rand() function to get the random numbers. This is going to make these two confusing. I would try 'columns' or 'matrix' or something a bit more unique, but still descriptive of what it is.

                          2) you declare rand and then try to access random. The method of access is correct (you use i as the index correctly), but the variable name isn't correct - this will cause an error.

                          3) you have the user entering in the values for the array. You will want to declare rand and assign it to a number (that will get overwritten ever time you call another random number), and then set that equal to the array.

                          4) This might be unintentional, but it's good that you started small - only did one part of the double-for loop, 2-d array first, and then when you understand it, it'll be very simple to make it bigger.

                          5) You declared 'int main()' and so should end with a 'return 0; }' (The '}' should be on the next line, I just don't know how to format it off the top of my head, without using the [ code] tags)

                          Comment

                          • Bigj0410
                            New Member
                            • Feb 2007
                            • 25

                            #14
                            Originally posted by sicarie
                            Posted from users PM:

                            You're getting the idea, but there are a few comment's I'd like to make.

                            1) naming variables. Once you get into larger programs, it's good practice to name variables with descriptive names. You did this, but you are also going to be using the rand() function to get the random numbers. This is going to make these two confusing. I would try 'columns' or 'matrix' or something a bit more unique, but still descriptive of what it is.

                            2) you declare rand and then try to access random. The method of access is correct (you use i as the index correctly), but the variable name isn't correct - this will cause an error.

                            3) you have the user entering in the values for the array. You will want to declare rand and assign it to a number (that will get overwritten ever time you call another random number), and then set that equal to the array.

                            4) This might be unintentional, but it's good that you started small - only did one part of the double-for loop, 2-d array first, and then when you understand it, it'll be very simple to make it bigger.

                            5) You declared 'int main()' and so should end with a 'return 0; }' (The '}' should be on the next line, I just don't know how to format it off the top of my head, without using the [ code] tags)

                            but still just trying to write it is frustrating.... .wut i do is write it on paper then type it out....i keep getting messed up...how would u write it? if i don't mind asking

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #15
                              Originally posted by Bigj0410
                              but still just trying to write it is frustrating.... .wut i do is write it on paper then type it out....i keep getting messed up...how would u write it? if i don't mind asking
                              Well, I'd start out with the shell:

                              Code:
                              #include <iostream>
                              using namespace std;
                              
                              int main()
                              {
                              
                                  return 0;
                              }
                              and then I would put my algorithm inside


                              Code:
                              #include <iostream>
                              using namespace std;
                              
                              int main()
                              {
                                  //  create matrix[10][10]
                                  // for each i in matrix [1][i]
                                      // get random number between 1 and 100
                                      // matrix[1][i] = random number
                                  // for each i in matrix [2][i]
                                      // get random number betwee 100 and 200
                                      // matrix[2][i] = rand
                                  /// and on to matrix [10][i]
                                  return 0;
                              }
                              Then I would go through and start breaking that algorithm down - into statements that could be in a single line, and then try to turn it into code


                              Code:
                              #include <iostream>
                              using namespace std;
                              
                              int main()
                              {
                                  //  create matrix[10][10]
                                  int matrix[10][10];
                                  int tmp_rand;
                                  // for each i in matrix [1][i]
                                  for (int i = 0; i < 10; i++) {
                                      // get random number between 1 and 100
                                      /* I'm not going to give this away, but I'm pretty sure you could figure it out */
                                      // matrix[1][i] = random number
                                  // for each i in matrix [2][i]
                                      // get random number betwee 100 and 200
                                      // matrix[2][i] = rand
                                  /// and on to matrix [10][i]
                                  }
                                  return 0;
                              }
                              and so on. This way it starts out as a working template (even though it doesn't do anything, it will compile), and builds up from there - and my code will be commented!

                              Does that make sense? Help at all?

                              Comment

                              Working...