Class 2/2
By default, C++ makes all class variables and functions private. That means you can actually declare private variables and functions at the top of your class declaration without even labeling them private:
main.cpp
#include <iostream>
#include "gaussian.h"
int main ()
{
Gaussian mygaussian(30.0,20.0);
Gaussian othergaussian(10.0,30.0);
std::cout << "average " << mygaussian.mu << std::endl;
std::cout << "evaluation " << mygaussian.evaluate(15.0) << std::endl;
std::cout << "mul results sigma " << mygaussian.mul(othergaussian).sigma2 << std::endl;
std::cout << "mul results average " << mygaussian.mul(othergaussian).mu << std::endl;
std::cout << "add results sigma " << mygaussian.add(othergaussian).sigma2 << std::endl;
std::cout << "add results average " << mygaussian.add(othergaussian).mu << std::endl;
std::cout << "average " << mygaussian.mu << std::endl;
mygaussian.mu = 25;
std::cout << "average " << mygaussian.mu << std::endl;
return 0;
}gausian.cpp
gaussian.h
Instead of writing the entire declaration twice, a better option is to put the declaration into a header file. Then you can include the entire declaration with a single line of code:
Last updated
Was this helpful?