Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct MyStruct
  8. {
  9. string liczba_przed_kropka;
  10. string liczba_po_kropce;
  11. string symbol;
  12. int dlugosc_po_kropce;
  13. };
  14. MyStruct str;
  15.  
  16. void PodzielSymbol(string symbol) {
  17. int dlugosc;
  18. dlugosc = symbol.length();
  19. bool czy_jest_kropka = false;
  20. int pozycja_kropki = 1;
  21. int dlugosc_symbolu = 0;
  22. string znak;
  23.  
  24. //Pobierz symbol
  25. if (isupper(symbol[dlugosc - 2])) {
  26. znak = symbol[dlugosc - 2];
  27. znak += symbol[dlugosc - 1];
  28. dlugosc_symbolu = 2;
  29. }
  30. else {
  31. znak = symbol[dlugosc - 1];
  32. dlugosc_symbolu = 1;
  33. }
  34. str.symbol = znak;
  35.  
  36. //sprawdz czy w wyrazeniu istnieje kropka i pobierz jej miejsce
  37. for (int i = 0; i < dlugosc; i++) {
  38. if (symbol[i] == '.') {
  39. czy_jest_kropka = true;
  40. break;
  41. }
  42. pozycja_kropki++;
  43. }
  44.  
  45. //Pobierz wartość przed kropka jesli istnieje. Jeżeli nie pobierz cała wartość bez symbolu
  46. if (czy_jest_kropka == true) {
  47. for (int i = 0; i < pozycja_kropki - 1; i++) {
  48. str.liczba_przed_kropka += symbol[i];
  49. }
  50. }
  51. else {
  52. for (int i = 0; i < dlugosc - dlugosc_symbolu; i++) {
  53. str.liczba_przed_kropka += symbol[i];
  54. }
  55. }
  56. cout << str.liczba_po_kropce;
  57.  
  58. //Pobierz wartość po kropce jesli istnieje bez symbolu
  59. if (czy_jest_kropka == true) {
  60. str.dlugosc_po_kropce += dlugosc - dlugosc_symbolu - pozycja_kropki;
  61. for (int i = pozycja_kropki; i < dlugosc - dlugosc_symbolu; i++)
  62. {
  63. str.liczba_po_kropce += symbol[i];
  64. }
  65. }
  66. }
  67.  
  68. void WypiszWyik(int liczba_zer) {
  69. string wynik;
  70. wynik += str.liczba_przed_kropka;
  71. if (str.dlugosc_po_kropce == 0) {
  72. for (int i = 0; i < liczba_zer; i++)
  73. {
  74. wynik += "0";
  75. }
  76. }
  77. else {
  78. wynik += str.liczba_po_kropce;
  79. for (int i = 0; i < liczba_zer - str.dlugosc_po_kropce; i++)
  80. {
  81. wynik += "0";
  82. }
  83. }
  84. cout << wynik << endl;
  85. }
  86.  
  87. void Konwertuj(string symbol) {
  88. PodzielSymbol(symbol);
  89.  
  90. if (str.symbol == "M") {
  91. WypiszWyik(6);
  92. cout << endl;
  93. }
  94. else if (str.symbol == "B") {
  95. WypiszWyik(9);
  96. cout << endl;
  97. }
  98. else if (str.symbol == "T") {
  99. WypiszWyik(12);
  100. cout << endl;
  101. }
  102. else if (str.symbol == "Qa") {
  103. WypiszWyik(15);
  104. cout << endl;
  105. }
  106. else if (str.symbol == "Qi") {
  107. WypiszWyik(18);
  108. cout << endl;
  109. }
  110. else if (str.symbol == "Sx") {
  111. WypiszWyik(21);
  112. cout << endl;
  113. }
  114. else if (str.symbol == "Sp") {
  115. WypiszWyik(24);
  116. cout << endl;
  117. }
  118. else if (str.symbol == "Oc") {
  119. WypiszWyik(27);
  120. cout << endl;
  121. }
  122. }
  123.  
  124. int main()
  125. {
  126. Konwertuj("999.99M");
  127.  
  128. system("pause");
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement