Hello again, In step 2, written by the expert below, I want the elements of arrays number inputted by user and once their is a number for elements of array I want the program to generate random...




Hello again,



In step 2, written by the expert below, I want the elements of arrays number inputted by user and once their is a number for elements of array I want the program to generate random numbers and then show modes number like in picture 3 and if there are no mode number then print 'there are no mode numbers' like in picture 2.



Here are thr original instructions for this program.


 In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Write a function that accepts as arguments the following:



  1. A) an array of integers

  2. B) An integer that indicates the number of elements in the array and returns a vector of integers

  3. C) Do not sort the array


The function should determine the mode of the array or modes. That is, it should determine which value or values in the array occurs most often. The mode is the value or values the function should return. If the array has no mode (none of the values occur more than once), the function should return an empty vector. (Assume the array will always contain nonnegative values).


Write functions that fill the array with random numbers


Test your function thoroughly.


Thank you





thumb_down



Step 1


Your 1st question:


In picture one - Line 12 - int main(), there is a green squiggly line under the word main


This is because at the end of the function you are not returning any value.


So to avoid that,write return 0


--------------------------------------------------


Your 2nd question:


picture 2 -  My output is not generated. I showed how when you input the number of elements for arrays and click enter the numbers do not appear, then I clicked enter more times for you to see nothing happened when I clicked enter until I input numbers myself.


You are getting this because in the code any message like "Enter numbers" is not written. Without any message user is expected to enter numbers. So that's why after entering number of elements for array let n, immediately the user is expected to enter n number one after another.


If you want any message to let user know when to enter numbers, just display a message asking user to enter numbers.


For that reason, I have added a message asking user to enter numbers.





Step 2



Modified Program:



#include 

#include 

#include

using namespace std;

vector mode(int[], int);

int main()

{

int n, a[100000];

vector answer;

vector::iterator it;

cout <><>

cin >> n;


cout<><><>

for (int i = 0; i <>

{

cin >> a[i];

}

answer = mode(a, n);

if (answer.size() == 0)

{

cout <><>

}

else if (answer.size() == 1)

{

cout <><>

}

else

{

cout <><>

}

for (it = answer.begin(); it != answer.end(); it++)

{

cout <><>

}


return 0;

}

vector mode(int a[], int n)

{

int greater = 0;

vector v;

map m1, m2;

for (int i = 0; i <>

{

m1[a[i]]++;

if (m1[a[i]] > greater)

greater = m1[a[i]];

}

for (int i = 0; i <>

{

if (m1[a[i]] == greater && greater > 1 && m2[a[i]] != 1)

{

v.push_back(a[i]);

m2[a[i]] = 1;

}

}

return v;

}






Step 3



Output:




Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here