473,372 Members | 1,157 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

C++ Frequency, median, and mode without using arrays

hi I'm supposed to do a frequency array and find mode,median and count, but without storing the actual data in an array. I am able to build a frequency array but I can't return the mode since I am not supposed to store the actual value in an array. Please help me with this problem.
Thank you
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <fstream>
  6. using namespace std;
  8. void open_input_file(ifstream &inf);
  10. int main()
  11. {
  12.  ifstream from_file;
  13.  open_input_file(from_file);
  15.  int i=0;
  16.  int j=0;
  17.  int f[30];
  18.  int a=0;
  20.  for(j=0;j<=29; j++)
  21.  {
  22.   f[j]=0;
  23.  }
  25.  from_file>>a;
  26.  int mode=f[0];
  27.  while(!from_file.eof())
  28.  {
  29.   i=a;
  31.   f[i]=f[i]+1;
  32.   cout<<i<<"  "<<f[i]<<"       "<<mode<<endl;
  33.   from_file>>a;
  34.  }
  36. void open_input_file(ifstream &inf)
  37. {
  38.  char input_file_name[80];
  40.  do
  41.  { inf.clear();
  42.    cout<<"Enter input file name: ";
  43.    cin>>input_file_name;
  44.    inf.open(input_file_name);
  45.  } while (inf.fail());
  46. }
Nov 14 '07 #1
1 4905
4,677 Expert Mod 4TB
If you're not worried about efficiency, you can take each individual number, go through and count how many times it occurs, hold both of them aside, and then get the next, count how many times it occurs, compare it to the last. If it's larger, move the new into the old, and get the next, etc...
Nov 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: nick.vitone | last post by:
Hi, I'm somewhat of a novice at Access, and I have no experience programming whatsoever. I'm attempting to calculate the statistical median in a query. I need to "Group by" one column and find...
by: Drebin | last post by:
I'm looking for mean, median, mode and standard deviation - maybe a couple methods that take in an array of floats or something?? Thanks much!
by: uspensky | last post by:
I have a table (cars) with 3 fields: VIN, Class, sell_price 101, sports, 10000 102, sports, 11000 103, luxury, 9000 104, sports, 11000 105, sports, 11000 106, luxury, 5000 107, sports, 11000
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new...
by: Yannick Tremblay | last post by:
Hi, I have a std::map<id, timestampcollection. The id is the normal reference so the key-value ordering is correct. However, once in a blue moon, I want to prune this collection. So that...
by: Scott | last post by:
I need to take the median from a field of records in a report. Can someone shed the light how to do it. Thanks, Scott
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
by: zfareed | last post by:
I created a program to determine the medians of arrays, be it of type int or float. I have used a template function and the problem I'm having is returning the float median for even arrays. Can...
by: mehwishobaid | last post by:
i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.