Thread: An Array? help pls

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    21

    An Array? help pls

    now then, ive been researching arrays for a while, but can't seem to find how to do this still..


    I need to write a program to generate the co-ordinates of twenty-five elements for a square.

    this square shape is 1m by 1m.


    I need it to read the program inputs:

    no. of element
    the length of the shape
    width of shape
    store the output in another file.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What data will you be storing? How will you use an array to store that data. Will you need more than one array?

    Once you know what array(s) you need, you have to declare it. To declare it, you need to know its size. Can you figure out how large to make the array based on the assignment above?

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    21
    all i have is the info above.. how do u think i shuld go about it?

    chers

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I think you should think about the questions I asked. That's how you should start. Figure out the answers to those questions and you will be on your way.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    21
    Code:
    #include <iostream>
    using namespace std;
    
    
    
    int main()
    {
      int x,y;
      int array[5][5];
    
      for ( x = 0; x < 5; x++ )
        for ( y = 0; y < 5; y++ )
          array[x][y] = x * y;
      }
    now, this is the matrix, but im not too sure what can i do next

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    21

    help a student:D

    Any ideas ppl please?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I need to write a program to generate the co-ordinates of twenty-five elements for a square.
    > this square shape is 1m by 1m.
    You mean like there is a square at 0cm,0cm to 20cm,20cm
    And a square at 0cm,20cm to 20cm,20cm

    all the way up to
    a square at 80cm,80cm to 100cm,100cm

    You don't need a 2D array for that, just a couple of for loops and some cout statements.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    21
    ah you are right i think more simple than i thought. hmmm

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    21
    ok, so far I've got this, i think im on the right lines

    can anyone help complete?



    Code:
    using namespace std;
    
    int main()
    {
       int length;
       int width;  
       int x,y;   // row, column
       
       cout << "Input the size of the length of the square"; // asks user for size of the side
       cin >> length; 
       
       cout<<"input the size of width of the square"; 
       cin>>width      
       
        
    for ( x = 0; i < side; ++x)
        {
           cout << "*";
        }

    chers

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    21
    I need to write a program to generate the co-ordinates of twenty-five elements for a square.

    this square shape is 1m by 1m.


    I need it to read the program inputs:

    no. of element
    the length of the shape
    width of shape
    store the output in another file.

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Your description of the problem makes no sense at all. If you already know the length & width are both 1m, and the number of elements is 25, what's the point of having the program get input for those values?

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I dunno, maybe he wants to print something like this
    Code:
    *****
    *****
    *****
    *****
    *****
    If that isn't what you want soundwave, then actually write out by hand an example of what you expect to type in and an example of what you want to be printed.

    "store the output in another file" just doesn't help.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. Pls help:: function initializing for 2d array
    By ypramesh in forum C Programming
    Replies: 3
    Last Post: 03-29-2006, 03:35 PM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. Replies: 2
    Last Post: 06-18-2002, 11:03 AM