File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,12 @@ int main() {
4646 for (int j = 0 ; j < items[i].coord .size (); ++j)
4747 cout << " Item [" << i << " ] [" << j << " ] = " << items[i].coord [j] << endl;
4848
49+ cout << " Initialize with vector" << endl;
50+
51+ Point w ({0.51 , 10.45 , 20.35 });
52+
53+ cout << " Point w " << w << endl;
54+
4955 return 0 ;
5056}
5157
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ using namespace std;
99// Constructor
1010Point::Point (int dimen) {
1111
12- // Could not accept dimension less then 1 , don't return an error, but set default
13- if (dimen < 1 )
12+ // Could not accept dimension less then 2 , don't return an error, but set default
13+ if (dimen < 2 )
1414 dimen= 2 ;
1515
1616 coord.resize (dimen);
@@ -19,6 +19,20 @@ Point::Point(int dimen) {
1919
2020} // Constructor
2121
22+ Point::Point (vector<double > p_coord)
23+ {
24+ coord = p_coord;
25+ size_t dimen = coord.size ();
26+
27+ if (dimen < 1 )
28+ {
29+ coord.resize (2 );
30+ if (dimen == 0 )
31+ coord[0 ] = 0.0 ;
32+ coord[1 ] = 0.0 ;
33+ }
34+ }
35+
2236// Function to calculate distance to other point
2337double Point::dist (Point other) {
2438 double sum = 0 ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class Point {
1919
2020 // Constructor
2121 Point (int dimen = 2 );
22+ Point (vector<double > p_coord);
2223
2324 // Function to calculate distance to other point
2425 double dist (Point other);
Original file line number Diff line number Diff line change @@ -28,4 +28,7 @@ int main (int argc, char* argv[])
2828 for (int i = 0 ; i < s; i++)
2929 cout << names[i] << " \n " ;
3030
31+ for (string st : names)
32+ cout << st << endl;
33+
3134}
You can’t perform that action at this time.
0 commit comments