13.07.2015 Views

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C++</strong> designHomework<strong>C++</strong> style• efficient with inline functions• don’t need knowledge of data structure• modular• re-usableHep3VectorF hits[100];// do some workfloat r = hits[i].mag();• later, we’ll get rid of <strong>the</strong> fixed or dynamic arraysSupposeclass Hep3VectorF {public:Hep3VectorF();Hep3VectorF(float x, float y, float z)Hep3VectorF(const Hep3VectorF &v);inline float x();inline float y();inline float z();inline float phi();inline float cosTheta();inline float mag();private:float r, cos_<strong>the</strong>ta, phi;};• write <strong>the</strong> implementation for this class• constructors take x, y, and z as arguments, but mustintialize r, cos(<strong>the</strong>ta), and phi data members• try clhep/threeVector0.C; it should still workwith this small change// #include #include “ThreeVector.h”• write a program to exercise x(), y(), and z()member functions<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 80 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 81 Paul F. Kunz

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!