## Jas11 3 years ago can someone explain what the functions do in this program

1. Jas11

#include <iostream> #include<cmath> using namespace std; //global constants const int MAX_PAIRS=10; //data types struct point { double x, y, distance; }; enum pointType {valuex, valuey, valued}; //functions void readData(point[]); void sortData(point[],pointType); void printData(point[]); int main() { pointType i; point pointList[MAX_PAIRS]; readData(pointList); for(i=valuex;i<=valued;i=pointType(i+1)) { sortData(pointList,i); if(i==valuex) cout<<"this is soorted by x in ascending order"<<endl; else if(i==valuey) cout<<"this is sorted by y in descending order"<<endl; else cout<<"this is the distance by ascending order"<<endl; printData(pointList); } return 0; } void readData(point pointList[MAX_PAIRS]) { int i; for (i=0;i<=MAX_PAIRS-1;i++) { cout <<"please enter the x and y for the pairs "<<i+1<<endl; cin>>pointList[i].x>>pointList[i].y; pointList[i].distance=sqrt(pow(pointList[i].x,2)+pow(pointList[i].y,2)); } } void sortData(point pointList[MAX_PAIRS],pointType whichValue) { int i,last; point temp; bool outOfOrder; for(last=MAX_PAIRS-1;last>=0;last--) for(i=0;i<=last-1;i++) { switch(whichValue)//which field am I sorting by? { case valuex: outOfOrder=pointList[i].x>pointList[i+1].x; break; case valuey: outOfOrder=pointList[i].y<pointList[i+1].y; break; case valued: outOfOrder=pointList[i].distance>pointList[i+1].distance; break; } if(outOfOrder) { temp=pointList[i]; pointList[i]=pointList[i+1]; pointList[i+1]=temp; } } } void printData(point pointList[MAX_PAIRS]) { int i; for (i=0;i<=MAX_PAIRS-1;i++) { cout<<pointList[i].x<<", "<<pointList[i].y <<", "<<pointList[i].distance<<endl; } cout<<endl; }

2. rohitranjan1994

which function.....

there are more than one functions in this program. Please specify any particular function whose operation you want to know.

4. Jas11

@rohitranjan1994 @ADGENIUS I wanted to know what all three functions did