How to sort input from a file without using an array?

Basically I need to write a program that reads in data from a file (ie. program.ccp < input_file) and do several things with the data without using an array for the scores specifically.

I need to take this data from external file:
28 80 81 35 47 60 82 77 58 36 37 62 70 68 86 79 63 64 54 57
69 54 65 74 82 68 56 89 0 26 60 76 47 61 52

And make the output look like the following:
Scores
  28  80  81  35  47  60  82  77  58  36  37  62  70  68  86
  79  63  64  54  57  69  54  65  74  82  68  56  89   0  26
  60  76  47  61  52

Descriptive Statistics
Number of non-zeroes =   34; Number of zeroes =    1        
Mean =  61.85;   Standard Deviation =  16.35

Score Distribution
      Score   Frequency   Cum Freq
         89         1                 1
         86         1                 2
         82         2                 4
         81         1                 5
  (and so on)

I am not allowed to use an array for the individual 'scores', however I can use an array for 'Frequency' and 'Cum Freq'.
int freq[MAX_SCORE], cum_freq[MAX_SCORE];

So I was able to take care of the output up until the score distribution. But now I am stuck as to how to manipulate the output at this point. The two allowable arrays seem easy enough, but how do I read in the input, sort (highest to lowest) and output in required columns? I thought 'bubble sort' required an array. How else can I sort an input variable without knowing the whole stream?

Here's my code so far, I appreciate any help.
int main(){
   cout << "Scores" << endl << endl;
   while ( cin >> score ) {
      score_count++;
      print_scores( score );
      total_score_calc( score );
   }
   cout << endl << endl << "Descriptive Statistics" << endl;
   mean_calc();
   print_stats();

} //end main

void print_scores( int xscore )
{
  cout << setw( 2 ) << xscore << " ";
  print_score_count++;
  if ( print_score_count >= VALUES_PER_LINE ){
     cout << endl;
     print_score_count = 0;
  }
}

void total_score_calc( int xscore )
{
  int xscore_square = 0;
  if ( xscore > 0 ){
     total_score = total_score + xscore;
     xscore_square = xscore * xscore;
     square_total = square_total + xscore_square;
  }
  else
     zero_count++;
}

void mean_calc( void )
{
  int square_mean;
  double mean_square;
  double temp_mean_cal;

  // Calculate mean
  mean_num = static_cast< double >(total_score) / (score_count - zero_count);

  // Calculate standard deviation
  square_mean = ((square_total) * (score_count - zero_count)) / ((score_count) * (score_count - 1));
  mean_square = ((total_score) * (total_score)) / ((score_count) * (score_count - 1));
  temp_mean_cal = static_cast< double >(square_mean) - static_cast< double >(mean_square);
  std_dev_num = sqrt( temp_mean_cal );
}

void print_stats( void )
{
  cout << "Number of non-zeroes =   " << (score_count - zero_count) << "; Number of zeroes =  " << zero_count << endl;
  cout << "Mean = " << setprecision( 4 ) << mean_num << ";    Standard Deviation =  " << setprecision( 4 ) << std_dev_num << endl;
}

m0neymanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
I take it you haven't been taught linked lists yet?
m0neymanAuthor Commented:
No, I have covered linked lists or classes yet.

The requirement says specifically:
The scores should NOT be read into an array. The score values themselves should be used to update any frequency arrays, but should not be stored in an array. In other words, there should only be a simple variable, say score, which will hold in turn each score value as you read through the data.

Also, The program should not contain any literal numeric constants except for -1, 0, 1, and 2.
SalteCommented:
Actually the problem can be solved without arrays, linked lists or any other collection.

However, this smell homework and I suggest you read again what you agreed to when you signed up to this site.

I can give you a few hints though.

1. To print out the scores you don't need an array, a single integer variable can be used to hold all the scores long enough that you can read it, use it to compute what you need to compute and print it out. Then you can read the next value into the same variable without storing in an array.

2. To compute averange or standard defviation you don't need all the values. To compute the mean you only need two variables and to compute the standard deviation you only need three variables.

Good luck with your homework.

Alf
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

grg99Commented:
You don't need to sort anything.

You only need to print out the scores in descending order.
But this is easy as you're allowed to have an array to hold the frequencies,
so you just index thru the array starting from the highest score down to the lowest.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
m0neymanAuthor Commented:
I got the standard deviation part, that is done. Sorry, but I am still confused on the frequencey arrays.

The 'frequency' array is only allowed to hold the value of the number of occurrences of a particular number not the score value itself. To add confusion the 'cumulative frequency' array is the number of scores that were greater than or equal to the score value.

1. I still don't see how I can output the input in descending order without an array. Is the 'cumulative frequency' array the key?

2. How do I index through the frequency array to get the scores? The 'frequency' array holds the values of the count of occurrances (1 or 2). How can I get a score value from the 'frequency' array?

Yes this is a homework assignment. I'm not asking for code, just how this will work logically, that is my roadblock.
m0neymanAuthor Commented:
Ok, I am making progress.

I was able to write the following code:
int main(){
   cout << "Scores" << endl << endl;
   while ( cin >> score ) {
      score_count++;
      freq_calc( score );
   }
   return 0;
} //end main

void freq_calc( int xscore )
{
  if ( score != 0 ){
     ++freq[ xscore ];
     cum_freq_num = cum_freq_num + freq[ xscore ];
     cout << setw( 6 ) << xscore << setw( 17 ) << freq[ xscore ] << setw( 24 ) << cum_freq_num << endl;
  }
}

This gives me the "Score Distribution" output I need, but not in descending order. Also, I need to add it into my original code and make sure it outputs last. Any suggestions?
m0neymanAuthor Commented:
Ah! I finally got it!!
Thanks for all you help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.