Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <math.h>
  4.  
  5. struct urojona
  6. {
  7. float x1u, x2u, su, ru, ilu, iru;
  8. };
  9.  
  10. struct zespolona
  11. {
  12. float x1r, x2r, sr, rr, ilr, irr;
  13. struct urojona u;
  14. };
  15.  
  16. class Rownanie
  17. {
  18. private:
  19. zespolona* z;
  20. int *a,*b,*c;
  21. float d, pd, md;
  22.  
  23. public:
  24. Rownanie();
  25. ~Rownanie();
  26.  
  27. #pragma region Metody
  28.  
  29. void podaj_dane()
  30. {
  31. printf("Podaj a b c\n");
  32. scanf_s("%d %d %d", *a, *b, *c);
  33. }
  34.  
  35. void formatuj_rownanie(int a, int b, int c) {
  36. //========================================================================================================================
  37.  
  38.  
  39.  
  40. if (a>1 || a<0)
  41. {
  42. printf("%d*x*x", a);
  43. }
  44. else
  45. {
  46. if (a == 1)
  47. {
  48. printf("x*x");
  49. }
  50. else
  51. {
  52. if (a != 0)
  53. {
  54. printf("\n######\nformatuj_rownanie blad_a\n");
  55. }
  56. }
  57. }
  58. if (b>1)
  59. {
  60. printf("+%d*x", b);
  61. }
  62. else
  63. {
  64. if (b<0)
  65. {
  66. printf("%d*x", b);
  67. }
  68. else
  69. {
  70. if (b == 1)
  71. {
  72. printf("+x");
  73. }
  74. else
  75. {
  76. if (b != 0)
  77. {
  78. printf("\n######\nformatuj_rownanie blad_b\n");
  79. }
  80. }
  81. }
  82. }
  83. if (c>0)
  84. {
  85. printf("+%d", c);
  86. }
  87. else
  88. {
  89. if (c<0)
  90. {
  91. printf("%d", c);
  92. }
  93. else
  94. {
  95. if (c == 1)
  96. {
  97. printf("%d", c);
  98. }
  99. else
  100. {
  101. if (b != 0)
  102. {
  103. printf("\n######\nformatuj_rownanie blad_c\n");
  104. }
  105. }
  106. }
  107. }
  108. printf(" = 0\n");
  109. }
  110.  
  111. float oblicz_d(int a, int b, int c) {
  112. return (float)((b*b) - ((4 * a)*c));
  113. }
  114.  
  115. float mnsqrt(float d)
  116. {
  117. float pd = 0;
  118. if (d > 0)
  119. {
  120. //obliczanie pierwiastka z d
  121. pd = d / 2;
  122. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  123. pd = (d / pd + pd) / 2;
  124. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  125. pd = (d / pd + pd) / 2;
  126. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  127. pd = (d / pd + pd) / 2;
  128. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  129. pd = (d / pd + pd) / 2;
  130. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  131. pd = (d / pd + pd) / 2;
  132. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  133. pd = (d / pd + pd) / 2;
  134. if ((d / pd - pd > 0.1) || (d / pd - pd < -0.1)) {
  135. pd = (d / pd + pd) / 2;// dokladnosc na poziomie 0.2
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. return pd;
  145. }
  146.  
  147. void oblicz_pierwiastki(int a, int b, int c, float* x1r, float *x2r, float *x1u, float *x2u) {
  148.  
  149. float d = oblicz_d(a, b, c);
  150. float pd;
  151.  
  152. if (d>0)
  153. {
  154. pd = sqrtf(d);
  155.  
  156. *x1r = ((-(float)b + pd) / (2 * (float)a));
  157. *x2r = ((-(float)b - pd) / (2 * (float)a));
  158. }
  159. else if (d == 0)
  160. {
  161. *x1r = ((-(float)b) / (2 * (float)a));
  162. }
  163. else
  164. {
  165. pd = sqrtf(fabsf(d));
  166.  
  167. *x1r = ((-(float)b) / (2 * (float)a));
  168. *x2r = *x1r;
  169.  
  170. *x1u = -pd / 2 / (float)a;
  171. *x2u = -*x1u;
  172. }
  173.  
  174. }
  175.  
  176. void dodaj(float d, float *x1r, float *x2r, float *x1u, float *x2u, float *sr, float *su) {
  177. if (d>0)
  178. {
  179. *sr = *x1r + *x2r;
  180. }
  181. else if (d<0)
  182. {
  183. *sr = *x1r + *x2r;
  184. *su = *x1u + *x2u;
  185. }
  186. }
  187.  
  188. void odejmij(float d, float *x1r, float *x2r, float *x1u, float *x2u, float *rr, float *ru) {
  189. if (d>=0)
  190. {
  191. *rr = *x1r - *x2r;
  192. }
  193. else if (d<0)
  194. {
  195. *rr = *x1r - *x2r;
  196. *ru = *x1u - *x2u;
  197. }
  198. }
  199.  
  200. void pomnoz(float d, float *x1r, float *x2r, float *x1u, float *x2u, float *ilr, float *ilu) {
  201. if (d>=0)
  202. {
  203. *ilr = *x1r * *x2r;
  204. }
  205. else if (d<0)
  206. {
  207. *ilr = *x1r * *x2r - *x1u * *x2u;
  208. *ilu = *x1r * *x2u + *x1r * *x2u;
  209. }
  210. }
  211.  
  212. void podziel(float d, float *x1r, float *x2r, float *x1u, float *x2u, float *irr, float *iru) {
  213. if (d >= 0 && *x2r != 0) {
  214. *irr = *x1r / *x2r;
  215. }
  216. else if (d < 0) {
  217.  
  218. *irr = (*x1r * *x2r - *x1u * *x2u) / (*x2r * *x2r + *x2u * *x2u);
  219. *iru = (*x2r * *x1u - *x1r * *x2u) / (*x2r * *x2r + *x2u * *x2u);
  220.  
  221. //*irr = (*x1r * *x2r - *x1u * *x2u) / (*x2r * *x2r + *x2u * *x2u);
  222. //*iru = (*x1r * *x2r + *x1u * *x2u) / (*x2r * *x2r + *x2u * *x2u);
  223. }
  224. }
  225.  
  226. void formatuj_zesp(float r, float u) {
  227.  
  228. float c = 3;
  229.  
  230. if (r>0 || r<0)
  231. {
  232. printf("%0f", r);
  233. }
  234. else
  235. {
  236. if (r == 1)
  237. {
  238. printf("1");
  239. }
  240. else
  241. {
  242. if (r != 0)
  243. {
  244. printf("\n######\nformatuj_zesp blad_a\n");
  245. }
  246. }
  247. }
  248.  
  249. if (u>0)
  250. {
  251. printf("+%fi", u);
  252. }
  253. else
  254. {
  255. if (u<0)
  256. {
  257. printf("%fi", u);
  258. }
  259. else
  260. {
  261. if (u == 1)
  262. {
  263. printf("+i");
  264. }
  265. else
  266. {
  267. if (u != 0)
  268. {
  269. printf("\n######\nformatuj_zesp blad_b\n");
  270. }
  271. }
  272. }
  273. }
  274.  
  275. }
  276.  
  277. void wyswietl_wynik(int a, int b, int c, float d, float x1r, float x2r, float x1u, float x2u, float sr, float su, float rr, float ru, float ilr, float ilu, float irr, float iru) {
  278. printf("\n a= %d b= %d c= %d\n", a, b, c);
  279.  
  280. formatuj_rownanie( a, b, c);
  281.  
  282. printf("\n d= %f\n", d);
  283. printf("\n pd= %f", sqrt(d));
  284.  
  285. printf("\n x1v= %f\n", x1r);
  286. printf("\n x2v= %f\n", x2r);
  287.  
  288. printf("\n x1u= %f\n", x1u);
  289. printf("\n x2u= %f\n", x2u);
  290.  
  291.  
  292. printf("\n sr= %f\n", sr);
  293. printf("\n su= %f\n", su);
  294.  
  295.  
  296. printf("\n rr= %f\n", rr);
  297. printf("\n ru= %f\n", ru);
  298.  
  299. printf("\n ilr= %f\n", ilr);
  300. printf("\n ilu= %f\n", ilu);
  301.  
  302. printf("\n irr= %f\n", irr);
  303. printf("\n iru= %f\n", iru);
  304. }
  305.  
  306. void modul()
  307. {
  308. md = sqrtf((z->x1r*z->x1r) + ((z->u).x1u*(z->u).x1u));
  309. }
  310. #pragma endregion //Metody
  311.  
  312. };
  313.  
  314. Rownanie::Rownanie()
  315. {
  316.  
  317. }
  318.  
  319. Rownanie::~Rownanie()
  320. {
  321.  
  322. }
  323.  
  324. int _tmain(int argc, _TCHAR* argv[])
  325. {
  326. return 0;
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement