/* University College London dept of P&A course in C++ 3C59 | all rights reserved 1999 | | Example: Compton Analysis | | "Example of a simple C++ function to calculate inverse energy" | | Author: P.Clarke */ #include #include //----------------------- //Set constant values in define statements #define EZERO 10 //----------------------- //Function to return inverse energy of Comptom scattered electron float inverseScatteredEnergy( float phi ) { //Declare constants in the formula float eZero = EZERO ; //Scattered energy float scatteredEnergy ; //Calculate scatteredEnergy = eZero / 2. / ( 1. - cos(phi) ) ; //Go home return scatteredEnergy ; } //-------------------------------------------------------- // Main program to use it int main() { // declare some variables float escatt ; float angle ; // Set the angle (in radians) and call the function angle = 0.5 ; escatt = inverseScatteredEnergy( angle ) ; std::cout << " The scattered energy was " << escatt << std::endl ; // Do same again with different variable names to emphasise that // these have nothing to do with the names used to write the function float escatt2 ; float angle2 ; angle2 = 0.2 ; escatt2 = inverseScatteredEnergy( angle2 ) ; std::cout << " The second scattered energy was " << escatt2 << std::endl ; return 1 ; }