I am writing a function and need to calculate the median...I am gonna b honest I absolutely have no idea how to start this but it is pretty much one of the last things I need to do with my program. Any advice would br greatly appreciated.....
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int MAX_SIZE = 100;
void Fill_Array(int Size[], int& count);
void Print_Array(int Size[], int count);
double Calc_Average(int Size[], double average);
void Sort(int Size[], int numbers_used);
void Swap(int& v1, int& v2);
int index_of_smallest(const int Size[], int start_index, int number_used);
int Calc_Median(int median);
void Print_Array_and_Calculations(int median, double average);
int main()
{
int count;
int Size [MAX_SIZE],
numbers_used = 0,
median = 0;
double average = 0.0;
Fill_Array(Size, count);
Print_Array(Size, count);
average = Calc_Average(Size, average);
Sort(Size, numbers_used);
Calc_Median(median);
Print_Array_and_Calculations(median, average);
return 0;
}
void Fill_Array(int Size[], int& count, int& number_used)
{
int size;
ifstream in_size;
string text_file;
cout << "Enter the file to read in:";
cin >> text_file;
cout << endl << "The numbers in the array are:" << endl << endl;
if(in_size.fail())
{
cerr << "Error opening file";
exit(1);
}
count = 0;
in_size >> size;
while((!in_size.eof()) && (count <= MAX_SIZE))
{
Size[count] = size;
count++;
in_size >> size;
}
in_size.close();
}
void Print_Array(int Size[], int count)
{
int number_used = 0;
for(int index = 0; index < number_used; index++)
cout << Size[index] << " ";
}
double Calc_Average(int Size[], double average)
{
int total = 0;
for (int i = 0; i < MAX_SIZE; i++)
{
total = total + Size[i];
}
average = double(total) / MAX_SIZE;
return average;
}
void Sort(int Size[], int number_used)
{
int index_of_next_smallest;
for (int index = 0; index < number_used - 1; index++)
{
index_of_next_smallest = index_of_smallest(Size, index, number_used);
Swap(Size[index], Size[index_of_next_smallest]);
}
}
void Swap(int& v1, int& v2)
{
int temp;
temp = v1;
v1 = v2;
v2 = temp;
}
int index_of_smallest(const int Size[], int start_index, int number_used)
{
int min = Size[start_index],
index_of_min = start_index;
for (int index = start_index + 1; index < number_used; index++)
if(Size[index] < min)
{
min = Size[index];
index_of_min = index;
}
return index_of_min;
}
int Calc_Median(int median)
{
}
void Print_Array_and_Calculations(int median, double average)
{
cout << "The average of the numbers is " << average;
cout << endl << "The median of the numbers is " << median;
}