I have this homework that i have to write the cxx of a header file. i started the homework but i got stuck in the meddle of it. I tried to find the abs_minimum function but it's too complicated because i have to keep track of the numbers and find it.

This is the header file

// Provided by:   
// Email Address: 
// FILE: stats.h
// CLASS PROVIDED: statistician
//   (a class to keep track of statistics on a sequence of real numbers)
//   This class is part of the namespace main_savitch_2C.
//
// CONSTRUCTOR for the statistician class:
//   statistician( );
//     Postcondition: The object has been initialized, and is ready to accept
//     a sequence of numbers. Various statistics will be calculated about the
//     sequence.
//
// PUBLIC MODIFICATION member functions for the statistician class:
//   void next(double r)
//     The number r has been given to the statistician as the next number in
//     its sequence of numbers.
//   void reset( );
//     Postcondition: The statistician has been cleared, as if no numbers had
//     yet been given to it.
//   
// PUBLIC CONSTANT member functions for the statistician class:
//   double abs_maximum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the absolute value of the number
//     with the largest magnitude in the statistician's sequence.
//   double abs_minimum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the absolute value of the number
//     with the smallest magnitude in the statistician's sequence.
//   int length( ) const
//     Postcondition: The return value is the length of the sequence that has
//     been given to the statistician (i.e., the number of times that the
//     next(r) function has been activated).
//   double maximum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the largest number in the
//     statistician's sequence.
//   double mean( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the arithmetic mean (i.e., the
//     average of all the numbers in the statistician's sequence).
//   double minimum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the tinyest number in the
//     statistician's sequence.
//   double recent( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the most recent number given to
//     the next function.
//   double sum( ) const
//     Postcondition: The return value is the sum of all the numbers in the
//     statistician's sequence.
//
// NON-MEMBER functions for the statistician class:
//   statistician operator +(const statistician& s1, const statistician& s2)
//     Postcondition: The statistician that is returned contains all the
//     numbers of the sequences of s1 and s2.
//   statistician operator *(double scale, const statistician& s)
//     Postcondition: The statistician that is returned contains the same
//     numbers that s does, but each number has been multiplied by the
//     scale number.
//     
// VALUE SEMANTICS for the statistician class:
// Assignments and the copy constructor may be used with statistician objects.

#ifndef STATS_H     // Prevent duplicate definition
#define STATS_H
#include <iostream>

namespace main_savitch_2C
{
    class statistician
    {
    public:
        // CONSTRUCTOR
        statistician( );
        // MODIFICATION MEMBER FUNCTIONS
        void next(double r);
        void reset( );
        // CONSTANT MEMBER FUNCTIONS
        double abs_maximum( ) const;
        double abs_minimum( ) const;
        int length( ) const;
        double maximum( ) const;
        double mean( ) const;
        double minimum( ) const;
        double recent( ) const;
        double sum( ) const;
        // FRIEND FUNCTIONS
        friend statistician operator +
            (const statistician& s1, const statistician& s2);
        friend statistician operator *
            (double scale, const statistician& s);
    private:
	double my_abs_maximum; // The absolute value of the largest magnitude
	double my_abs_minimum; // The absolute value of the smallest magnitude
        int my_length;         // How many numbers in the sequence
        double my_maximum;     // The largest number in the sequence
        double my_minimum;     // The smallest number in the sequence
	double my_recent;      // The most recent number given to the sequence
        double my_sum;         // The sum of all the numbers in the sequence
    };
}

#endif

this is the cxx file that i wrote

#include <cassert>
#include <math>
#include "stats.h"


namespace main_savitch_2c
{
	statistician::statistician() : count(0), total(0) 
	{
	}
	
	void statistician::next(double r)
	{
		if (count <= 0)
		{
			count = 1;
			total = r;
			tinyest = r;
			largest = r;
			return;
		}
		count = count + 1;
		total +=r;
		if (r < tinyest)
		{
			tinyest = r;
		}
		if (largest < r)
		{
			largest = r;
		}
	}
	
	void statistician::reset()
	{
		count= 0;
		total = 0;
	}
	
	double statistician::abs_maximum( ) const
	{
		asser(length() > 0);
		a= f_abs(largest);
		b= f_abs(tinyest);
		if (a>b)
		{
			return a;
		}
		else (a<b)
		{
			return b;
		}
	}
	
	double statistician::abs_minimum() const
	{
		asser(length() > 0);
		return
	}
	
	int statistician::length() const
	{
		return count;
	}
	
	double statistician::maximum() const
	{
		asser(length() > 0);
		return largest;
	}
	
	double statistician::mean() const
	{
		asser(length() > 0);
		return total/count;
	}
	
	double statistician::minimum() const
	{
		asser(length() > 0);
		return tinyest;
	}
	
	double statistician::recent() const
	{
		asser(length() > 0);
		return 
	}
	
	double statistician::sum() const
	{
		return total;
	}
	
	statistician operator +(const statistician& s1, const statistician& s2)
	{
		statistician s3;
		s3.next (s1.sum() + s2.sum());
		return s3;
	}
	
	statistician operator *(double scale, const statistician& s)
	{
		return s2;
	}
}

so your not sure how to get the abs_minimum? arent you calculating it in you next function

if (count <= 0)
		{
			count = 1;
			total = r;
			tinyest = r;
			largest = r;
			return;
		}
		count = count + 1;
		total +=r;
		if (r < tinyest)
		{
			tinyest = r;  //<-- here you are setting the minimum.
		}
		if (largest < r)
		{
			largest = r;
		}
}

all you have to do is return the absolute value of the minimum to satisfy the return value for the function. there are abs() functions in math.h that will do that for you or you could write your own

I didn't understand it. can you explain it in another way please. I'm not a native speaker and I'm a beginner.

This article has been dead for over six months. Start a new discussion instead.