This is the program but I can\'t figure out the frequency array. Can anyone help
ID: 3635408 • Letter: T
Question
This is the program but I can't figure out the frequency array. Can anyone help?/******************************************************************************
program: frequency.cpp
author: N.Gallagher
assignment: #10
date due: 12/12/11
purpose: To load, sort and display the frequency of an array.
******************************************************************************/
#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;
//global constants
const int SIZE=50;
//function prototypes
void load_array(int numbers[]);
void sort_array(int numbers[]);
void display_array(const int numbers[]);
void display_frequency(const int numbers[]);
int main ()
{
int numbers[SIZE];
srand(time(0));
load_array(numbers);
sort_array(numbers);
display_array(numbers);
display_frequency(numbers);
system("pause");
return 0;
}
//////////////////////////////////////////////////////////////////////////
void load_array(int numbers[])
{
for(int count=0; count<SIZE; count++)
{
numbers[count]=rand()%20+1;
cout << numbers[count] << " ";
}
cout << endl << endl;
}
//////////////////////////////////////////////////////////////////////////
void sort_array(int numbers[SIZE])
{
int large, temp;
for(int pos=0; pos<SIZE-1; pos++)
{
large=pos;
for(int scan=pos+1; scan<SIZE; scan++)
if(numbers[scan] > numbers[large])
large=scan;
temp=numbers[large];
numbers[large]=numbers[pos];
numbers[pos]=temp;
}
}
//////////////////////////////////////////////////////////////////////////
void display_array(const int numbers[])
{
for(int count=0; count<SIZE; count++)
cout << numbers[count] << " ";
cout << endl << endl;
}
//////////////////////////////////////////////////////////////////////////
void display_frequency(const int numbers[])
{
int current;
int count=1;
for(int x=0; x<SIZE; x++)
{
if(numbers[x]==current)
{
count++;
}
else
{
cout << numbers[x] << " " << count << endl;
count=1;
}
}
}
//////////////////////////////////////////////////////////////////////////
Explanation / Answer
public static void sort(String[] a) { int N = a.length; for (int i = 1; i 0; j--) if (a[j-1].compareTo(a[j]) > 0) exch(a, j, j-1); else break; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.