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
|
#include <iostream>
#include "Rectangle.h"
#include "Square.h"
#include "Cross.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void print(vector<unique_ptr<ShapeTwoD>>& newCoords)
{
for (int i=0;i<newCoords.size();i++)
{
(*newCoords[i]).toString();
}
}
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>>& newCoords)
{
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")
{
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);
newCoords.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);
newCoords.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;
do{
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);
}break;
case 2:
{
compute(shape);
}break;
case 3:
{
print(shape);
}break;
case 4:
{
}break;
case 5:
{
}break;
}
}while(choice!=5);
return 0;
}
|