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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education