/*
 * Instituto Superior de Engenharia do Porto
 *
 * Estruturas de Informação
 *
 * 2000/2001
 *
 * ------------------------------------------
 *
 * Miniteste
 *
 */

#include <string>
using namespace std;
#include "nota.h"

CNota::CNota()
{
	setNF(true);
	setNota(0);
}

CNota::CNota(const CNota& o)
{
	setNota(o.getNota());
	setNF(!o.frequentou());
	setNumMatricula(o.getNumMatricula());
}

CNota::CNota(string sNum, bool bNF, int nNota)
{
	setNumMatricula(sNum);
	setNota(nNota);
	setNF(bNF);
}

bool CNota::setNota(int nNota)
{
	if (nNota >= 0 && nNota < 20)
	{
		m_nNota = nNota;
		m_bNF = false;
		return true;
	}
	else
		return false;
}

CNota& CNota::operator=(const CNota& o)
{
	setNota(o.getNota());
	setNF( !o.frequentou() );
	setNumMatricula(o.getNumMatricula());
	return *this;
}

double media(CNota turma[], int nNumAlunos)
{
	int accum = 0;
	int nNumReal = 0;
	for (int i = 0; i < nNumAlunos; i++)
	{
		if (turma[i].frequentou())
		{
			accum += turma[i].getNota();
			nNumReal++;
		}
	}
	return (double)accum/nNumReal;
}


ostream& operator<<(ostream& output, const CNota& obj)
{
	output << "Num Matricula:" << obj.getNumMatricula() << " -- ";
	if (obj.frequentou())
		output << obj.getNota() << endl;
	else
		output << " NF "  << endl;
	return output;
}
