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
Guinness -
#include <iostream>
-
#include <iomanip>
-
#include <cstdlib>
-
#include <fstream>
-
-
using namespace std;
-
-
void open_input_file(ifstream &inf);
-
-
int main()
-
{
-
ifstream from_file;
-
open_input_file(from_file);
-
-
int i=0;
-
int j=0;
-
int f[30];
-
int a=0;
-
-
for(j=0;j<=29; j++)
-
{
-
f[j]=0;
-
}
-
-
from_file>>a;
-
int mode=f[0];
-
while(!from_file.eof())
-
{
-
i=a;
-
-
f[i]=f[i]+1;
-
cout<<i<<" "<<f[i]<<" "<<mode<<endl;
-
from_file>>a;
-
}
-
-
void open_input_file(ifstream &inf)
-
{
-
char input_file_name[80];
-
-
do
-
{ inf.clear();
-
cout<<"Enter input file name: ";
-
cin>>input_file_name;
-
inf.open(input_file_name);
-
} while (inf.fail());
-
}
1 4907
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...
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: 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: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |