2d Array

Hi all, would appreciate if someone could solve my problem.
I am creating a 2d array to store x , y vertices to make into a shape of square.
AS i am a beginner in C++, please pardon my errors. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//main.cpp

  cout << "[Input sensor data]\n";

	cout << "Please enter name of shape :";
	cin >> shape;
	
	cout << "Please enter special type :";
	cin >> stype;

	if (stype =="WS")
	{
	containsWarpSpace = true;
	}
	else
	{
	containsWarpSpace = false;
	}

	
	if (shape == "Square")
	{
	int coords[4][2];
	vertices=4;

	for (int i = 0 ; i <vertices; i++)
	{
            cout << "Please enter x-ordinate of pt. " << (i+1) << ":";

            cin >> coords[i][0];

 

            cout << "Please enter y-ordinate of pt. " << (i+1) << ":";

            cin >> coords[i][1];

        	}

        //How do i declare to store the coords into square?
	Square square (shape, containsWarpSpace, vertices, coords[]);
	}



	cout << "\nRecord successfully stored. Going back to main menu...\n" ;

	cout << "-----------------------------------------------------------"<<endl <<endl;

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//square.cpp

//Am i doing the right way to declare int[][] to store vertices? if not how should i do it?


#include "Square.h"

Square::Square(string ShapeName, bool warpspace, int vertices, int[][]):ShapeTwoD(ShapeName, warpspace)
{
	vert = vertices
	//ord[] = ordinates[]
	this->int[4][2] = int[4][2];
	
}


int Square::getVert() {
 
    return vert;
 
}
 
void Square::setVert(int vertices) 
{
 
    vert = vertices;
 
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "ShapeTwoD.h"
#include "Point.h"

class Square:public ShapeTwoD{

	private:
  
	int vert;
	
	//int[4][2] coords;   WILL HIT ERROR here


	public:
	Square();
 	Square(string,bool,int,int[4][2]);

	

	int getVert();
	void setVert(int vert);	
	
};

I'm afraid I don't understand your assignment any better now than I did in your last thread.

Why is ShapeTwoD a concrete class?
Why can you change the name of a thing?
What is a "warp space"?

and now:

What sensor data are you reading?
You have a menu system?

As for the code above:

What is int[4][2] coords supposed to do? (You have an int coords[4][2] above, if that's what you mean.)

Line 41: Square square (shape, containsWarpSpace, vertices, coords); (Pass the address of the array.)

Line 8: You cannot have an argument of int[][]. (You should try to compile this and look at the errors you get.)
Line 12: You cannot assign an array to another. (You have to copy the individual elements.)

It really looks like you need to go back and review arrays: declaration, handing, modifying, passing as function arguments.

Hope this helps.
Sensor data is when user enter choice 1 to enter data for a shape. System will prompt to ask what is the shape, user will 'Square'. It will go to the square if statement and ask for 4 vertices.

It's a menu system where there's few choices to choose. First to input data and it will store in an object array, choice 2 will get all the record in an array and compute their own shape area individually.


int[4][2] is to store a 2d array for vertices. The issue is that i'm not ure how can i pass in the address area and what to put in the constructor. Hopefully you could use mine and show me an example or smth. I'm really short of time at the moment. Thanks pal.
Topic archived. No new replies allowed.