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

Write a program that reads in a list of integers into an array with base type in

ID: 3631971 • Letter: W

Question

Write a program that reads in a list of integers into an array with base type int. Assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. 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 example, for the input
-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

having to start off using

#include <iostream)

using namespace std:

Explanation / Answer

#include <iostream>
#include <stdlib.h>
using namespace std;

void fillArray(int a[], int size, int& numberUsed);
void showFrequency (int a[], int SIZE);
void CheckDuplicate( int num, int arry[], int SIZE, int index);


int main( )
{
int sampleArray[50]={-12, 3, -12, 4, 1, 1, -12, 1, -1, 1, 2, 3, 4, 2, 3, -12};
int numberUsed; //the index

fillArray (sampleArray, 50 , numberUsed);


showFrequency (sampleArray, numberUsed);
return 0;
}



void fillArray(int a[], int SIZE, int& numberUsed)
{
int nums=16;
cout << "Enter up to " << SIZE << " whole numbers. ";
cout << "How many numbers do you want to enter? ";
cin >> nums;

for(int index; index < nums; ++index)
{
//cin >> a[index];
}
numberUsed=nums;
}

void showFrequency (int a[], int SIZE)
{
int prev = a[0], count = 0;
cout << " Number count ";
//cout << a[0] << " ";
for (int i=0; i< SIZE; i++)
{
CheckDuplicate(a[i], a, SIZE, i);
}
}

void CheckDuplicate( int num, int arry[], int SIZE, int index)
{
bool duplicate=false;
bool hasNumAppeard=false;
int counter=0;
static int *temp = new int[SIZE];
temp[index]=num;

for(int x=0; x < index; ++x)
{
if(temp[x]==num){
hasNumAppeard=true;
}
}

for(int x=0; x < SIZE; ++x)
{
if(arry[x]==num){
duplicate = true;
++counter;
}
}
if(duplicate==true && hasNumAppeard==false){
cout<<num<<" "<<counter<<endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote