Skip to content

Instantly share code, notes, and snippets.

@barbarbar338
Created April 12, 2025 10:26
Show Gist options
  • Save barbarbar338/4954c7a930df8059dd4aaad198a93383 to your computer and use it in GitHub Desktop.
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
#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