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
ADVERTISEMENT
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
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
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
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
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
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
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
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
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
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
May 2, 2014
I have to find mean,mode and median of a 2-D array :
2 5 2 5 9 5 8 3 6 10
8 1 10 10 7 1 4 4 3 8
4 3 1 2 4 10 3 9 8 5
6 10 8 3 6 10 5 1 2 5
2 2 9 2 5 5 1 1 7 5
7 9 9 2 1 5 2 2 2 4
3 6 1 9 3 4 10 7 4 6
7 10 4 6 2 10 10 8 7 6
7 1 3 6 2 4 6 7 8 9
8 5 9 2 3 2 1 5 1 8
I coded for mean but stuck for mode.
Code:
// Assign4_Q2.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
[Code] ......
View 10 Replies
View Related
Mar 20, 2014
I've been trying for over an hour to think of the logic to find the mode of an array.I left out code for initializing the arrays, but all the values in the array are between 0-9. Check out my code below.
Code:
int mode( int array[], int size ) {
int i;
int count;
int max = 0;
int num = 0;
int mode;
[code]....
View 7 Replies
View Related
Feb 6, 2014
How do you find a mode in array? This is what i got so far. I put this after i sort the array
for (int index = 0; index < size2; index ++) {
//count[mode[index] - 1]++;
if (mode[index] == mode[index + 1]) // compare the first to sec array {
again++;
cout <<"This is number " << again << endl;
}
}
View 1 Replies
View Related
Sep 14, 2014
I've been working to make program to find the mode of sorted array. But the program didn't return the results correctly. Here is the code:
#include <iostream>
using namespace std;
int main () {
cout<<"Enter the size"<<endl;
int size;
cin>>size;
int data [size];
[code]....
View 14 Replies
View Related
Sep 9, 2013
I have to use numbers in my .txt file that are stored in an array. So i have to write a function to find the mode of the numbers in my array.
View 5 Replies
View Related
Oct 20, 2014
My code seems to find the mode of the array I input sometimes. Sometimes it gives me the wrong number or multiple numbers. It just all depends on what is number is inputted into the array. I don't know what the problem is. I tried looking online and editing many times and can't find the answer. Maybe I'm overlooking something or doing something wrong. Here's my code.
#include <stdio.h>
void readArray(int arr[], int length)
{
printf("Enter data:
");
[Code].....
Maximum: 15
Mode: 2
As you can see the mode is clearly not 2 and I do not know why.
View 8 Replies
View Related
Sep 14, 2014
I've been working on my program to find mode of sorted array. But the program didn't return the res
#include <iostream>
using namespace std;
int main () {
cout<<"Enter the size"<<endl;
int size;
cin>>size;
int data [size];
[Code] ....
View 1 Replies
View Related
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
Sep 27, 2013
I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :
1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
"
View 7 Replies
View Related
Jun 7, 2014
Objective: Write a function with the given signature that will take a sorted array of integers and return the array compacted. That is, given an array containing: 1, 2, 6, 8, 8, 8, 9, 10, 10, when the function returns, the contents of the array should be: 1, 2, 6, 8, 9, 10.
Restrictions:
Cannot use Distinct method
Signature:
public static int[] CompactArray(int[] input)
View 14 Replies
View Related
Apr 18, 2013
I am trying to create a code to sort an array of integer, but only between two positions of the array, not the all array.
like this:
array: 1 2 5 4 7 2 9 8
index: 0 1 2 3 4 5 6 7
i want to sort the array per exemple between the the index 2 and 5.the result is... array: 1 2 2 4 5 7 9 8
View 2 Replies
View Related
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
View Related
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
Mar 21, 2014
I now know how to count integers with while loop but I'm not sure how to count the integers with array.
So the question is:
1. program should keep reading integers as long as the integers are within [0,9999]
2. when user typed the integer not between 0 to 9999, the program print out the numbers of integers that were typed.
Sample
3
3
3
9999
9999
-1
You entered 3 3 times.
You entered 9999 2 times.
#include <iostream>
using namespace std;
int main() {
int i=-1;
int x;
int numbers[10000];
[Code] ....
I cannot use "do" ....
View 1 Replies
View Related
Feb 28, 2013
How to solve this because i was not able to get the idea of using arrays in classes . Here is the Question :
The PVR Cinemas manager approaches you to develop a system for ticket booking. It has 5 screens each with a capacity of 500 seats of which 100 are platinum, 100 are diamond and 300 are gold. The cost of platinum, diamond and gold tickets are Rs.150, Rs.125, and Rs.100 respectively.
•Construct a class to model a screen with an array of integers for each category of seats. Provide a constructor to initialize the array to 0.
•Include a member function bookSeat() that gets the category of the seat and number of tickets to be booked and then prints the seat numbers. The booked seats are marked by 1. If no seats are available then your program should display appropriate message.
Test the above class with a main program that creates an array of objects (size of array depends on the number of screens) and display the total amount to be paid by the visitor.
View 6 Replies
View Related