Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C++. Key Concepts: Arrays, parallel arrays, sorting, formatting output Set up

ID: 3678445 • Letter: I

Question

IN C++.

Key Concepts: Arrays, parallel arrays, sorting, formatting output

Set up a pair of parallel arrays of values with decimals. (You could just grab arrays from any form of your project or you could hardcode a new pair of arrays with at least 10 pairs of points.)

Implement any of the sorting algorithms from class. Specifically tell which algorithm you are implementing in your header comments. (You must use one of the algorithms from class, not anything else, regardless of whether it might work, as learning implementing of those classic algorithms is one of the goals.)

In doing your sort, sort according to the values in one of the arrays, but be careful to move both data points in each pair while sorting. See the example below.

Print out the data in both arrays both before and after sorting. In doing so...

Put each array in a column of width 10, where values are right-aligned.

Display each value with exactly one decimal place.

Sample Starting Arrays:

Here is code to set up those arrays that you may copy and paste to save time:

Sample Arrays, Sorted by x:

Sample Arrays, Sorted by x and with Output Decimals as Directed:

x y 33.35 1 26 3.2 20.1 2.1 28.123 4.3 12 5.4

Explanation / Answer

//linear sorting

class x{
   public:
       void x(){
           int i=0;
           double x[5], y[5],tempX, tempY;
           cout<<"Enter Value Of X and Y";
           for(i=0;i<5;i++)
               cin>>x[i]>>y[i];
           //sorting
           for(i=0;i<5;i++)
           {
               for (j=0;j<5;j++)
               if(x[i]<x[j])
               {
                   tempX=x[j]; tempY=y[j];
                   x[j]=x[i]; y[j]=y[i];
                   x[i]=tempX; y[i]=tempY;
               }
           }
           //outputing
           cout<<"x"<<" "<<"y"<<" ;
           for(i=0;i<5;i++)
               cout<<x[i]<<" "<<y[i]<<" ";
       }
}

void main(){
   x L;
   L.x();
   getch();
}