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

Create the following program using C++ This following is the example of a partia

ID: 3868043 • Letter: C

Question

Create the following program using C++

This following is the example of a partially filled array (page 536)

of type integer numbers.txt (click to download) a The file can contain up to 50 numbers which means that you should use a partially filled array ike example on page 536. Your program should call a function to sort the array in descending order, from highest to lowest. This function should have two parameters: the array of integers and the last used index. For example, if the file has 42 numbers, then the last used index should be 41. The sort function should not sort the entire array, only up to the last used index. Finally, your program should call another function to display the frequency of numbers (count of occurrences) in the array. For example, if the input array from file is, -12 3-12 411-121-1123 4 23-12 the output should be, N Count -12 4 Important: your program will be tested with files containing different sequences of integers

Explanation / Answer

#include<iostream>
#include<fstream>

using namespace std;

void sort (int input[], int count){
    int i,j;
    int temp;

     for (i=0; i<=count; i++){
        for (j=i; j<=count; j++){
            if (input[i] < input[j]){
               temp = input[i];
               input[i] = input[j];
               input[j] = temp;
            }
        }
     }
}

void frequency (int input[], int count){
    int i,j;
    int temp;
    int freq;
    int a[50];
    int found;

     cout << "N" << "   " << "Count" << endl;
     for (i=0; i<=count; i++){
        freq = 0;
        if (i > 0){
           if (input[i] == input[i-1])
              continue;
        }
        for (j=0; j<=count; j++){
              if (input[i] == input[j]){
                  freq++;
               }
        }
        cout << input[i] << "   " << freq << endl;
     }
}


int main(){

   ifstream fin;
   int input[50];
   int count;
   int temp;

   fin.open("numbers.txt");
   if (fin){
     count = 0;
     while (fin >> input[count])
           count++;
     sort(input,count-1);
     frequency(input,count-1);
    
   }
   else {
      cout << "Error in opening file" << endl;
   }
   return 0;
}

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