#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<fstream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
bool comparator( const std::pair<int, int> &left, const std::pair<int, int> &right )
{
return ( left.first > right.first);
}
void CalculateFrequency(int *arr , int n )
{
vector< pair<int,int> > moves;
pair<int,int> position;
for(int i=0;i<n;++i){ //iterate through array
bool flag= false; //check if encounter duplicates
size_t x=0;
for ( ; x < moves.size(); ++x ) { //iterate the vector
if(moves[x].first == arr[i]){
moves[x].second++;
flag = true;
break;
}
}
if(!flag){
position.first = arr[i];
position.second = 1;
moves.push_back(std::make_pair(position.first, position.second)); //Make pair i.e first element as array element and 2nd element as Count
}
}
sort(moves.begin() , moves.end(), comparator); //Sort the pair in descending order using comparator
cout << " N" <<" " << "Count" << endl;
for ( size_t x = 0; x < moves.size(); ++x ) { //Print Output
printf(" %d\t%d\n",moves[x].first ,moves[x].second);
}
}
int main ()
{
char choice;
while(true ) {
printf("Enter Your choice\n" ) ;
printf("1. Take input from the Keyboard\n");
printf("2. Take Input from the File\n");
printf("3. Exit\n" ) ;
scanf("%c",&choice);
string filename;
int n, count=0;
int *arr;
ifstream File;
switch(choice)
{
case '1' :
printf("Enter the number of elements\n");
scanf("%d",&n);
arr = (int *)malloc(n*sizeof(int));
for(int i=0;i<n;++i)
{
if(i==0)
printf("Enter %dst element: ", (i+1) );
else if(i==1)
printf("Enter %dnd element: ", (i+1) );
else if(i==2)
printf("Enter %drd element: ", (i+1) );
else
printf("Enter %dth element: ", (i+1) );
scanf("%d",&arr[i]);
}
CalculateFrequency(arr, n);
break;
case '2':
printf("Enter the name of file\n");
cin>>filename;
int a;
File.open(filename);
while (File >> a){
++count;
}
File.close();
File.open(filename);
arr = (int *)malloc(count*sizeof(int));
for(int a = 0; a < count; a++)
File >> arr[a];
CalculateFrequency(arr, count);
break;
case '3':
exit(0);
break;
default:
printf("Wrong Choice\n");
}
}
return 0;
}
=================================================================================
Adding Images, Comments and Output for more clarity

Output
Thanks, Let me know if there is
any concern. Please provide feedback.
Attaching more Images



MORE RUNS

Let me know your concern.
In C++ Sorted List of User Entered Numbers 2. Write a program that reads in a...
C++ Programming question
Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...
:Pls help for this programing problem in c++ (standard IO
without file read/write),better with some comment about why coding
that way,thanks
Problem A: Counting Numbers Problem Description Write a program that reads numbers from the keyboard into an integer array. You may assume that there will be 50 or fewer entries in the array. Your program allows any number of numbers to be entered, up to 50 numbers. The output is to be a two-column list. The first column is...
In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.
Please and thank you
2) (5 pts) Arrays & Vectors: write a program which prompts the user to enter numbers (terminated with a non-numeric), reads them simultaneously into an array of doubles and into a vector of doubles, then prints A) the array elements in the original order B) the vector elements in reverse order C) the average of the vector elements D) the largest of the vector elements Example program output, user input shown underlined Enter a list of...
Write a complete C++ program to ask the user to enter 4
integers. The program must use a function
to find the smallest integer among them and print it on the screen.
Typical output screen should be as following:
Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...
using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: must use loops and numbers to do this 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
Write a program that reads integers, finds the smallest of them, and counts its occurrences. Assume that the input ends with number -1. Suppose that you entered 4 2 9 2 2 -1; the program finds that the smallest is 2 and the occurrence count for 2 is 3. (Hint: Maintain two variables, min and count. min stores the current min number, and count stores its occurrences. Initially, assign the first number to min and 1 to count. Compare each...
This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...
[C++] Write a program that reads a list of integers, and outputs those integers in reverse. You must use an array for this lab. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Ex: If the input is: 5 2 4 6 8 10 the output is: 10 8 6 4 2 5 To achieve the above, first read the integers into...