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

C++ Program In this project you need to summarize an array. Summary of an (data)

ID: 3758862 • Letter: C

Question

C++ Program
In this project 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 <stdlib.h>

using namespace std;

int main() {

   int randArray[100];

   //there are 41 numbers in range contians 10-50 numbers, so its the maximum size of array, Based on repetition of numbers
   //its size decreases. lenSummaryArray - Gives final size of summary array
   bool alreadyCount[41]; //this is to store unique numbers in the random array
   int summaryArray[41]; //this is store no of times each number present in random array
   int lenSummaryArray = 0, count = 0;
   int i,j;
   for(i = 0; i < 100; i++) {
       //numbers in range [ 10,50]
//       randArray[i] = 0;
       randArray[i] = rand() % 41 + 10;
   }

   cout << "Random array [100 elements]" <<endl;

       for(i = 0; i < 100; i++) {
           cout << randArray[i] << " ";
           if((i+1) % 20 == 0)
               cout <<" " <<endl;
       }

   for(i = 0; i < 41; i++) {
       summaryArray[i] = 0;
       alreadyCount[i] = false;

   }

   lenSummaryArray = 0;
   int index = 0;
   for(i = 0; i < 99; i++) {
       count = 0;
       index = randArray[i] - 10; //0- index contains 10, 1 cotains 11 and so on... 40 index contians 50

       if(!alreadyCount[index]) {
           summaryArray[index] = 1; //found once
           for(j = i+1; j < 100; j++) {
               if(randArray[i] == randArray[j]) {
                   summaryArray[index] = summaryArray[index]+1;
                   lenSummaryArray++;
               }
           }
       }
       alreadyCount[index] = true;
   }



   cout <<" " <<endl;
   cout<<("Unique numbers in random array: ");
   for(i = 0; i < 41; i++) {
       if(summaryArray[i] != 0) {
           cout << " " << (i+10);
       }
   }
   cout <<" " <<endl;

   cout<<("Summary Array                 : ");
       for(i = 0; i < 41; i++) {
           if(summaryArray[i] != 0) {
               cout << " " << summaryArray[i];
           }
       }
       cout <<" " <<endl;
}

-output---------------------

Random array [100 elements]
10 27 30 24 32 31 49 12 35 38 16 29 44 27 49 50 12 21 40 34

11 18 17 40 15 10 47 30 48 20 45 47 21 27 34 37 11 28 30 23

13 41 49 44 12 41 22 13 14 31 14 20 36 49 39 36 41 34 28 50

26 11 19 48 11 22 30 14 45 26 27 35 33 15 26 26 10 33 49 32

41 46 27 38 29 42 15 47 42 37 21 18 36 17 12 23 15 42 20 28

Unique numbers in random array:    10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   44   45   46   47   48   49   50

Summary Array                 :    3   4   4   2   3   4   1   2   2   1   3   3   2   2   1   4   5   3   2   4   2   2   2   3   2   3   2   2   1   2   4   3   2   2   1   3   2   5   2

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