44 lines
1.7 KiB
C++
44 lines
1.7 KiB
C++
#include "Atomkern.h"
|
|
#include <ostream>
|
|
|
|
Atomkern::Atomkern(std::string symbol, unsigned int masseZ,
|
|
unsigned int ordnungZ)
|
|
: elementsymbol(symbol), massen_zahl(masseZ), ordnungs_zahl(ordnungZ) {}
|
|
Atomkern Atomkern::NEUTRON = Atomkern("Neutron", 1, 0);
|
|
Atomkern Atomkern::PROTON = Atomkern("Proton", 1, 1);
|
|
std::string Atomkern::symbol() const { return elementsymbol; }
|
|
unsigned int Atomkern::ordnungszahl() const { return ordnungs_zahl; }
|
|
unsigned int Atomkern::massenzahl() const { return massen_zahl; }
|
|
Atomkern &Atomkern::operator+=(const Atomkern &atom1) {
|
|
massen_zahl += atom1.massenzahl();
|
|
ordnungs_zahl += atom1.massenzahl();
|
|
return *this;
|
|
}
|
|
Atomkern Atomkern::operator-(const Atomkern &atom1) {
|
|
return Atomkern(symbol(), massen_zahl - atom1.massenzahl(),
|
|
ordnungs_zahl - atom1.ordnungszahl());
|
|
}
|
|
Atomkern Atomkern::operator-=(const Atomkern &atom1) {
|
|
massen_zahl -= atom1.massenzahl();
|
|
ordnungs_zahl -= atom1.massenzahl();
|
|
return *this;
|
|
}
|
|
bool Atomkern::operator==(Atomkern const atom2) {
|
|
return ordnungszahl() == atom2.ordnungszahl() &&
|
|
massenzahl() == atom2.massenzahl();
|
|
}
|
|
Atomkern operator+(const Atomkern &atom1, const Atomkern &atom2) {
|
|
return Atomkern(atom1.symbol(), atom1.massenzahl() + atom2.massenzahl(),
|
|
atom1.ordnungszahl() + atom2.ordnungszahl());
|
|
}
|
|
Atomkern operator*(int i, const Atomkern &atom1) {
|
|
return Atomkern(atom1.symbol(), atom1.massenzahl() * i,
|
|
atom1.ordnungszahl() * i);
|
|
}
|
|
std::ostream &operator<<(std::ostream &os, const Atomkern &atom) {
|
|
os << atom.symbol()
|
|
<< "(" << atom.massenzahl()
|
|
<< "," << atom.ordnungszahl() << ")";
|
|
return os;
|
|
}
|