Did you try sketching a quick diagram of this. You should be able to eliminate values which are outside your requirements using the comparison operators ==, >, >=, < and <= .
Logically, I don't quite understand where should I start, how do I eliminate the unwanted values. It has been puzzling me. Been searching through the internet.
Like how is it use that using those operators will found out the values that I need to find out..
Honestly, if you just get out a piece of paper and draw yourself a cartesian numberline and a square, then play with figuring out how to tell if a point is in or out of the square, then you will get it fairly quickly and have a very good understanding of how to make it work.
This is fine, when storing names/anything else in array1[50].
I store the coordinates in array2 because I have no idea how to store 4 (x,y) points into 1 variable and extract them when trying to match them.
So whenever I try the virtual and dynamic way which is.
Adding a virtual and also changing the arrays to
1 2
Test *array1[50]
Test *array2[50][12]
For the first array1[50] with the new *. It is fine. Nothing is wrong.
But when it comes to the second new array, it hangs whenever I put this array in. Is there any way to go about this?
point square[4];
square[0].x = 0.0;
square[0].y = 0.0;
square[1].x = 0.0;
square[1].y = 2.0;
// etc.
a good way to store them? If so, how do I know what to extract when I am looking for square[0] ? Is there a better way to store all the four points of the square? i.e x and y.
I am also dealing with inheritance and polymorphism.
So in what way is it best, for me to store all the four points so that it is easier for me to extract information out when I need the first square, or the second triangle, or the third rectangle?
struct point {
double x;
double y;
};
struct triangle {
point a;
point b;
point c;
};
struct square {
point points[4];
};
triangle t;
t.a.x = 0;
t.a.y = 1;
// etc
square s;
s.points[0].x = 2;
s.points[0].y = 2;
// etc.
These are just ideas to play with. I did triangle with individual corners, while the square has an array of 4 points.
I can't tell you whether they are suitable for your needs, in fact this may be a completely wrong direction.
You could extend this so the square, triangle etc. are proper classes with constructors etc. It really does depend on what are the full requirements that you have.
You could perhaps have a generic shape containing an array of points. Then depending on what type of shape it is, you will know how many points are in use.
#include <iostream>
#include <string>
#include "Shape.h"
#include "Square.h"
usingnamespace std;
class Test
{
public:
void mainMenu();
char menuChoice;
void stringToUpper(string &s);
};
void stringToUpper(string &s)
{
for(unsignedint l = 0; l < s.length(); l++)
{
s[l] = toupper(s[l]);
}
}
void Test::mainMenu()
{
cout<<"test"<<endl<<endl;
cout<<"1) input x y coords"<<endl;
cout<<"2) 2"<<endl;
cout<<"3) 3"<<endl;
cout<<"4) 4"<<endl;
cout<<"Q) q to quit<<endl<<endl;
}
int main()
{
char menuChoice;
bool quit=false;
Test test;
int count=0;
string shape, special;
Shape *arrayOfShapes[10];
while ( !quit )
{
test.mainMenu();
cout<<"Please enter your choice : ";
cin>>menuChoice;
menuChoice = toupper(menuChoice);
switch(menuChoice)
{
case '1':
cout<<endl<<"input x,y coords"<<endl;
cout<<"Please enter name of shape : "<<endl;
cin>>shape;
break;
case '2':
cout<<"Print"<<endl<<endl;
break;
case '3':
cout<<"You choosen 3"<<endl<<endl;
break;
case '4':
cout<<"You choosen 4"<<endl<<endl;
break;
case 'Q':
cout<<"You have chosen to quit!"<<endl<<endl;
quit=true;
exit(0);
default:
cout<<"Invalid entry!"<<endl<<endl;
break;
}
}
}
For the main program, I will also add in codes for the user to enter coords X and Y. Now the problem for me is, how do I input data for x,y and store them. I might play around with the ideas you gave me.
Do you get a clearer point of view here? Am I able to call the one at Square setXY, when I know that the input of the shape is 'Square' at the main program, then storing the coords?