University of Michigan
ENGR 151 radionuc.hpp
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
class radioNuclide{
public:
double m_lambda;
int numParticles;
void operator +=(const int &x);
friend ostream &operator <<(ostream &fout, const radioNuclide nuclide);
radioNuclide(){
m_lambda = 0;
numPa
...[Show More]
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
class radioNuclide{
public:
double m_lambda;
int numParticles;
void operator +=(const int &x);
friend ostream &operator <<(ostream &fout, const radioNuclide nuclide);
radioNuclide(){
m_lambda = 0;
numParticles = 1;
}//default
radioNuclide(const double lambda, const int N0){
m_lambda = lambda;
numParticles = N0;
}
// constructor that takes in a value for lambda
// and a value for the number of nuclei radioNuclide(const double,const int);
int Count(){
return numParticles;
} // returns the number of nuclei remaining
// This reduces the number of nuclei due to radioactive decay, each with
probability lambda*t
int Decay(const double dt){
double p = m_lambda*dt;
double test;
int decayedN = 0;
for (int i =0; i<numParticles; i++){
test = 1.0 *rand()/RAND_MAX;
if (test <= p){
decayedN++;
}
}
[Show Less]