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
|
#include <iostream>
#include <cstdlib>
using namespace std;
//define type
struct TPont{double x,y;} ;
float read(int &n, TPont &p);
void quadrants(int &first, int &second, int &third, int &fourth);
void waitforKB();
int main()
{
//input
TPont p;
int n, first, second, third, fourth;
//output
read(n, p);
quadrants(first,second,third,fourth);
waitforKB();
return 0;
}
//reading input
float read(int &n, TPont &p){
bool error;
string tmp;
do{
cout << "How many points will you be checking for?" << endl; cin >> n;
error=cin.fail() || n<0;
if (error)
{
cout << "Wrong input!" <<endl;
cin.clear(); getline(cin,tmp,'\n');
}
}while (error);
for(int i=0;i<n;i++){
do{
cout << "Please give the x 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);
}
return p.x;
return p.y;
}
//define 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;
}
//count which quadrants have how many points
void quadrants(int& first, int& second, int& third, int& fourth){
TPont p;
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++;
}
//check for maximum
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;
}
//This doesn't work AT ALL, I am just trying to put the coordinates that lie on the x axis in an array, but it isnt working at all
// void xAxis(float xAxis[]){
// if (p.x==0)
// {
// p.y=xAxis[n];
// cout << xAxis[n] <<endl;
// }
// }
void waitforKB()
{
system("pause");
}
|