//myfunc.cpp
#include <iostream>
#include <cmath>
using namespace std;
double avg(const double data[], int size)
{
double total=0;
for (int i=0; i<size; i++)
{
total=total+data[i];
}
return total/(size);
}
double stddev(const double data[], double avg, int size)
{
double s=0;
for(int i=0; i<size; i++)
{
s = s + pow((data[i] - avg),2);
}
return sqrt(s/(size-1));
}
#include <cmath>
using namespace std;
double avg(const double data[], int size)
{
double total=0;
for (int i=0; i<size; i++)
{
total=total+data[i];
}
return total/(size);
}
double stddev(const double data[], double avg, int size)
{
double s=0;
for(int i=0; i<size; i++)
{
s = s + pow((data[i] - avg),2);
}
return sqrt(s/(size-1));
}
//myfunc.h
double avg(const double data[], int size);
double stddev(const double data[], double avg, int size);
//prg.cpp
#include <iostream>
#include "myfunc.h"
using namespace std;
void getmarks(double marks[],int max);
void print(double average, double standarddev);
int main()
{
const int MAX = 10;
double marks[MAX];
double average , standarddev;
getmarks(marks,MAX);
average = avg(marks,MAX);
standarddev = stddev(marks,average,MAX);
print(average,standarddev);
cout << endl;
return 0;
}
void getmarks(double marks[],int max)
{
cout << endl << "Enter 10 marks...\n";
for (int i=0; i<max; i++)
{
cout << "Enter mark " << i+1 << " : ";
cin >> marks[i];
}
cout << endl;
}
void print(double average, double standarddev)
{
cout << "The Average is " << average << endl
<< "The standard Deviation is " << standarddev << endl;
}
#include "myfunc.h"
using namespace std;
void getmarks(double marks[],int max);
void print(double average, double standarddev);
int main()
{
const int MAX = 10;
double marks[MAX];
double average , standarddev;
getmarks(marks,MAX);
average = avg(marks,MAX);
standarddev = stddev(marks,average,MAX);
print(average,standarddev);
cout << endl;
return 0;
}
void getmarks(double marks[],int max)
{
cout << endl << "Enter 10 marks...\n";
for (int i=0; i<max; i++)
{
cout << "Enter mark " << i+1 << " : ";
cin >> marks[i];
}
cout << endl;
}
void print(double average, double standarddev)
{
cout << "The Average is " << average << endl
<< "The standard Deviation is " << standarddev << endl;
}
0 comments:
Post a Comment