Tutoriales Física simple con C++
Aquí tienes una colección de programas tipo “problema de olimpiada” en C++ para calcular parámetros básicos de cinemática y dinámica. Están pensados para ser fáciles de reutilizar: cada uno tiene entrada estándar → salida estándar, usando double y con formato fijo.
Nota: uso ( g = 9.81 , m/s^2 ) por defecto (puedes cambiarlo a 9.8 si tu enunciado lo pide).
1) MRU (Movimiento Rectilíneo Uniforme)
Dados (x_0), (v), (t) → calcula (x(t)=x_0+vt) y (\Delta x=vt).
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double x0, v, t;
cin >> x0 >> v >> t;
double dx = v * t;
double x = x0 + dx;
cout << fixed << setprecision(6);
cout << "dx " << dx << "\n";
cout << "x " << x << "\n";
return 0;
}
2) MRUA (Aceleración constante)
Dados (x_0), (v_0), (a), (t) → calcula:
- (v(t)=v_0+at)
- (x(t)=x_0+v_0t+\tfrac12 at^2)
- (\Delta x = x(t)-x_0)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double x0, v0, a, t;
cin >> x0 >> v0 >> a >> t;
double v = v0 + a * t;
double x = x0 + v0 * t + 0.5 * a * t * t;
double dx = x - x0;
cout << fixed << setprecision(6);
cout << "v " << v << "\n";
cout << "x " << x << "\n";
cout << "dx " << dx << "\n";
return 0;
}
3) MRUA sin tiempo: ecuación (v^2 = v_0^2 + 2a\Delta x)
Dados (v_0), (a), (\Delta x) → calcula (v) (raíz principal si es posible).
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double v0, a, dx;
cin >> v0 >> a >> dx;
double inside = v0*v0 + 2.0*a*dx;
cout << fixed << setprecision(6);
if (inside < 0) {
cout << "impossible\n"; // no hay v real
return 0;
}
double v = sqrt(inside);
cout << "v " << v << "\n";
return 0;
}
4) Tiro parabólico (sin rozamiento)
Entrada: (v_0) (m/s), ángulo (\theta) en grados, (g).
Salida: tiempo de vuelo (T), alcance (R), altura máxima (H).
Formulas (misma altura salida/llegada):
- (T=\frac{2v_0\sin\theta}{g})
- (R=\frac{v_0^2\sin(2\theta)}{g})
- (H=\frac{v_0^2\sin^2\theta}{2g})
#include <bits/stdc++.h>
using namespace std;
static constexpr double PI = 3.14159265358979323846;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double v0, deg, g;
cin >> v0 >> deg >> g;
double th = deg * PI / 180.0;
double T = (2.0 * v0 * sin(th)) / g;
double R = (v0 * v0 * sin(2.0 * th)) / g;
double H = (v0 * v0 * sin(th) * sin(th)) / (2.0 * g);
cout << fixed << setprecision(6);
cout << "T " << T << "\n";
cout << "R " << R << "\n";
cout << "H " << H << "\n";
return 0;
}
5) Movimiento circular uniforme
Entrada: radio (r), periodo (T).
Salida: velocidad (v), velocidad angular (\omega), aceleración centrípeta (a_c).
- (\omega = \frac{2\pi}{T})
- (v = \omega r)
- (a_c=\frac{v^2}{r}=\omega^2 r)
#include <bits/stdc++.h>
using namespace std;
static constexpr double PI = 3.14159265358979323846;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double r, T;
cin >> r >> T;
double w = 2.0 * PI / T;
double v = w * r;
double ac = w * w * r;
cout << fixed << setprecision(6);
cout << "w " << w << "\n";
cout << "v " << v << "\n";
cout << "ac " << ac << "\n";
return 0;
}
DINÁMICA
6) Segunda ley de Newton (resultante y aceleración)
Entrada: masa (m) y fuerzas (componentes) (F_x, F_y).
Salida: (|\vec F|), (a_x, a_y), (|\vec a|).
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double m, Fx, Fy;
cin >> m >> Fx >> Fy;
double F = hypot(Fx, Fy);
double ax = Fx / m;
double ay = Fy / m;
double a = hypot(ax, ay);
cout << fixed << setprecision(6);
cout << "F " << F << "\n";
cout << "ax " << ax << "\n";
cout << "ay " << ay << "\n";
cout << "a " << a << "\n";
return 0;
}
7) Plano inclinado con rozamiento (aceleración bajando)
Entrada: (m), ángulo (\theta) (grados), coeficiente (\mu), (g).
Aceleración (si baja):
[
a = g(\sin\theta – \mu\cos\theta)
]
También calcula normal (N=mg\cos\theta) y fricción (f=\mu N).
#include <bits/stdc++.h>
using namespace std;
static constexpr double PI = 3.14159265358979323846;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double m, deg, mu, g;
cin >> m >> deg >> mu >> g;
double th = deg * PI / 180.0;
double N = m * g * cos(th);
double f = mu * N;
double a = g * (sin(th) - mu * cos(th));
cout << fixed << setprecision(6);
cout << "N " << N << "\n";
cout << "f " << f << "\n";
cout << "a " << a << "\n";
return 0;
}
8) Trabajo–Energía (trabajo de una fuerza constante)
Entrada: componentes de fuerza (F_x,F_y) y desplazamiento (dx,dy).
Trabajo: (W=\vec F\cdot \vec d = F_xdx + F_ydy).
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double Fx, Fy, dx, dy;
cin >> Fx >> Fy >> dx >> dy;
double W = Fx*dx + Fy*dy;
cout << fixed << setprecision(6);
cout << "W " << W << "\n";
return 0;
}
9) Energía cinética y velocidad
Entrada: masa (m), velocidad (v).
Salida: (K=\tfrac12 mv^2).
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double m, v;
cin >> m >> v;
double K = 0.5 * m * v * v;
cout << fixed << setprecision(6);
cout << "K " << K << "\n";
return 0;
}
10) Choque perfectamente inelástico (se pegan)
Entrada: (m_1,v_1,m_2,v_2) (1D).
Velocidad final común:
[
v_f=\frac{m_1v_1+m_2v_2}{m_1+m_2}
]
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double m1, v1, m2, v2;
cin >> m1 >> v1 >> m2 >> v2;
double vf = (m1*v1 + m2*v2) / (m1 + m2);
cout << fixed << setprecision(6);
cout << "vf " << vf << "\n";
return 0;
}
Si me dices qué tipo de enunciados caen en tus sesiones (por ejemplo: “tiro con altura inicial”, “plano inclinado con cuerda/polea”, “choques elásticos”, “MCU/MUA con varias fases”), te los preparo en el mismo formato olimpiada (lectura robusta, varios casos, edge cases).
Etiqueta:c++, ies monterroso, programación

