C++ :: Average And Median Of Arrays

Apr 12, 2013

I need to calculate the average and median of an array. I do not know how to put it in code.

View 1 Replies


ADVERTISEMENT

C++ :: Pointers (Average And Median)

Apr 29, 2014

Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user to enter the number of movies each student has seen. The program should then calculate the average, and median of the values entered.

My problem is that i keep getting a error box that says:
Run-Time Check Failure #2 - Stack around the variable 'sNUM' was corrupted.
and then my program shuts down!

This is what i have so far

Code:
#include <iostream>
#include <iomanip>
using namespace std;
void movAVG(int *, int);
void movMED(int *, int);
int main() {
int sNUM,
sARRAY,
*sARRAYptr;

[Code] ....

View 2 Replies View Related

C++ :: Compute Average Median And Mode For Numbers In Vector?

Feb 23, 2014

I needed to compute average median and mode for numbers in a vector. Im having a few issues I have already figured out how to calculate average and median just not mode. Also the program crashes when 0 is entered instead of exiting nicely. Also i keep getting a error on line 47 saying primary expression expected before else.

#include <iostream>
#include <conio.h>
#include <math.h>

[Code]....

View 7 Replies View Related

C++ :: Generate A List Of 200 Random Numbers - Determine Median / Mode And Average

Oct 24, 2013

I am just starting out programming and have an assignment due in the near future. the problem is I cant seem to figure it out. I started it already but got stuck cant seem to figure it out. Here is the assignment.

Create a program that will generate a list of 200 random numbers (ranging from 1-1000) and determine the medium, mode, and average of the list of numbers. Have the program display the original list ant then display the list in ascending and descending order on the screen.

View 2 Replies View Related

C++ :: Dynamic Arrays - Sort Input Data And Calculate Average

Jul 15, 2014

I'm still fairly new to c++ and am having trouble with dynamic arrays. My task is to create an array for test scores. The user needs to define the size of the array and then input data to later sort and calculate the average.

Below is what I have so far. I am struggling with the user input part. I receive the following errors for the data input of the individual scores:

"error C2108:subscript is not of integral type"
"IntelliSense:expression must have integral or unscoped enum type"

Code :

#include<iostream>
#include<iomanip>
using namespace std;
int main() {
//user input total number of scores
cout<<"Please enter the total number of test scores."<<endl<<endl;

[Code] ....

View 1 Replies View Related

C++ :: Pointers And Arrays - Program To Display Sorted List And Average Of Scores With Appropriate Headings

Apr 22, 2014

I am writing a class that dynamically allocates an array that holds a user-defined number of test scores (test scores go from 0 to 10 both included). Once all the test scores are entered and validated (values only between 0 and 10, both included), the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates theaverage of all the scores.The main program should display the sorted list of scores and the average of the scores with appropriate headings.

View 6 Replies View Related

C :: Print Correct Normalized Value / Average And Values Above Average

Nov 14, 2013

I must write a function that has a one dimensional double array and the number of values in the array as its arguments. Normalize the values. I must also print the maximum, minimum, average and numbers of values above the average in the array.

The equation that computes the normalized value from a value x is:

Normalized x= (x-min(array))/(max(array)-min(array))

My code does not print the correct normalized value, average and values above average.

Code:
#include <stdio.h>
int findMax( double array1[], int num_elements) // This function computes the maximum value of the array
{
int i, max=-32000;
for (i=0; i<num_elements; i++)

[Code] .....

View 5 Replies View Related

C++ :: Average Negative / Positive Numbers And Total Average?

Nov 18, 2013

I am trying to average the negative numbers and positive number and of course the total average.

This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.

vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);

[code]....

array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) {
int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
for (auto i : array) {
sum += i;
if (i > 0) { pos_sum += i; ++pos_count; }

[code]....

View 1 Replies View Related

C++ :: Find Median Of Array?

Jul 4, 2013

I am trying to find the median of an array in c++.

This is the array that I would like to find the median for.

scores[14] = {62,70,98,71,81,99,74,80,73,88,73,72,95,71};

View 5 Replies View Related

C++ :: Compute Mean / Median / Mode For Map Construct

May 28, 2013

I am writing code, which reads an input file (280 MB) containing a list of words. I would like to compute

1) total # of words
2) total # of unique/distinct words
3) mean/median/mode of word count (Link)

I managed to get done with 1) and 2), but my program crashes for 3). I am not quite sure whether there are memory issues or some bug in the code.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

[Code] .....

View 2 Replies View Related

C++ :: How To Make Median Display As Double

Feb 8, 2015

How do i make the median display as a double?

#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int main {
int* randomArray(int, int); /*This function creates an array of random numbers
of a given size within a given range*/

[Code]...

View 2 Replies View Related

C++ :: Sorting And Calculating Median Of A Vector?

Dec 1, 2014

I am trying to to pull data from a file into a vector, then calculate different statistics from said vector. I've got everything working great except for one part. The program requires the median be calculated, which means I need to sort the data in the vector. However I can't do a quick easy sort, I'm required to use the functions swap(double, double), sort(vector), and index_of_smallest.

how to get these all working in sync to calculate the median(not to mention my algorithms appear to be wrong as I return nothing but 0's for the median value.)

I'm either not sorting right, or the index_of_smallest function is supposed to be doing something I don't realize.

#include <iostream> // for screen and kbd io
#include <iomanip>
#include <fstream> // file io
#include <cstdlib> // for exit()
#include <cmath> // for sqrt
#include <string>
#include <vector>
using namespace std;
void fill_vector(ifstream& in_file,vector<double>& v);

[code]...

View 1 Replies View Related

C/C++ :: Two Dimensional Array Median Filtering?

Nov 12, 2014

I'm trying to write code that implements [median filtering] on a two-dimensional array.

Here's an image to illustrate:

The program starts at the beginning of the array. The maximum array size is 100. I know that I can use an array like:

int a[100][100];

to store the input, and that I can iterate over a part of this array using two `for` loops like this:

for(i=0;i<size_filter;i++)
for(j=0;j<size_filter;j++)
temp[i][j]=a[i][j] // not so sure

But how can I make this code loop over the neighbors of every element in the array, calculate their median, and replace the center element with the median?

For some examples of what I'm trying to do, let's say that the input is a 5x5 matrix, so the input size is 5. And I want to run a 3x3 median filter on it, i.e. each element should be replaced by the median of the 3x3 elements surrounding it.

The program starts at the corner index (0,0). For this index, it scans the 3x3 region surrounding it (of which only four indexes actually lie within the input array), which contains the values 0, 0, 1, and 0. The median of these values is 0, so that's what the code should output for this array index.

In the picture below, the number in -band - is the center cell, and the plain * and * numbers are its neighbors within the 3x3 region surrounding it:

-0- *0* 0 0 0
*1* *0* 0 1 0
1 1 0 0 0
0 1 1 0 0
0 0 0 0 0

Here's another example, this time with the center index (0,1):

*0* -0- *0* 0 0
*1* *0* *0* 1 0
1 1 0 0 0
0 1 1 0 0
0 0 0 0 0

This time, the elements in the 3x3 region (excluding those outside the input array) have the values 0, 0, 0, 1, 0, and 0, and again, their median is therefore 0.

Here's yet another example, this time from the middle of the input, at center index (3,2):

0 0 0 0 0
*1* *0* *0* 1 0
*1* -1- *0* 0 0
*0* *1* *1* 0 0
0 0 0 0 0

This time, the elements within the 3x3 region have the values 1, 0, 0, 1, 1, 0, 0, 1, and 1, and their median in therefore 1.

Final example:

<size of array><size filter> <data>
8
3
0 0 0 0 0 0 0 0
0 5 0 0 6 0 0 0
0 0 0 0 0 7 0 0
0 0 0 0 5 0 0 0
0 0 0 5 6 0 0 0
0 0 8 5 5 0 0 0
0 0 0 7 0 0 9 0
0 0 0 0 0 0 0 0

Output:

0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 5 5 0 0 0
0 0 0 5 5 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

View 4 Replies View Related

C++ :: Calculate Mode / Mean And Median Of Array Of Integers

Mar 17, 2013

I'm writing a program that calculates the mode, mean and median of an array of integers. I've done the mean and median but i can't figure out mode.

I have to find the number of modes.

Ex array of integers: 10, 10, 4, 5, 6,5, 6, 7

My function has to return the number 3. Because there are 3 sets of mode; 10,5,6.

How do i implement this in my function because for now it just calculates the mode. It only return the number mode 10.

View 5 Replies View Related

C/C++ :: Find Minimum - Getting Median And Mode In Array

Feb 7, 2015

So I am trying to find the min, max, range, mean, median, and mode. The max number is right but the min isnt. Once that is corrected, i can get range and mean easily. Also, how to get mode and median. I am guessing the values in the arr2 would have to be sorted. This refers to the values in arr2 which are the calculated values in the formula. You can enter -2 and 2 for userMin and userMax.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << fixed << setprecision(1);
float userMin;

[Code] .....

View 13 Replies View Related

C++ :: Create Program That Displays Median Of Array Using Pointers

Feb 27, 2013

The assignment is to create a program that displays the median of an array using pointers. Assume the array is already in ascending or descending order.I'm getting errors currently on the bottom two "return median;" statements.The code that I have so far is as follows...

#include <iostream>
using namespace std;
char again;
int getMedian(int*, int);
const int constant = 100;

[code]....

View 3 Replies View Related

C/C++ :: Calculating Median And Mode In Movie Statistics Program

May 5, 2014

I am having trouble calculating the median and mode in a program that I am writing. When I run the program, lets say there are 5 students being surveyed. The input is as follows, Student #1 sees 2 movies, student #2 sees 6,student #3 sees 5 movies, student #4 sees 2 movies, and student #5 sees 1 movie. However, for the median, I get 5, because that is at element 2, and thus midway through the count, so the program interprets that number as the median. For the mode, even though 5 is repeated twice, the program displays that there was no mode, or displays "-1" (indicating no mode). Here is my code:

Write a program that can be used to gather statistical data about the number of movies college students see in a month. The program should perform the following steps:

A) Ask the user how many students were surveyed. An array of integers with this many elements then be dynamically allocated.

B)/> Allow the user to enter the number of movies each student saw into the array.

C) Calculate and display the average, median, and mode of the values entered.

Input Validation: Do not accept negative numbers for input.

#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double calculateMean(int *, int);
double calculateMedian(int *, int);
int calculateMode(int *, int);

[Code] .....

View 2 Replies View Related

C/C++ :: Find Median Of Array Of 5 Values - No Instance Of Overloaded Function

Mar 12, 2014

I am so close to finishing this program. It will find the median of an array of 5 values. I have one last error that I cannot seem to get to go away. Here's the code:

#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
using namespace std;
int main() {
int integer1, integer2, integer3, integer4, integer5;

[Code] .....

The error states: "IntelliSense: no instance of overloaded function "std::nth_element" matches the argument list, argument types are: (std::_Array_iterator, std::_Array_iterator, unsigned int, std::_Array_iterator)

View 1 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C++ :: Passing 2 Dimensional Array Through Median Function To One Of 2 Other Function

Aug 20, 2013

I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function

#include <iostream>
#define random(x)(rand()%x) // for random number between numbers of 0 and 1
using namespace std;
void proc1 (int iArray[][2]);
void proc2 (int iArray[][2]);
void selectfunction(int iArray[][2]);
int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };

[Code]...

View 1 Replies View Related

C++ :: Using Arrays As Sources Of Data For Arrays In A Structure?

Feb 6, 2014

I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

Code:

int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS

[Code]....

View 2 Replies View Related

C :: Assigning Values To Arrays / Printing Arrays

Jul 1, 2014

Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.

I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] .....

View 3 Replies View Related

C++ :: Ranged For Loop With Arrays Of Arrays

Dec 17, 2014

int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }

Why do we name it row instead column?

int arr[row][column]

Wouldn't this be like

int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}

It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?

View 2 Replies View Related

C/C++ :: Keep Getting 0 For Average

Feb 6, 2015

#include <iostream>
using namespace std;
int num_ints;
int num_doubles;
double running_total;
double average;

[Code] .....

View 1 Replies View Related

C :: How To Get Average Of Program

Mar 20, 2013

Cannot divide the real output of the AVERAGE.:

Code:

#include<stdio.h>
#include<conio.h>
struct student
{
char Name[50];

[Code]....

View 7 Replies View Related

C++ :: Getting Average Value Of Array In Function

Nov 29, 2014

How to power value in function too.

View 2 Replies View Related







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