C/C++ :: Statistical Analysis Of Vector Data Set Of Integers - Frequency Distribution?

Feb 16, 2014

I am working on my second c++ project that is a statistical analysis of a vector data set of integers. I created a struct called range with a maximum value, minimum value and count for occurrence. The frequencies are stored in a vector<range>.

I have tried messing around with the increment to get the high range test above the maximum element, though my ranges cumulatively increase by 9.9. I'm not sure how the professor's program has the distance between high and low ranges as 10 instead of 9.9, which is the increment. I'm also unsure why half way through his buckets, the ranges appear as 9.99 briefly and then return to 10 after (40.00 - 49.99 then 49.99 - 59.99). I feel like I am missing something very obvious on line 04 or 10 in my code.

Here is the code for the frequency that accepts a vector reference for my data set of integers.

void frequency(vector<int>& data_set){
double max = findMax(data_set);
double min = findMin(data_set);
double increment = (max - min) / 10;
double percentage = 0.0;

[Code] ....

View 1 Replies


ADVERTISEMENT

C/C++ :: Frequency Distribution - Finds All Numbers In Array That Show Up Exactly 5 Times

Oct 9, 2014

Create a program that finds all numbers in an array that show up exactly 5 times. I am trying to solve this issue by making a frequency distribution via two loops and two arrays, but I am having trouble getting my loop to not recount a number it has already counted.

For example, if you enter ten 1's into the "entered Numbers" array I want it to store a count of 10 in frequencyarray[1]. Instead it is storing

frequencyarray[0]10
frequencyarray[1]9
frequencyarray[2]8
etc...

#include <iostream>
using namespace std;
void enternumber(long[], int);
int main() {
int size;
int numbers5=0;

[Code] .....

View 14 Replies View Related

C++ :: Letter Frequency For A Vector

Nov 9, 2013

I am trying to print out the letter frequency of a vector that the user inputs and what number that letter is in the ASCII. I am supposed to say, for example: "w" which is ASCII 119 occurs 2 times. How to do this?

View 1 Replies View Related

C++ :: Triangular Distribution For Creating Momentum Four Vector

Nov 12, 2014

In my problem I am to create a base class to represent a four vector (a concept in physics involving a four dimensional vector) then create a derived class specifically to represent the four momentum of a particle which inherits from the base class. I have been supplied a small piece of code to use to generate a 'random' x y and z component of the momentum magnitude. The code is as follows

#include <cstdlib>
double triangular(double momentum){
double x, y;
do{
x = momentum*rand()/RAND_MAX;
y = x/momentum;
} while (1.0*rand()/RAND_MAX > y);
return x;
}

It is said in my problem that this code is supposed to generate the magnitude, and then randomly split into x, y and z components. This code returns a single value and so I cannot see how it is doing what it says in the problem.

View 2 Replies View Related

C++ :: Normal Distribution Range - Select Objects On A Vector

May 23, 2014

I'm implementing an normal_distribution to select objects on a vector. The thing is I can't use values greater then 1 or less then -1. Here is what could be done:

gausx=gaus_distributionx(generator);
while((gausx>1) || (gausx<-1))
gausx=gaus_distributionx(generator);

The question is if the distribution would loose it's power to be a normal distribution, because some of the gerated numbers wouldn't be used. Any way to set ranges for the distribution?

View 6 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C++ :: Vector With Strings And Integers

Apr 5, 2013

I have a file where the first column shows letters, second column shows numbers.

How could I make it to print everything exactly how it is in the file – a vector/array with strings and integers?

View 13 Replies View Related

C++ :: How To Make 5x3 2D Vector Of Integers

Feb 8, 2014

I am trying to make a 5x3 2D-vector of integers, then set its i-capacity to be 5 and j-capacity to be 3, i.e:

vec2D[i][j] i = 1,2,3,4,5 j = 1,2,3

and then assign integer values to it.

#include <vector>
#include <iostream>
using namespace std;
int main () {
vector<vector<int> > vec2D;

[Code] ....

It compiles, but does not work properly:

Test.exe exited with code -1073741819

i-capacity before reserve: 0
i-capacity after reserve: 5

i = 0
j-capacity before reserve: 336043326
j-capacity after reserve: 336043326
i = 1
j-capacity before reserve: 4282929217
j-capacity after reserve: 4282929217
Press <RETURN> to close this window...

I am trying to convert a C code with dynamic 2D arrays, to a C++ code. I prefer to keep the vec2D[i][j] = ... way of assignment instead of using vec2D.push_back(...).

View 8 Replies View Related

C++ :: Vector Of Integers - How To Print Indicators

Apr 8, 2014

I have a vector of integers, which can take values 0 or 1, say

0 0 0 1 1

I need to print indicators, telling in which position 1-values occur. So

0 0 0 1 0
and
0 0 0 0 1

View 11 Replies View Related

C++ :: Program To Create A Vector Of Integers

Feb 10, 2015

1. Write a c++ program to create a vector of integers. copy the vector contents into list, sort the contents, then copy selected items into another vector(like elements less than 10 etc)

View 1 Replies View Related

C :: Binary Tree - Return A Vector Of Integers

Oct 19, 2014

So I have a Binary Tree and I need to return a vector of integers (the nodes) of the heaviest path in the tree.

First, is it possible to do in C? Because I think a vector is an ADT in C++.

I've started writing something recursive, which worked for a balanced tree of height 1, and failed for longer height.

This is what I've written - [URL] ....

View 6 Replies View Related

C++ :: Generate Random Integers In The Range And Store Them In A Vector

Sep 3, 2014

You are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000 ] and to store them in a vector < int > of size VEC_SIZE = 250. Then, sort the contents of the vector (in ascending order) and display it on stdout.

To sort the contents of a vector, use the sort ( ) function from the STL. In addition to the main ( ) routine, implement the following subroutines in your program:

• void genRndNums ( vector < int >& v ) : This routine generates VEC_SIZE integers and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value SEED = 1, and generates random integers by calling the function rand ( ).

• void printVec ( const vector < int >& v ) : This routine displays the contents of vector v on stdout, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on stdout.

Programming Notes:

• You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout.
• Let v be a vector of integers, then the call: sort ( v.begin ( ), v.end ( ) ) sorts the elements of v in ascending order. The detailed description of the sort ( ) routine can be found on the course web site and in the course textbook.
• Execute the srand ( ) function only once before generating the first random integer with the given seed value SEED. The rand ( ) function generates a random integer in the range [ 0, RAND_MAX ], where the constant value RAND_MAX is the largest random integer returned by the rand ( ) function and its value is system dependent. To normalize the return value to a value in the range [ LOW, HIGH ], execute: rand ( ) % ( HIGH – LOW + 1 ) + LOW.

View 1 Replies View Related

C++ :: Sorting Large Numbers Of Vector Of Random Integers Returns All Zero

Jul 31, 2014

I tried to sort a large numbers of vector of random integers with std::sort(), but when the number increases over 10M, std::sort returns all zero in values. Does std::sort have a limitation of input numbers?

View 1 Replies View Related

C/C++ :: Analysis And Evaluation Algorithms?

Mar 25, 2015

#include <iostream>
#include <vector>
#include <list>

[Code].....

The problem is it's not finding the shortest path.

View 1 Replies View Related

C :: Textual Analysis - Pattern Matching

Feb 11, 2014

I am looking to write a program that, given a particular word, looks at a plain text document and gives a list of words that appear within x words of the given word along with a count of how many times it appears.

Do I need to use regex to do the pattern matching here? Is there a particular data structure that I should use that is particularly suited to a task like this? I don't want to reinvent the wheel, it seems like there should be libraries that would already do this sort of thing but searches have turned up nothing.

View 5 Replies View Related

Visual C++ :: Analysis And Evaluation Algorithms

Mar 25, 2015

Undirected graph G = {V, E} is given by the list next to the DS. Let u, v of V. Construction of two paths algorithm A1 (u, v) and A2 (u, v) such that no edge in common and have the shortest total length.

View 1 Replies View Related

C++ :: Floating Point Numbers / Numerical Analysis

Oct 30, 2013

I have the problem of trying to find the smallest natural number that makes two consecutive terms in single precision floating point notation in the riemann zeta function equal. So basically the riemann function of 2 is given by:

sum of 1/(k^2) from k=1 until infinity, so : 1/(1^2) + 1/(2^2) + 1/(3^2) + ...... until infinity.

Now the question asks to stop at the smallest natural number n, at which the sum 1/1^2 + 1/2^2 + ......+ 1/(n^2) is equal to the sum 1/1^2 + 1/2^2 + ..... + 1/((n+1)^2) in single precision floating point notation.

Now well the obvious way to look for n would be on this way:

float i = 1.0;
float n = 1/(i);
float n1 = 1/(i+1.0);
while ( n != n1){
i += 1.0;
n = 1/i;
n1 = 1/(i+1.0);}

But first of all this is obviously completely inefficient and I dont think it will yield a valid answer for any float variable, i.e. I dont think the sum until 1/n^2 and 1/(n+1)^2 will ever differ. I tried it out with the largest possible value of a variable of type float and the values were still seen as unequal in C++. How to do this? Will C++ find a value for n for which the condition holds? Is the compiler or my hardware important for this, i.e. would I get different results on a different pc?

View 2 Replies View Related

C++ :: Library (Eigen / Boost) To Calculate Principle Component Analysis (PCA)?

Mar 4, 2013

I have a text file which consists of 907 objects and 1000 feature vector for each object. Is there any Library (Eigen/Boost) to calculate Principle Component Analysis(PCA)?

View 1 Replies View Related

C++ :: Analysis Of Discrete Wavelet Transform - Modifying For Loop To Make It Faster

Aug 25, 2014

I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.

int rows = signal.size();
int cols = signal[0].size();
int cols_lp1 =(int) ceil( (double) cols / 2);
vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
vector<double> temp_row;
temp_row.reserve(512);

[Code] ....

View 5 Replies View Related

C++ :: Letter Frequency Count

Nov 13, 2013

I am new to c++. I am writing a program that reads in a text file and gives a count of how many times each letter appeared in the file. I got it to read the text file and do the letter count. B

X = 102
Y = 126
Z = 165
etc...

THAT IS WORNG

The sample output should be
E = 165
T = 126
A = 102
O = 93
etc...

I got it to sort from lowest to highest for the frequency, but cant seem to get the appropriate letter assigned to it.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

[code].....

View 1 Replies View Related

C++ :: Word Frequency In A Text

Dec 7, 2013

This program counts how many times does a word appear in a text. Why i have to add 1 to p in the while loop?

#include <iostream>
#include <cstring>
using namespace std;
char s[200], c1[20], *p;
int main() {
int k=0;

[Code] ....

View 1 Replies View Related

C++ :: Completely Random Distribution Of Numbers

Feb 5, 2014

I'm looking to code a completely random distribution of numbers that doesn't affect performance using rand. I believe this code would be ideal but I don't understand how to use it. Where would I input the range of numbers and the quantity?

double uniform_deviate ( int seed ){
return seed * ( 1.0 / ( RAND_MAX + 1.0 ) );
} int r = M + uniform_deviate ( rand() ) * ( N - M );

And for the seed...

unsigned time_seed(){
time_t now = time ( 0 );
unsigned char *p = (unsigned char *)&now;
unsigned seed = 0;
size_t i;
for ( i = 0; i < sizeof now; i++ )
seed = seed * ( UCHAR_MAX + 2U ) + p[i];
return seed;
} srand ( time_seed() );

View 2 Replies View Related

C++ :: Accessing Poisson Distribution Template?

Jun 21, 2013

I am using QT Creator 2.4.1 based on 4.7.4.

I wanted to generate a standard normal poisson distribution. So I used the template poisson distribution included in the header <random> by setting the value of mean to 0 and variance to 1.

I copied the entire example code for testing it but I get an error like "This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options."

View 4 Replies View Related

Visual C++ :: CPP High Frequency Trading

Jul 15, 2014

I have taken a keen interest in writing trading programs. I have some Python background, a little C# but no C++.

The example below was provided in a book on HFT and I would love to see how the results look. I was hoping that I would just compile it and away you go!

That didn't happen. To start with the author listed this as a function, so I converted it to a main program. Still having issues with my path and where to see the output. Here it is..

Code

void HFT_AvellanedaStoikov() {
FILE* fin, *fout;
double lambda_a, lambda_b, d_lambda_a, d_lambda_b;
int hh = 0, mm = 0, ss, nb = 0, na = 0, prevnb = 0, prevna = 0, prevm = 0;
double bid, ask, prevbid = 0, prevask = 0;
char * p1, *p2, buffer[1024], fname[512];

[Code] .....

Here is some data:

14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
.... and so on ....

View 3 Replies View Related

C++ :: Data Corruption In Vector

May 2, 2013

I have this code that is supposed to store numbers in one vector and another vector stores pointers to the values in the first vector:

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <cstdio>

[Code] ....

However, when I print out the values stored by the pointer vector, the first 2 values are not the same as what the input was. I have tried it with 4 - 10 values and always, the first 2 are not the same as the input but the rest are. I tried printing out the values as they are stored in the vector in the first for-loop and it seems to contain them all, but after that first for-loop, when I try to print *station.front(), it is now changed to something else.

input:
4
1231 234354 4544343 121312

output:
34144320 0 4544343 121312

input:
6
123 2435 353 12221 356567 4544452

output:
21704768 0 353 12221 356567 4544452

View 9 Replies View Related

C++ :: How To Push Data Into The Vector

Apr 20, 2013

How can push data into the vector <list<Edge>> adjList? adjList[n].push_back (e);//gives error.

struct Edge {
int from_node_number;
int to_node_number;
int weight;
};
vector <list<Edge>> adjList;
Edge e;
for (int n=0; n< graph.size(); n++)
adjList[n].push_back (e);

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved