Uhhhhh yes

This commit is contained in:
Tyler Beckman 2024-08-25 20:44:35 -06:00
parent 351f3f4093
commit 4247e4fecb
Signed by: Ty
GPG key ID: 2813440C772555A4
2 changed files with 162 additions and 118 deletions

View file

@ -1,3 +1,39 @@
IndentWidth: 4 IndentWidth: 4
UseTab: Always UseTab: Always
TabWidth: 4 TabWidth: 4
InsertBraces: false
SortIncludes: true
IncludeBlocks: Regroup
IncludeCategories:
# System headers from C
- Regex: '<(cassert|ccomplex|cctype|cerrno|cfenv|cfloat|cinttypes|ciso646|climits|clocale|cmath|csetjmp|csignal|cstdalign|cstdarg|cstdatomic|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstdnoreturn|cstring|ctgmath|cthreads|ctime|cuchar|cwchar|cwctype)>'
Priority: 3
# System headers without extension.
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
Priority: 2
# Local headers with extension.
- Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"'
Priority: 1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
IndentCaseLabels: true
IntegerLiteralSeparator:
Binary: 0
Decimal: 3
Hex: -1

244
main.cpp
View file

@ -14,161 +14,169 @@ double const SPHERE_VOLUME = 4.0 / 3;
double const VACUUM_PERMITTIVITY = 0.000'000'000'008'854'187'818'8; double const VACUUM_PERMITTIVITY = 0.000'000'000'008'854'187'818'8;
double ideal_gas_law(double moles, double gas_absolute_temperature, double ideal_gas_law(double moles, double gas_absolute_temperature,
double volume) { double volume) {
return (moles * MOLAR_GAS_CONSTANT * gas_absolute_temperature) / volume; return (moles * MOLAR_GAS_CONSTANT * gas_absolute_temperature) / volume;
} }
double average_acceleration(double pos_start, double pos_end, double time_start, double average_acceleration(double pos_start, double pos_end, double time_start,
double time_end) { double time_end) {
return (pos_end - pos_start) / std::pow(time_end - time_start, 2); return (pos_end - pos_start) / std::pow(time_end - time_start, 2);
} }
double ohms_law(double voltage, double resistance) { double ohms_law(double voltage, double resistance) {
return voltage / resistance; return voltage / resistance;
} }
double universal_gravitation(double mass_one, double mass_two, double universal_gravitation(double mass_one, double mass_two,
double distance) { double distance) {
return GRAVITATIONAL_CONSTANT * return GRAVITATIONAL_CONSTANT *
((mass_one * mass_two) / std::pow(distance, 2)); ((mass_one * mass_two) / std::pow(distance, 2));
} }
double pythagorean_theorem(double x, double y) { double pythagorean_theorem(double x, double y) {
return std::sqrt(std::pow(x, 2) + std::pow(y, 2)); return std::sqrt(std::pow(x, 2) + std::pow(y, 2));
} }
double sphere_volume(double radius) { double sphere_volume(double radius) {
return SPHERE_VOLUME * M_PI * std::pow(radius, 3); return SPHERE_VOLUME * M_PI * std::pow(radius, 3);
} }
double deflection(double weight, double length, double elasticity_modulus, double deflection(double weight, double length, double elasticity_modulus,
double moment_of_inertia) { double moment_of_inertia) {
return (weight * std::pow(length, 3)) / return (weight * std::pow(length, 3)) /
(3 * elasticity_modulus * moment_of_inertia); (3 * elasticity_modulus * moment_of_inertia);
} }
double heat_transfer_rate(double transfer_coefficient, double surface_area, double heat_transfer_rate(double transfer_coefficient, double surface_area,
double temperature_change) { double temperature_change) {
return transfer_coefficient * surface_area * temperature_change; return transfer_coefficient * surface_area * temperature_change;
} }
double stress(double force, double area) { return force / area; } double stress(double force, double area) { return force / area; }
double shear_stress(double sigma_x, double sigma_y, double tau_xy, double shear_stress(double sigma_x, double sigma_y, double tau_xy,
double theta) { double theta) {
return -0.5 * (sigma_x - sigma_y) * sin(2 * theta) + tau_xy * cos(2 * theta); return -0.5 * (sigma_x - sigma_y) * sin(2 * theta) +
tau_xy * cos(2 * theta);
} }
double coulombs_law(double charge_1, double charge_2, double coulombs_law(double charge_1, double charge_2,
double relative_static_permittivity, double distance) { double relative_static_permittivity, double distance) {
return std::fabs(charge_1 * charge_2) / return std::fabs(charge_1 * charge_2) /
(4 * M_PI * VACUUM_PERMITTIVITY * relative_static_permittivity * (4 * M_PI * VACUUM_PERMITTIVITY * relative_static_permittivity *
std::pow(distance, 2)); std::pow(distance, 2));
} }
double input_double(std::string prompt) { double input_double(std::string prompt) {
double out; double out;
while (true) { while (true) {
std::cout << prompt + ": "; std::cout << prompt + ": ";
std::cin >> out; std::cin >> out;
if (std::cin.fail()) { if (std::cin.fail()) {
std::cin.clear(); std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid number, Please try again" << std::endl; std::cout << "Invalid number, Please try again" << std::endl;
} else { } else {
break; break;
} }
} }
return out; return out;
} }
int main() { int main() {
while (true) { while (true) {
std::cout << "[0] Quit program" << std::endl std::cout << "[0] Quit program" << std::endl
<< "[1] Ideal gas law" << std::endl << "[1] Ideal gas law" << std::endl
<< "[2] Average acceleration" << std::endl << "[2] Average acceleration" << std::endl
<< "[3] Ohm's law" << std::endl << "[3] Ohm's law" << std::endl
<< "[4] Universal gravitation" << std::endl << "[4] Universal gravitation" << std::endl
<< "[5] Pythagorean theorem" << std::endl << "[5] Pythagorean theorem" << std::endl
<< "[6] Sphere volume" << std::endl << "[6] Sphere volume" << std::endl
<< "[7] Deflection" << std::endl << "[7] Deflection" << std::endl
<< "[8] Heat transfer rate" << std::endl << "[8] Heat transfer rate" << std::endl
<< "[9] Stress" << std::endl << "[9] Stress" << std::endl
<< "[10] Shear Stress" << std::endl << "[10] Shear Stress" << std::endl
<< "[11] Coulomb's law" << std::endl; << "[11] Coulomb's law" << std::endl;
int equation = input_double("Which equation would you like to calculate?"); int equation =
input_double("Which equation would you like to calculate?");
std::string output = ""; double output;
switch (equation) { switch (equation) {
case 0: case 0:
return 0; return 0;
case 1: case 1:
output = ideal_gas_law( output = ideal_gas_law(
input_double("Please enter amount of moles"), input_double("Please enter amount of moles"),
input_double("Please enter the gas absolute temperate"), input_double("Please enter the gas absolute temperate"),
input_double("Please enter the volume")); input_double("Please enter the volume"));
break; break;
case 2: case 2:
output = average_acceleration( output = average_acceleration(
input_double("Please enter the starting position"), input_double("Please enter the starting position"),
input_double("Please enter the ending position"), input_double("Please enter the ending position"),
input_double("Please enter the starting time"), input_double("Please enter the starting time"),
input_double("Please enter the ending time")); input_double("Please enter the ending time"));
break; break;
case 3: case 3:
output = ohms_law(input_double("Please input the voltage"), output = ohms_law(input_double("Please input the voltage"),
input_double("Please input the resistance")); input_double("Please input the resistance"));
break; break;
case 4: case 4:
output = universal_gravitation( output = universal_gravitation(
input_double("Please input the mass of object 1"), input_double("Please input the mass of object 1"),
input_double("Please input the mass of object 2"), input_double("Please input the mass of object 2"),
input_double("Please input the distance between objects")); input_double("Please input the distance between objects"));
break; break;
case 5: case 5:
output = output = pythagorean_theorem(
pythagorean_theorem(input_double("Please input the x distance"), input_double("Please input the x distance"),
input_double("Please input the y distance")); input_double("Please input the y distance"));
break; break;
case 6: case 6:
output = sphere_volume(input_double("Please input the sphere radius")); output = sphere_volume(
break; input_double("Please input the sphere radius"));
case 7: break;
output = deflection(input_double("Please input the force of weight"), case 7:
input_double("Please input the length"), output = deflection(
input_double("Please input the elasticity modulus"), input_double("Please input the force of weight"),
input_double("Please input the moment of inertia")); input_double("Please input the length"),
break; input_double("Please input the elasticity modulus"),
case 8: input_double("Please input the moment of inertia"));
output = heat_transfer_rate( break;
input_double("Please input the transfer coefficient"), case 8:
input_double("Please input the surface area"), output = heat_transfer_rate(
input_double("Please input the change in temperature")); input_double("Please input the transfer coefficient"),
break; input_double("Please input the surface area"),
case 9: input_double("Please input the change in temperature"));
output = stress(input_double("Please input the amount of force"), break;
input_double("Please input the surface area")); case 9:
break; output =
case 10: stress(input_double("Please input the amount of force"),
output = shear_stress( input_double("Please input the surface area"));
input_double("Please enter σ_x"), input_double("Please enter σ_y"), break;
input_double("Please enter τ_xy"), input_double("Please enter θ")); case 10:
break; output = shear_stress(input_double("Please enter σ_x"),
case 11: input_double("Please enter σ_y"),
output = coulombs_law( input_double("Please enter τ_xy"),
input_double("Please input the first charge"), input_double("Please enter θ (in radians)"));
input_double("Please input the second charge"), break;
input_double("Please input the relative static permittivity"), case 11:
input_double("Please input the distance between charges")); output = coulombs_law(
break; input_double("Please input the first charge"),
default: input_double("Please input the second charge"),
std::cout << "That is not a valid choice. Please try again." input_double(
<< std::endl; "Please input the relative static permittivity"),
continue; input_double("Please input the distance between charges"));
} break;
std::cout << "The result of that calculation is: " << output << std::endl; default:
} std::cout << "That is not a valid choice. Please try again."
<< std::endl;
continue;
}
std::cout << "The result of that calculation is: " << output
<< std::endl;
}
} }