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
|
#include <iostream>
#include <cstdlib>
using namespace std;
//define type:
struct TPont{double x,y;} ;
//define the maximum relation:
int max(int a,int b,int c,int d)
{
int max_val=a;
if (b>max_val)
max_val=b;
if (c>max_val)
max_val=c;
if (d>max_val)
max_val=d;
return max_val;
}
int main()
{
//input
TPont p;
int n;
//output
//checking the validity of input
bool hiba;
string tmp;
//intializing quadrants
int first=0;
int second=0;
int third=0;
int fourth=0;
//inputting
do{
cout << "How many points will you be checking for?" << endl; cin >> n;
error=cin.fail();
if (error)
{
cout << "Wrong input!" <<endl;
cin.clear(); getline(cin,tmp,'\n');
}
}while (error);
for(int i=0;i<n;i++){
do{
cout << "Please type the x and y coordinates of point p! " << endl; cin >> p.x >> p.y;
error=cin.fail();
if (error)
{
cout << "Wrong input!" <<endl;
cin.clear(); getline(cin,tmp,'\n');
}
}while (error);
//counting how many points lie in each quadrant
if (p.x>0)
{
if (p.y>0) first++;
else if (p.y<0) fourth++;
}else if (p.x<0){
if (p.y>0) second++;
else if (p.y<0) third++;
}
//If any points lie on the x axis then the program writes that
if (p.x==0)
{
cout << "The (" << p.x << ", "<< p.y <<")" << "point lies on the X axis." <<endl;
}
}
//checking for maximum and writing it on the screen
if (first==max(first, second, third, fourth))
{
cout << "Most points lie in the first quadrant." <<endl;
}
if (second==max(first, second, third, fourth))
{
cout << "Most points lie in the second quadrant." <<endl;
}
if (third==max(first, second, third, fourth))
{
cout << "Most points lie in the third quadrant." <<endl;
}
if (fourth==max(first, second, third, fourth))
{
cout << "Most points lie in the fourth quadrant." <<endl;
}
system("pause");
return 0;
}
|