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

I will rate the highest to whomever helps me with this program written in C++. W

ID: 3555117 • Letter: I

Question

I will rate the highest to whomever helps me with this program written in C++.

Write a program that reads in an array of type int. You may assume that there are fewer
than 50 entries in the array. Your program determines how many entries are used. The
output is to be a two-column list. The first column is a list of the distinct array elements;
the second column is the count of the number of occurrences of each element. The list
should be sorted on entries in the first column, largest to smallest.

For the array values:

-12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

the output should be

N Count
4 2
3 3
2 2
1 4
-1 1
-12 4

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
int size;
cout<<"enter size of array : ";
cin>>size;
int data[size];
for(int i=0;i<size;i++)
{
cout<<"enter data : ";
cin>>data[i];
}
int temp;
for(int i=1;i<size;i++){
temp=data[i];
int j=i-1;
while((temp>data[j])&&(j>=0)){
data[j+1]=data[j];
j=j-1;
}
data[j+1]=temp;
}
cout<<endl;
for(int i=0;i<size;i++)
cout<<data[i]<<endl;

int dat[size][2];
int flag=0;
int count=1;
for(int i=0;i<size;i++)
{
dat[i][0]=data[i];

if(count==1)
{


int j=i;
while(data[j+1]==data[j] && j!=size && flag==0)
{
count=count+1;
j=j+1;
flag=1;
}
dat[i][1]=count;
}
else
{
dat[i][1]=dat[i-1][1];
count--;
}


}

for(int i=0;i<size;i++)
{
cout<<endl;
for(int j=0;j<2;j++)
{
cout<<" " <<dat[i][j]<<" ";
}
}
}