|
ok..here is the finished product
only things: you need to create a file called new.txt and insert the amount of numbers you have set(#define MAX __)
when you change the amount of numbers inside the txt file you must change #define MAX __
thanks trancealholic and whoever else helped me on my quest.
[code]
#include
#include
#include
#include //allow use of pow and sqrt function
using namespace std; //rids the program of std::
void sort( double array[], int legnth); //sorts #'s
void inFile(double array[]); //prints numbers from the .txt. file
double *max(double array[],int legnth); //prints out max value in the array
double *min(double array[],int legnth); //prints out min value in the array
double mean(double array[],int legnth); //prints out mean value of array
double median(double array[],int legnth); //prints out median value of the array
double std_dev(double array[],int legnth); //prints out standard deviation of the array
#define MAX 4 //amount of values inside txt program
int main() //main
{
double *MaxValue;
double *MinValue;
cout<<"inputting data from a file called new.txt\n\n";
double array[MAX];
cout<<"1) the numbers in the text file that are put into an array are:\n";
inFile(array); // print function
cout<
MaxValue = max(array,MAX);
MinValue = min(array,MAX);
cout<<"3) the maximum value of the array is: "<<*MaxValue;
cout<
cout<
cout<<"4) the minimum value of the array is: "<<*MinValue;
cout<
cout<
cout<<"5) the mean is : "<
cout<
cout<
cout<<"6) the median is: "<
cout<
cout<
cout<<"7) standard Deviation: ";
cout<< std_dev(array,MAX)<
return 0;
}
void inFile(double array[]) //file print function
{
double num;
int i=0;
ifstream inFileNew;
inFileNew.open("new.txt");
if(!inFileNew){
cerr<<"file could not be opened"<
exit(1);
}
while (! inFileNew.eof())
{
inFileNew>>num;
array[i]=num;
i++;
cout<
}
inFileNew.close();
}
double *max(double array[],int legnth) //max function
{
double *maximum;
if(legnth>0){
maximum=&array[legnth-1];
}
else if(legnth<=0){
maximum=0;
}
return maximum;
}
double *min(double array[],int legnth) //min function
{
double *minimum;
if(legnth>0){
sort(array,legnth);
minimum=&array[0];
}
else if(legnth<=0){
minimum=0;
}
return minimum;
}
double mean(double array[],int legnth) //mean function
{
double sum=0,mean=0;
for(int i=0;i<=legnth;i++)
{
sum=sum+array[i];
}
mean=(sum/MAX);
return mean;
}
void sort( double array[], int legnth) //sort function
{
double hold;
for (int pass = 0; pass
{
for (int j = 0; j
{
if (array[j] > array[j + 1])
{
hold = array[j];
array[j] = array[j + 1];
array[j + 1] = hold;
}
}
}
cout<<"\n\n2) Array after sorting...\n";
for(int l = 0; l
cout<
cout<
cout<
}
double median(double array[],int legnth) //mean function
{
double median;
median=array[legnth/2];
return median;
}
double std_dev(double array[],int legnth) //standard deviation function
{
double std_dev=0,average;
average = mean(array, MAX);
for(int i=0;i
std_dev+=pow((array [i]-average),2);
std_dev/=(legnth-1);
std_dev=sqrt(std_dev);
return std_dev;
}
[code] 
___________________
ATB -Let u go
Iio - Rapture(riva edit)
Dj Encore - I see right through you
Lasgo - something
The best vocal tunes on LI RIP(2001-2002)
Last edited by Trancealot on Nov-19-2002 at 19:10
|