CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jul 2008
    Posts
    6

    Resolved c++ How can I append 3 values at once to a 2d array?

    #ifndef __dot_h
    #define __dot_h
    #include <iostream>

    struct dots
    {
    private:

    dots();
    ~dots();
    float points[3][3];
    float mids[2][3];

    public:

    float x(int point);
    float y(int point);
    float z(int point);
    void Init_dots();
    void Add_dots(float x1,float y1, float z1);
    void Add_dots(float x1,float y1, float z1,float x2, float y2, float z2);
    void Print_dots();

    };

    dots:ots()
    {

    }

    dots::~dots()
    {
    delete points;
    delete mids;
    }

    float dots::x(int point)
    {
    return points[point-1][0];
    }

    float dots::y(int point)
    {
    return points[point-1][1];
    }

    float dots::z(int point)
    {
    return points[point-1][2];
    }

    void dots::Init_dots()
    {
    for(int i=0;i<((sizeof(points)/sizeof(float))-1)/3;i++)
    {
    for(int j=0;j<3;j++)
    {
    points[i][j]=i+j;
    }
    }
    }

    void dots::Add_dots(float x1,float y1, float z1)
    {
    points[(sizeof(points)/sizeof(float))/3]={x1,y1,z1};
    }

    void dots::Add_dots(float x1,float y1, float z1,float x2,float y2, float z2)
    {
    points[sizeof(points)/sizeof(float)]={x1,y1,z1};
    points[sizeof(points)/sizeof(float)]={x2,y2,z2};
    }

    void dots::Print_dots()
    {
    for(int p=0;p<=(sizeof(points)/sizeof(float))-1;p++)
    {
    cout << points[p];
    cout << "\n";
    }
    }



    #endif;

    The problem occurs in "Add_dots" fuction. I want to be able to append 3 vales to the 2d array all at once if this is possible. I am pretty new to programming so if you see any other errors/better ways of doing things I am open to suggestions. Thank you.
    Last edited by fishies; July 22nd, 2008 at 01:00 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured