Using the previous array program Sort and Search rewrite the

Using the previous array program (Sort and Search), rewrite the program using a pointer to display the original and sorted contents of the array. Ex: Use array++ where array is the name of the array.

- For all loop manipulating arrays, use the array address as the starting point and the last element as the ending point.

- For all loops manipulating arrays, do not use subscripts to assign or compare array elements.

- Please output all currency values using two decimal places.

#include

#include

#include

#include

using namespace std;

void bubbleSort(string name[], int year[], double tuition[], int i)

{

   string tempS;

   double tempD;

   int tempI;

   for (int j = i - 1; j>0; j--)

   {

       for (int k = 0; k

       {

           if (year[k]>year[k + 1])

           {

               tempI = year[k];

               year[k] = year[k + 1];

               year[k + 1] = tempI;

               tempS = name[k];

               name[k] = name[k + 1];

               name[k + 1] = tempS;

               tempD = tuition[k];

               tuition[k] = tuition[k + 1];

               tuition[k + 1] = tempD;

           }

       }

   }

}

void display(string name[], int year[], double tuition[], int i)

{

   for (int j = 0; j

   {

       cout << left << setw(20) << name[j] << right << setw(10) << year[j] << setw(10) << tuition[j] << endl;

   }

}

int linearSearch(string name[], int year[], double tuition[], int i, int y)

{

   for (int j = 0; j

       if (year[j] == y)

           return i;

   return 0;

}

Solution

Hi, I have modified your code according to your requirement.

I have used pointer every where and printing decimal point up to two decimal

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;

void bubbleSort(string *name, int *year, double *tuition, int i)
{
string tempS;
double tempD;
int tempI;
for (int j = i - 1; j>0; j--)
{
for (int k = 0; k<=j; k++)
{
if (*(year+k) > *(year+k + 1))
{
tempI = *(year+k);
*(year+k) = *(year+k+1);
*(year+k+1) = tempI;

tempS = *(name+k);
*(name+k) = *(name+k+1);
*(name+k+1) = tempS;

tempD = *(tuition+k);
*(tuition+k) = *(tuition+k+1);
*(tuition+k+1) = tempD;
}
}
}
}
void display(string *name, int *year, double *tuition, int i)
{
for (int j = 0; j<i; j++)
{
cout << left << setw(20) << *(name+j) << right << setw(10) << *(year+j) << setw(10) <<
fixed<<setprecision(2)<<*(tuition+j) << endl;
}
}
int linearSearch(string *name, int *year, double *tuition, int i, int y)
{
for (int j = 0; j<i; j++)
if (*(year+j) == y)
return i;
return 0;
}

Using the previous array program (Sort and Search), rewrite the program using a pointer to display the original and sorted contents of the array. Ex: Use array+
Using the previous array program (Sort and Search), rewrite the program using a pointer to display the original and sorted contents of the array. Ex: Use array+
Using the previous array program (Sort and Search), rewrite the program using a pointer to display the original and sorted contents of the array. Ex: Use array+

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site