// PURPOSE: to evaluate g[m/s^2] as a function of pendulum period // FILENAME: gfun1.cpp // PROGRAMMER: Dr.Iz (Urieli) 8/15/03 // DESCRIPTION: class Pendulum defines the pendulum in terms // of its length and baseline value of g. A method is defined // in the class to determine the local value of g given the // measured value of period. #include #include #include "gfun1.h" using namespace std; int main() { float length, period; cout << "This program evaluates the local value of g[m/s^2]\n" << "as a function of pendulum period\n"; cout << "\nEnter the pendulum length [m]: "; cin >> length; Pendulum pend(length); cout << "enter period [s]: "; cin >> period; cout << "for period = " << period << " seconds, " << "g = " << pend.find_g(period) << "[m/s^2]\n"; return 0; } //############################################################## // function to determine local acceleration due to gravity g // based on a pendulum experiment // pre: argument "period" and pendulum "length" have values // post: value of g has been evaluated and returned. float Pendulum::find_g(float period) { float g = 4*PI*PI*length/(period*period); return g; // [m/s^2] }