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 program code below. I have sent the entire question and answer below. 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 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; } check_circle Expert Answer thumb_up   thumb_down Step 1 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. Step 2 Code: #include #include // 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

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

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 program code below. I have sent the entire question and answer below.

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:

  1. an array of integers.
  2. B) An integer that indicates the number of elements in the array and returns a vector of integers.
  3. 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;

}

check_circle

Expert Answer

thumb_up
 
thumb_down
Step 1

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.

Step 2

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Multimedia tools and applications
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