Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Jas11

  • 3 years ago

can someone explain what the functions do in this program

  • This Question is Closed
  1. Jas11
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #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
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    which function.....

  3. ADGENIUS
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. Jas11
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy