Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hints: Sort the elements in the array to find the minimum and maximum values. To

ID: 3582864 • Letter: H

Question

Hints: Sort the elements in the array to find the minimum and maximum values.
To find the value that occurs the most, use a two-dimensional array to store the number of occurrences for each value.
Problem 2: Write a C++ program that prompts the user to input 10 integer values. The program should display the minimum and maximum of those values. The program also should display the value that occurs the most and the number of occurrences. Hints: Sort the elements in the array to find the minimum and maximum values To find the value that occurs the most, use a two-dimensional array to store the number of occurrences for each value. Sample input/output "CAUsers 101512NDesktopATeachingNCourses 1411-116 Programming NHwstHw3VQ2-exe Enter 10 integer values ualuee IM value 1 10 value 2 ualuee 3 17 value A 25 value S value 6 value 7 8 value 8 value 9 8 The maxi value The minimum value The most occurring value is It occurs 3 times Process returned C0x0> execution time 47.659 s Press any key to continue

Explanation / Answer

#include<iostream>

using namespace std;

int main () //start of main fcn
{

int values[ 10 ]; //delcares array and how many elements
int small,big; //declares integer
for ( int i = 0; i < 10; i++ ) //counts to 10 and prompts user for value and stores it
{
cout << "Enter value " << i << ": ";
cin >> values[i];
}
big=small=values[0]; //assigns element to be highest or lowest value
for (int i = 0; i < 10; i++) //works out bigggest number
{
if(values[i]>big) //compare biggest value with current element
{
big=values[i];
}
if(values[i]<small) //compares smallest value with current element
{
small=values[i];
}
}
cout << "The biggest number is " << big << endl; //prints outs biggest no
cout << "The smallest number is " << small << endl; //prints out smalles no

unsigned int store[10] = {}; // large enough to hold the largest array value,
// initialized to zero

for (int n : values)
++store[n]; // update counts

for (int i = 0; i != 10; ++i)
{
std::cout << "Frequency of int " << i << " is " << store[i] << " ";
}
}

There might be some minor errors but that varies complier to compiler

You can also use map to solve this problem

after finding out the the smallest and largest number

ou may use a map first to store num->frequency and then a multimap to store freqeuncy => num.

Here is the working solution.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote