Struct

Hey guys, I'm hoping there is an easier way to do this. So Ive got 22 of these to do. Is there a easier/more efficient way to declare these???

1
2
3
4
5
6
7
8
9
10
struct Triangle {
	Point a, b, c;
	string color;
};

	Triangle triangles[100];
	triangles[0].a = { 0, 0 };
	triangles[0].b = { 600, 600 };
	triangles[0].c = { 600,0 };
	triangles[0].color = "yellow";
I didn't feel like including <windows.h> so I just made up a dummy struct

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
#include 	<iostream>
#include 	<string>

 using namespace std;
 
 struct Point {
	 int xpos, ypos;
 };
 
 struct Triangle {
		Point a, b, c;
		string color;

  // Implement a default constuctor.		
		Triangle () {
			a = { 0, 0 };
			b = { 600, 600 };
			c = { 600, 0 };
			color = "yellow";
		}
 };
 
 int main( ) {
        // Probably a good idea to avoid this kind of name as it can be confusing.
	Triangle triangles [22];
	return 0;
 }

I could use some help transferring these structs into svg format, without having to retype them all. It is supposed to be in a function as below. Ive been stuck on this for a few hours.

1
2
3
Triangle triangles[22];
	triangles[0].a = { 0, 0 }; triangles[0].b = { 600, 600 }; triangles[0].c = { 600,0 }; triangles[0].color = "yellow";
 

I have 22 declared as above (with different points).

1
2
3
void drawTriangle(Triangle t) {
	cout  << "<polygon points='0 0 600 600 0 600 z' fill='red' stroke='none' fill-opacity= '1.0' />" << endl;
}


I cant figure out how to get variables to be displayed in the svg format. Help would be appreciated.
Last edited on
Topic archived. No new replies allowed.