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

program needs to determine how many entries are actually entered (not counting t

ID: 3621957 • Letter: P

Question

program needs to determine how many entries are actually entered (not counting the 0) as it reads them in, Use a function called GET_DATA that is passed the array to read in the numbers and return the number of nonzero entries that were read in. (Have it either return the number of nonzero values that were read in directly or via a call by reference parameter- your choice) . DO NOT use global variables…Main should be actually declaring the array and calling GET_DATA.

#include <iostream>

using namespace std;

void get_data(int a[], int size, int& number_used);

void sort(int a[], int number_used);

void swap_values(int& v1, int& v2);

int index_of_smallest(const int a[], int start_index, int number_used);

void print_array(int a[], int number_used);

void display_count(const int a[], int number_used);

int main()

{

using namespace std;

int sample_array[10];

int number_used;

cout<<"Enter size of array";

cin>>number_used;

get_data(sample_array, 10, number_used);

sort(sample_array, number_used);

print_array(sample_array, number_used);

/*cout<<"Sorted Array"<<endl;

for (int index=0; index<number_used; index++)

cout<<sample_array[index]<< " ";

cout<<" ";*/

display_count(sample_array, number_used);

return 0;

}

void get_data(int a[], int size, int& number_used)

{

using namespace std;

cout<<"Enter at most 50 positive integers ranging from 1 to 9, when you are done enter 0:"<<endl;

int next;

int index = 0;

cin>>next;

while(next!=0 && next<=9)

{

a[index]=next;

index++;

cin>>next;

}

number_used = index;

}

void sort(int a[], int number_used)

{

int index_of_next_smallest;

for(int index = 0; index<number_used-1;index++)

{

index_of_next_smallest = index_of_smallest(a, index, number_used);

swap_values(a[index], a[index_of_next_smallest]);

}

}

void print_array(int a[], int size)

{

cout<<" Sorted Array"<<endl;

for (int index=0; index<size; index++)

cout<<a[index]<< " ";

cout<<" ";

}

void swap_values(int& v1, int& v2)

{

int temp;

temp = v1;

v1=v2;

v2=temp;

}

int index_of_smallest(const int a[], int start_index, int number_used)

{

int min = a[start_index];

int index_of_min = start_index;

for(int index= start_index+1; index<number_used; index++)

if(a[index]<min)

{

min = a[index];

index_of_min = index;

}

return index_of_min;

}

void display_count(const int a[], int number_used)

{

cout<<"N Count"<<endl;

int x=0;

for(int i=0;i<number_used+1;i++)

{

int count;

if(i==0)

count=0;

else

count=1;

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

{

count++;

i++;

}

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

x=i;

}

}

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
void get_data(int a[], int size, int& number_used);
void print_array(int a[], int number_used);
int main()
{
int sample_array[50];
int number_used=0;
get_data(sample_array, 50, number_used);
print_array(sample_array, number_used);
system("pause");
return 0;
}
void get_data(int a[], int size, int& index)
{int next;
cout<<"Enter at most 50 positive integers ranging from 1 to 9, when you are done enter 0:"<<endl;
cin>>next;
while(next!=0 && index<size)
{
a[index]=next;
index++;
cin>>next;
}
}


void print_array( int array[], int number)
{int i;
cout<<"Your array has "<<number<<" numbers ";
for(i=0;i<number;i++)
   cout<<array[i]<<" ";
cout<<endl;
}