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.

Line fit continuedCharacter StringsPart 2 (ch2/linefit.C)// Compute coefficientsdouble sx_over_n = sx / n;double stt = 0.0;double b = 0.0;for (i = 0; i < n; i++) {double ti = x[i] - sx_over_n;Character strings are special case of array andarray initializationchar hello1[] = { ’H’, ’i’ };The above is too tedious, so use double quoteschar hello2[] = "Hi";}stt += ti * ti;b += ti * y[i];}b /= stt;double a = (sy - sx * b) / n;delete [] x;delete [] y;cout

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

Saved successfully!

Ooh no, something went wrong!