Trying to add an array or a vector of coordinates x and Y into my vector of unique pointers

Originally i did the adding of data through the using of x1,x2,etc..
but the requirements state that i have to create arrays or vectors to store my coordinates in my subclasses and do other methods using them. Now my question is how do i do that? i tried to do it normally but my constructor doesn't allow it. Please help, thanks.

Display.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  #include <iostream>
#include "Rectangle.h"

void print(vector<unique_ptr<ShapeTwoD>>& newCoords)
{
	string s;
	for (int i=0;i<newCoords.size();i++)
	{
		s=(*newCoords[i]).toString();
		cout<<s<<endl;
	}
}

void compute(vector<unique_ptr<ShapeTwoD>>& newCoords)
{
	ShapeTwoD sh;
	double a;
	for (int i=0;i<newCoords.size();i++)
	{
		a=(*newCoords[i]).computeArea();
		(*newCoords[i]).setArea(a);
	}
}

void input(vector<unique_ptr<ShapeTwoD>>& data,vector<Rectangle>& coords)
{
	
	
	int xCoord,yCoord,x1Coord,y1Coord,x2Coord,y2Coord,x3Coord,y3Coord;
	string s;
	double a;
	bool b = true;
		cout<<"name?"<<endl;
		getline(cin,s);
		
		
		if(s=="Rectangle")
		{
		
		for(int i=0;i<4;i++)
		{
		cout<<"Please enter value of x"<<endl;
		cin>>xCoord;
		cout<<"Please enter value of y"<<endl;
		cin>>yCoord;
		
		coords.insert(xCoord,yCoord);
		}
		/*cout<<"Please enter value of x1"<<endl;
		cin>>x1Coord;
		cout<<"Please enter value of y1"<<endl;
		cin>>y1Coord;
		cout<<"Please enter value of x2"<<endl;
		cin>>x2Coord;
		cout<<"Please enter value of y2"<<endl;
		cin>>y2Coord;
		cout<<"Please enter value of x3"<<endl;
		cin>>x3Coord;
		cout<<"Please enter value of y3"<<endl;
		cin>>y3Coord;*/
		//Square sq(s,b,x,y);
		data.emplace_back(new Rectangle(s,b,xCoord,yCoord,x1Coord,y1Coord,x2Coord,y2Coord,x3Coord,y3Coord,a));
	}
	/*if(s=="Square")
		{
		cout<<"Please enter value of x"<<endl;
		cin>>xCoord;
		cout<<"Please enter value of y"<<endl;
		cin>>yCoord;
		cout<<"Please enter value of x1"<<endl;
		cin>>x1Coord;
		cout<<"Please enter value of y1"<<endl;
		cin>>y1Coord;
		cout<<"Please enter value of x2"<<endl;
		cin>>x2Coord;
		cout<<"Please enter value of y2"<<endl;
		cin>>y2Coord;
		cout<<"Please enter value of x3"<<endl;
		cin>>x3Coord;
		cout<<"Please enter value of y3"<<endl;
		cin>>y3Coord;
		//Square sq(s,b,x,y);
		data.emplace_back(new Square(s,b,xCoord,yCoord,x1Coord,y1Coord,x2Coord,y2Coord,x3Coord,y3Coord,a));
	}*/
		/*cout<<"name?"<<endl;
	
		getline(cin,s);
		cout<<"Please enter value of x"<<endl;
		cin>>x;
		cout<<"Please enter value of y"<<endl;
		cin>>y;
		
		//Square sq(s,b,x,y);
		newCoords.emplace_back(new Rectangle(s,b,x,y));
	*/
}
	


int main(int argc, char** argv) {
	
	//ShapeTwoD sh;
	stringstream stream;
	int choice;
	string choiceString; 
	vector<unique_ptr<ShapeTwoD>>shape;
	vector<Rectangle>coordinates;
	
	
	do{

	cout << "Welcome to Assn2" << endl;
	cout << "1)	Input sensor data" << endl;
	cout << "2)	Compute area (for all records)" << endl;
	cout << "3)	Print shapes report" << endl;
	cout << "4)	Sort shape data" << endl;
	cout << "5)	Quit" << endl;
	cout <<endl;
	cout << "Please enter your choice : ";
	
	stream.clear();//clears stringstream
	getline(cin,choiceString);//gets whole line of input and store it into a string
	stream.str(choiceString);//stores string into stringstream
	choice= atoi(stream.str().c_str());//convert string into int
				
	while(!(stream >> choice))//loop if convert from string to int fail
	{
			
	cout<<"Please enter a valid choice"<<endl;
	stream.clear();//clears stringstream
	getline(cin,choiceString);//gets whole line of input and store it into a string
	stream.str(choiceString);//stores string into stringstream
	choice= atoi(stream.str().c_str());//convert string into int
					
					
				}
	cout<<endl;
	cout<<endl;
	
	switch(choice)
	{
		case 1:
			{
				input(shape,coordinates);	
			}break;
		case 2:
			{
				compute(shape);
			}break;
		case 3:
			{
				print(shape);
			}break;
		case 4:
			{
			}break;
		case 5:
			{
			}break;
				}	
}while(choice!=5);	
	return 0;
}

ShapeTwoD.h
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
	
	class ShapeTwoD {
		protected:
		string name;
		bool containsWarpspace;
		double area;
		int x,y;	
		
				
		public:
			ShapeTwoD();
			ShapeTwoD(string,bool,int,int,double);
			void setX(int);
			void setY(int);
			void setName(string);
			void setContainsWarpSpace(bool);
			virtual void setArea(double);
		 	virtual double getArea();
			string getName();
			int getX();
			int getY();
			bool getContainsWarpSpace();
			virtual double computeArea();
			virtual bool isPointInShape(int,int);
			virtual bool isPointOnShape(int,int);
			virtual string toString();
			
			
			
	};
	
	
	
	
	 
	#endif


ShapeTwoD.cpp
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
51
52
53
54
55
56
57
58
59
60
61
#include "ShapeTwoD.h"



ShapeTwoD::ShapeTwoD()
{

}
ShapeTwoD::ShapeTwoD(string sName,bool contain, double sArea)
{
	setName(sName);
	setContainsWarpSpace(contain);
	setArea(sArea);
}

double ShapeTwoD::computeArea()
{
	cout<<"No area computation defined"<<endl;
}

bool ShapeTwoD::isPointInShape(int coordx,int coordy)
{
	
}

bool ShapeTwoD::isPointOnShape(int coordx,int coordy)
{
	
}

double ShapeTwoD::getArea()
{
	return area;
}



void ShapeTwoD::setArea(double sArea)
{
	area=sArea;
}
void ShapeTwoD::setName(string sName)
{
	name=sName;
}
void ShapeTwoD::setContainsWarpSpace(bool contain)
{
	containsWarpspace=contain;
}


bool ShapeTwoD::getContainsWarpSpace()
{
	return containsWarpspace;
}


string ShapeTwoD::toString()
{
	
}

Rectangle.h
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"

class Rectangle:public ShapeTwoD{
		private:
		int x,y,x1,x2,x3,y1,y2,y3;
		double area;
		vector<Rectangle>rec;
		public:
		Rectangle();
		Rectangle(string,bool,int,int,double);
		//Rectangle(string,bool,int,int,int,int,int,int,int,int,double);
		double computeArea();
		string toString();
		void setArea(double);
		double getArea();
		int getX();
		int getY();
		vector<Rectangle> getRec();
		void setX(int);
		void setY(int);
		
	};


Rectangle.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Rectangle.h"


Rectangle::Rectangle()
{
}
Rectangle::Rectangle(string sName,bool contain,int coordX, int coordY,double sArea):ShapeTwoD(sName,contain,sArea)
{
    setX(coordX);
	setY(coordY);	
}
int Rectangle::getX()
{
	return x;
}
int Rectangle::getY()
{
	return y;
}

vector<Rectangle> Rectangle::getRec()
{
	return rec;
}

double Rectangle::getArea()
{
	return area;
}



void Rectangle::setArea(double sArea)
{
	area=sArea;
}

void Rectangle::setX(int coordX)
{
	x=coordX;
}
void Rectangle::setY(int coordY)
{
	y=coordY;
}


double Rectangle::computeArea()
{
	double area;
	cout<<"I'm a rectangle"<<endl;
	
	area = ((sqrt(pow((x-x1),2)+(pow((y-y1),2)))+(sqrt(pow((x-x3),2)+(pow((y-y3),2))))));
	cout<<area<<endl;
	//setArea(area);
	return area;
}

string Rectangle::toString()
{
	ostringstream os;
	os<<"The area is:" <<area<<endl;
	string var =os.str();
	
	return var;
}
Last edited on
Topic archived. No new replies allowed.