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

// // main.cpp // ch. 7 project 5 // # include <iostream> using namespace std ;

ID: 3536818 • Letter: #

Question

//

// main.cpp

// ch. 7 project 5

//


# include <iostream>

using namespace std;



void get_array(int [a], int size, int number);

void sort_array(int a[], int number);

void swap_numbers (int & num1, int & num2);

int smallest(const int a[], int starti, int number);


void countnumbers(const int a[], int number);


int main ()

{

int myarray[50], number;

cout<<"Enter the size of the array you want to use";

cin>>number;

get_array(myarray, 50, number);

sort_array(myarray, number);

countnumbers(myarray, number);

return 0;

  

}


void get_array(int a[], int size, int number)

{

cout<<"Enter the numbers: ";


int next;

int i=0;

while ((i<number))

{

cin>>next;

a[i]=next;

i++;

}

}


void sort_array(int a[],int number)

{

int inext;

for (int i=0; i<number-1; i++)

{

inext=smallest(a, i, number);

swap_numbers(a[i], a[inext]);

}

}


void swap_numbers (int &num1, int& num2)

{

int c;

c=num1;

num1=num2;

num2=c;

}


int smallest(const int a[], int starti, int number)

{

int min= a[starti], imin=starti;

for (int i=starti+1; i<number; i++)

if (a[i]>min)

{

min=a[i];

imin=i;

}

return imin;

}



void countnumbers(const int a[], int number)

{

cout<<"N Count"<<endl;

int x=0;

int count;

int j=0;

for(int j=0; j<number; j++)

{

if(j==0)

count=0;

else

count=1;

while (a[x]==a[j])

{

count++;

j++;

}

}

cout<<a[x]<<" "<<count<<endl;

x=j;

}

Explanation / Answer

change this line

void get_array(int [a], int size, int number);


to

void get_array(int a[], int size, int number);