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

#include <iostream> using namespace std; void fill_array(int a[], int size, int

ID: 3644356 • Letter: #

Question

#include <iostream>
using namespace std;


void fill_array(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 countOccurences(const int a[], int number_used);

int main( )
{
using namespace std;
int sample_array[10], number used;
cout<<"Enter size of array:";
cin>>number_used;
fill_array(sample_array, 10, number_used);
sort(sample_array, number_used);
countOccurences (sample_array, number_used);

system("pause");
return 0;
}

void fill_array (int a[], int size, int number_used)
{
using namespace std;
cout<<" Enter up elements";

int next, index=0;
while ( (index< number_used))
{
cin >> next;
a[index] = next;
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 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],
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 countOccurences (const int a[], int number_used)
{
cout<<"N Count"<<endl;
int x=0;
for(int i=0; i,number_used; 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;
}
}

I keep getting error C2678 and I cannot figure out why.

Explanation / Answer

please rate - thanks

if I knew what the program did I'd help debug it. I've highlighted and commented your problem

#include <iostream>
using namespace std;


void fill_array(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 countOccurences(const int a[], int number_used);

int main( )
{
using namespace std;
int sample_array[10], number_used;           //missing _
cout<<"Enter size of array:";
cin>>number_used;
fill_array(sample_array, 10, number_used);
sort(sample_array, number_used);
countOccurences (sample_array, number_used);

system("pause");
return 0;
}

void fill_array (int a[], int size, int number_used)
{
using namespace std;
cout<<" Enter up elements";

int next, index=0;
while ( (index< number_used))
{
cin >> next;
a[index] = next;
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 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],
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 countOccurences (const int a[], int number_used)
{
cout<<"N Count"<<endl;
int x=0;
for(int i=0; i,number_used; 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;
}
}