Banner Ad

    A    L    W    A    Y    S           D    E    S    I    R    E           T    O           L    E    A    R    N           S    O    M    E    T    H    I    N    G           U    S    E    F    U    L   

Sunday, May 8, 2011

IPE Lab 9b

//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));
}
//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;
}
 


0 comments:

Related Posts Plugin for WordPress, Blogger...

your comments