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
|
bool sortByAreaAscend( unique_ptr<ShapeTwoD>& lhs, unique_ptr<ShapeTwoD>& rhs)
{
return lhs->getArea()< rhs->getArea();
}
bool sortByAreaDescend( unique_ptr<ShapeTwoD>& lhs, unique_ptr<ShapeTwoD>& rhs)
{
return lhs->getArea()> rhs->getArea();
}
bool sortByTypeAndArea( unique_ptr<ShapeTwoD>& lhs, unique_ptr<ShapeTwoD>& rhs)
{
return lhs->getContainsWarpSpace()> rhs->getContainsWarpSpace()&& lhs->getArea()> rhs->getArea();
}
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,int count)
{
ShapeTwoD sh;
double a;
for (int i=0;i<newCoords.size();i++)
{
newCoords[i]->computeArea();
}
cout<<"Computation completed! ( "<<count<<" records were updated )"<<endl;
}
void input(vector<unique_ptr<ShapeTwoD>>& data)
{
string s;
double a;
bool b;
string bs;
cout<<"[ Input sensor data ]"<<endl;
cout<<"Please enter name of shape : "<<endl;
getline(cin,s);
if(s=="Rectangle")
{
int coordX[4];
int coordY[4];
cout<<"Please enter special type : "<<endl;
cin.clear();
getline(cin,bs);
if(bs=="WS")
{
b = true;
}
else
{
b = false;
}
for(int i=0;i<4;i++)
{
cout<<"Please enter x-ordinate of pt."<<i+1<<endl;
cin>>coordX[i];
cout<<"Please enter y-ordinate of pt."<<i+1<<endl;
cin>>coordY[i];
}
data.emplace_back(new Rectangle(s,b,a,coordX,coordY));
cout<<data.size()<<endl;
}
cout<<"Record successfully stored.Going back to main menu...."<<endl;
}
void sortMenu(vector<unique_ptr<ShapeTwoD>>& newCoords)
{
char sortChoice;
cout <<endl;
cout << "a) Sort by area (ascending)" << endl;
cout << "b) Sort by area (for all records)" << endl;
cout << "c) Sort by special type" << endl;
cout <<endl;
cout <<"Please select sort option ('q' to go main menu) : ";
cin >>sortChoice;
switch(sortChoice)
{
case 'a':
{
sort(newCoords.begin(),newCoords.end(),sortByAreaAscend);
print(newCoords);
}break;
case 'b':
{
sort(newCoords.begin(),newCoords.end(),sortByAreaDescend);
print(newCoords);
}break;
case 'c':
{
sort(newCoords.begin(),newCoords.end(),sortByTypeAndArea);
print(newCoords);
}break;
case 'q':
{
}break;
}
}
|