Abdulg

SUVAT calculator [C++]

Dec 3rd, 2012
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. //Made to test out g++ in Arch, not tested extensively
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.  
  10. int S,U,V,A,T,Unknown,Temp,Sknown,Uknown,Vknown,Aknown,Tknown,Sfigureable, Ufigureable, Vfigureable, Afigureable, Tfigureable = 0;
  11.  
  12. cout << "SUVAT - S = Displacement (Fancy for distance), U = Initial Velocity (Almost always zero), V = Final velocity, A = Acceleration (~10m/s due to gravity), T = time..\n";
  13.  
  14. cout << "Is S known? (0 = No, 1 = Yes)\n";
  15. cin >> Sknown;
  16.  
  17. cout << "\nIs U known? \n";
  18. cin >> Uknown;
  19.  
  20. cout << "\nIs V known? \n";
  21. cin >> Vknown;
  22.  
  23. cout << "\nIs A known? \n";
  24. cin >> Aknown;
  25.  
  26. cout << "\nIs T known? \n";
  27. cin >> Tknown;
  28.  
  29. cout << "Calculating what is figurable...\n";
  30.  
  31. if (Uknown, Tknown, Aknown == 1 || Uknown, Vknown, Tknown == 1)
  32. Sfigureable = 1;
  33.  
  34. if (Vknown, Aknown, Tknown == 1)
  35. {
  36. Ufigureable = 1;
  37. Vfigureable = 1;
  38. }
  39.  
  40. if (Uknown, Aknown, Sknown == 1)
  41. Vfigureable = 1;
  42.  
  43. if (Vknown, Uknown, Tknown == 1)
  44. Afigureable = 1;
  45.  
  46. if (Vknown, Aknown, Uknown == 1)
  47. Tfigureable = 1;
  48.  
  49. if (Sknown == 1)
  50. Sfigureable = 0;
  51.  
  52. if (Uknown == 1)
  53. Ufigureable = 0;
  54.  
  55. if (Vknown == 1)
  56. Vfigureable = 0;
  57.  
  58. if (Aknown == 1)
  59. Afigureable = 0;
  60.  
  61. if (Tknown == 1)
  62. Tfigureable = 0;
  63.  
  64. if (Sfigureable == 1)
  65. cout << "S is figurable!\n";
  66. else if (Sknown == 1)
  67. cout << "S is already known!\n";
  68. else cout << "S is not figurable / already known!\n";
  69.  
  70. if (Ufigureable == 1)
  71. cout << "U is figurable!\n";
  72. else if (Uknown == 1)
  73. cout << "U is already known!\n";
  74. else cout << "U is not figurable / already known!\n";
  75.  
  76. if (Vfigureable == 1)
  77. cout << "V is figurable!\n";
  78. else if (Vknown == 1)
  79. cout << "V is already known!\n";
  80. else cout << "V is not figurable / already known!\n";
  81.  
  82. if (Afigureable == 1)
  83. cout << "A is figurable!\n";
  84. else if (Aknown == 1)
  85. cout << "A is already known!\n";
  86. else cout << "A is not figurable / already known!\n";
  87.  
  88. if (Tfigureable == 1)
  89. cout << "T is figurable!\n";
  90. else if (Tknown == 1)
  91. cout << "T is already known!\n";
  92. else cout << "T is not figurable! / already known!\n";
  93.  
  94. if (Sknown == 1)
  95. {
  96. cout << "S = ";
  97. cin >> S;
  98. cout << "\n";
  99. }
  100.  
  101. if (Uknown == 1)
  102. {
  103.     cout << "U = ";
  104.     cin >> U;
  105.     cout << "\n";
  106. }
  107.  
  108. if (Vknown == 1)
  109. {
  110.     cout << "V = ";
  111.     cin >> V;
  112.     cout << "\n";
  113. }
  114.  
  115. if (Aknown == 1)
  116. {
  117.     cout << "A = ";
  118.     cin >> A;
  119.     cout << "\n";
  120. }
  121.  
  122. if (Tknown == 1)
  123. {
  124.     cout << "T = ";
  125.     cin >> T;
  126.     cout << "\n";
  127. }
  128.  
  129.  
  130. if (Sfigureable == 1)
  131. {
  132.     if (Aknown == 1)
  133.     S = U*T + 0.5*A*(T*T);
  134.  
  135.     else S = 0.5*(U+V)*T;
  136. }
  137.  
  138. if (Ufigureable == 1)
  139. U = V - A*T;
  140.  
  141.  
  142. if (Vfigureable == 1)
  143. {
  144.     if (Tknown == 1)
  145.     V = U + A*T;
  146.  
  147.     else  V = sqrt(U^2 + 2*A*S);
  148. }
  149.  
  150. if (Afigureable == 1)
  151. A = (V-U)/T;
  152.  
  153. if (Tfigureable == 1)
  154. T = (V-U)/A;
  155.  
  156. cout << "S: ";
  157. if (Sknown == 1)
  158. cout << S << " - ";
  159. if (Sfigureable == 0)
  160. cout << "Not figured!\n";
  161. else cout << S << "\n";
  162.  
  163. cout << "U: ";
  164. if (Uknown == 1)
  165. cout << U << " - ";
  166. if (Ufigureable == 0)
  167. cout << "Not figured!\n";
  168. else cout << U << "\n";
  169.  
  170. cout << "V: ";
  171. if (Vknown == 1)
  172. cout << V << " - ";
  173. if (Vfigureable == 0)
  174. cout << "Not figured!\n";
  175. else cout << V << "\n";
  176.  
  177. cout << "A: ";
  178. if (Aknown == 1)
  179. cout << A << " - ";
  180. if (Afigureable == 0)
  181. cout << "Not figured!\n";
  182. else cout << A << "\n";
  183.  
  184. cout << "T: ";
  185. if (Tknown == 1)
  186. cout << T << " - ";
  187. if (Tfigureable == 0)
  188. cout << "Not figured!\n";
  189. else cout << T << "\n";
  190.  
  191. return 0;
  192. }
  193. /*
  194. U = V - AT
  195. T = (V-U)/A
  196. A = (V-U)/T
  197. */
Advertisement
Add Comment
Please, Sign In to add comment