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

Write a C++ code that you need to summarize an array. Summary of an (data) array

ID: 3758991 • Letter: W

Question

Write a C++ code that you need to summarize an array. Summary of an (data) array means that printing all the items and quantity of a specific items found in the array. The summary of the array should be kept in another 1D array. Summary array should keep the items of data arrays in order. For instance, we are given an array with 10 items,


then summary of these array should be another array of  


Notice that in the summary array [2*n] shows the item found in the data array and [2*n+1] shows the quantity of [2*n+1], such as [0]=3, and [1] =4, how many times 3 found in the data array. Note that the size of summary array is not known.

In your program, you will create an data array with the size 100 and fill out with the random numbers between 10 and 50 (including 10 and 50). Then build your summary array based on data array and print out summary array.

5 3 19 5 4 3 7 3 3 5

Explanation / Answer

#include<iostream>

#include<time.h>

using namespace std;

int main() {

int data[100];

int summary[100];

int hash[51];

for (int i=0; i<51; i++) {

hash[i] = 0;

}

  

srand(time(NULL));

for (int i=0; i<100; i++) {

data[i] = rand()%41 + 10;

}

  

for (int i=0; i<100; i++) {

hash[data[i]]++;

}

  

for (int i=0; i<51; i++) {

summary[i] = hash[data[i]];

}

  

cout<<"Summary data: ";

  

for (int i=0; i<100; i++) {

cout<<summary[i]<<", ";

}

  

cout<<" ";

return 0;

}

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