resistor.cpp
unknown
c_cpp
2 years ago
1.2 kB
9
Indexable
/**
* \file resistor.cpp
* (UTF-8 kodolasu fajl. Allitsa at a megjenetes kodolasat,
* ha a tovabbi kommentek nem olvashatok helyesen!)
*
* Ohmikus ellenállást modellező osztály megvalósítása
*/
/**
* Itt kell megvalósítani a resistor.h-ban deklarált nem inline függvényeket.
* A Jportára ezt a fájlt kell feltölteni.
*/
#include "resistor.h"
double Resistor::defR = 64;
Resistor::Resistor(){R = defR; Pr("ctor0");}
Resistor::Resistor(double r) {R = r; Pr("ctor1");}
void Resistor::setDef(double r) {defR = r;}
Resistor Resistor::operator+(const Resistor& r) const
{
Resistor res(R + r.R);
return res;
}
Resistor Resistor::operator%(const Resistor& r) const
{
Resistor res(1 / ( (1/R) + (1/r.R) ) );
return res;
}
Resistor operator*(int n, const Resistor& r)
{
if (n <= 0)
throw "GTD6KM";
Resistor res(0);
for (int i = 0; i < n; i++)
res = res + r;
return res;
}
Resistor::Resistor(const Resistor& rhs) :R(rhs.R) {Pr("copy");}
Resistor::~Resistor() {Pr("dtor");}
Resistor& Resistor::operator=(const Resistor& rhs)
{
Pr("assign");
this->R = rhs.r;
return *this;
}
Editor is loading...
Leave a Comment