I sent and receive an answer from a expert a day ago but my Visual Studio 2019 for windows 10 would not open the header ,stdc++.h. I was wondering if there is a different header that can be used so I can run the
Hello, can you please help me. Can you check the code below with the instructions I may have missed something and please check line 69 because I get an error there? If possible, once complete please run the program and see that it works. I have not been able to because of the error.
---------------------------------------------------------------------------
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:
- an array of integers.
- B) An integer that indicates the number of elements in the array and returns a
vector of integers. - You may or may 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.
Outcome Criteria
1) program compiles
2) program solves problem according to specification
3) program declares, creates, or initializes static or dynamic array correctly
4) if required program defines function or functions with array parameters or array returns
5) program uses arrays to solve problem
6) program destroys any dynamic arrays
This is the code I needed corrected
#include <iostream>
using namespace std;
int detectMode(int* data, int size)
{
if (size == 0)
return 0;
int i, j, mode, frequency = 0, count = 0;
int** freq_array = (int**) (2 * sizeof(int*));
for (i = 0;i < 2;i++)
freq_array[i] = (int*) (size * sizeof(int));
for (i = 0;i < size;i++)
freq_array[1][i] = 0;
for (i = 0;i < size;i++)
{
for (j = 0;j < count;j++)
if (freq_array[0][j] == data[i])
{
freq_array[1][j]++;
break;
}
if (j == count)
{
freq_array[0][count] = data[i];
freq_array[1][count] = 1;
count++;
}
}
for (i = 0;i < count;i++)
if (freq_array[1][i] > frequency)
{
mode = freq_array[0][i];
frequency = freq_array[1][i];
}
for (i = 0;i < 2;i++)
free(freq_array[i]);
if (frequency == 1)
return -1;
else
return mode;
}
int main()
{
int n, i, result;
cout << "Enter size of array ";
cin >> n;
int data[n]; //Gives error under the n [n]
for (i = 0;i < n;i++)
cin >> data[i];
result = detectMode(data, n);
if (result == -1)
cout << "Mode not found\n";
else
cout << "Mode is " << result << endl;
return 1;
}
Expert Answer
Ans:)
In this program, you have used the counting sort technique. It's a bit confusing to debug. But I have created my own program with the same technique and requirements as the problem statement.
This program will return the array mode and if all the elements exist only once, it will print "Mode is not present."
Code and output screenshots are attached below. Hope it helps.
Code:
#include <iostream>
#include <bits/stdc++.h> // error: cannot open
using namespace std;
int detectMode(int data[], int size)
{
// variable to store max of
// input array which will
// to have size of count array
int max = *max_element(data, data + size);
// count array is used to
// store count of numbers.
int t = max + 1; //size of count array
int count[t];
for (int i = 0; i < t; i++)
count[i] = 0;
// Store count of each element
// of input array
for (int i = 0; i < size; i++)
count[data[i]]++;
// mode is the index with maximum count
int mode = 0;
int chk;
int k = count[0];
for (int i = 1; i < t; i++) {
if (count[i] > k) {
k = count[i];
mode = i;
}
}
if (k==1)
return -1;
else
return mode;
}
int main()
{
int n, i, result;
cout << "Enter size of array: ";
cin >> n;
int data[n]; //Gives error under the n [n]
for (i = 0;i < n;i++)
cin >> data[i];
result = detectMode(data, n);
if (result == -1)
cout << "Mode not found\n";
else
cout << "Mode is: " << result << endl;
return 1;
}
Output:
Thank you
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images
- Complete the code with if statement(s) to solve this problem? Print the message "charge your phone" if you have a charger and battery level is 15% or less. Print "Charge your phone when your charger s is available." if the battery is 15% or less and you don't have a charger. Print "Your battery is charged" if the battery level is more than 15%. Please set the font in the text editor to Courier New to make it easier for code to line up. 1 charger_available = True 2 battery_level = 0.15 3 4 7 10 Charge your phone.arrow_forwardI want to create a program for the user to enter the height and weight, perform simple mathematical operations, and tell them whether the weight is healthy or not simple GUI please with buttons and evreythingarrow_forwardUsing visual studio, please may you write a piece of programming about anything of your choice in Python. You can pick anything, but the programming must include all of the following Python features below. Radio buttons Messages Menus Listbox Scrollbar Canvas Basic GUI elements using Tkinter Events Please then write a description explaining the programming code's design and functionality, very detailed.arrow_forward
- The code will get a new value every 1 second ranging from -5 to 5 however if the value goes -3 to 1 back to -3 it should stay red and not switch back to black eg -5 = red -4 = red -3 = red -2.2 = red (this should be black but I want it to remain red as it is in between 2 red values and want to avoid flickering off the blinkstick) -4 = red 0 = black -1 = black 1 = black 2 = black 3 = black 3.5 = black 4.9 = green 5 = green 6 = green 4.4 = green (this should be black but I want it to remain green as it is in between 2 green values and want to avoid flickering off the blinkstick) 4.9 = greenarrow_forwardHello! I need help in creating a Universal Windows Project. Need to create an interface that should include a TextBox, Button, and two Label controls on the main window. Place them anywhere in the window. need to also calculate sq root as well, but not using Math.Sqrt. See imaged posted for the expected out come. Thank you!arrow_forwardPlease send me code for this assignment!! I will rate you good for sure!! Please send me as soon as possible!!arrow_forward
- Please explain the meaning of the Visual Basic word "Dim" by providing an example.Please use visual basic to describe the following terms and provide examples of their use in the attached forms. It has a "command" button, a "textbook," a "combination box," and "operation instructions."arrow_forwardBelow this question was asked and answered with the output to prove it works from an expert, but for some reason when I put the code into my MS Visual Studio 2019, C++ console for Windows 10 there appeared to be a warning at line 6 - int main(){. I received a warning under the word main (green squiggly line) and my output don't work for me as yours did for you. Do you think you can help me please. Could you please write in C++ according to instructions and criteria a program for the following: 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) You may or may 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…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education