Created
April 12, 2025 10:26
-
-
Save barbarbar338/4954c7a930df8059dd4aaad198a93383 to your computer and use it in GitHub Desktop.
Shows information about an ideal pendulum - Prepared for AGU EEE Coma Capsule Integrated Project#3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
const double pi = acos(0) * 2; | |
class Pendulum { | |
private: | |
double length; | |
double acceleration; | |
public: | |
Pendulum(double length, double acceleration) { | |
this->length = length; | |
this->acceleration = acceleration; | |
displayInfo(); | |
} | |
double calculatePeriod() { | |
return 2 * pi * sqrt(length / acceleration); | |
} | |
string toString() { | |
return "Pendulum:\nLength = " + to_string(length) + "m\nGravity = " + to_string(acceleration) + "m/s^2\nperiod = " + to_string(calculatePeriod()) + "s"; | |
} | |
void displayInfo() { | |
cout << toString() << endl; | |
} | |
}; | |
int main() { | |
Pendulum pendulum(1.5, 9.8); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment