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: A) an array of integers B) An integer that indicates the number of elements in the array and returns a vector of integers C) Do not sort the array The function should determine the mode of the array or

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
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 <iostream>
#include <vector>
#include <map>
using namespace std;
vector<int> mode(int[], int);
int main()
{
int n, a[100000];
vector<int> answer;
vector<int>::iterator it;
cout << "Enter number of elements in array:" << endl;
cin >> n;
cout<<"Enter "<<n<<" numbers: ";
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
answer = mode(a, n);
if (answer.size() == 0)
{
cout << "There are no modes" << endl;
}
else if (answer.size() == 1)
{
cout << "Mode is:" << endl;
}
else
{
cout << "Modes are:" << endl;
}
for (it = answer.begin(); it != answer.end(); it++)
{
cout << *it << " ";
}
return 0;
}
vector<int> mode(int a[], int n)
{
int greater = 0;
vector<int> v;
map<int, int> m1, m2;
for (int i = 0; i < n; i++)
{
m1[a[i]]++;
if (m1[a[i]] > greater)
greater = m1[a[i]];
}
for (int i = 0; i < n; 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:

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage