Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. 1.
  2.  
  3. #include "stdafx.h"
  4.  
  5. using namespace System;
  6. using namespace System::IO;
  7. using namespace System::Text;
  8.  
  9. int main(array<System::String ^> ^args)
  10. {
  11. StreamReader ^sr1 = nullptr;
  12. try{
  13. sr1 = gcnew StreamReader(L"dane.txt");
  14. }
  15. catch (Exception ^e)
  16. {
  17. Console::WriteLine("Błąd!-->{0}", e->Message);
  18. Console::ReadKey();
  19. return -1;
  20. }
  21. String ^s = sr1->ReadLine();
  22. array<String ^>^ds = s->Trim()->Split(L' ');
  23. double x1 = double::Parse(ds[0]);
  24. double y1 = double::Parse(ds[ds->Length-1]);
  25. s = sr1->ReadLine();
  26. sr1->Close();
  27. array<String ^>^dt = s->Trim()->Split(L' ');
  28. double x2 = double::Parse(dt[0]);
  29. double y2 = double::Parse(dt[dt->Length - 1]);
  30. double dx = x2 - x1;
  31. double dy = y2 - y1;
  32. double d = Math::Sqrt(dx*dx + dy*dy);
  33. Console::WriteLine(L"Odleglosc = {0}", d);
  34. StreamWriter ^sr2 = nullptr;
  35. try
  36. {
  37. sr2 = gcnew StreamWriter(L"wynik.txt", false, Encoding::UTF8);
  38. }
  39. catch (Exception ^e)
  40. {
  41. Console::WriteLine("Błąd!-->{0}", e->Message);
  42. Console::ReadKey();
  43. return -1;
  44. }
  45. sr2->WriteLine(d);
  46. sr2->Close();
  47. Console::ReadKey();
  48. return 0;
  49. }
  50.  
  51.  
  52. 2.
  53.  
  54. #include "stdafx.h"
  55.  
  56. using namespace System;
  57. using namespace System::IO;
  58. using namespace System::Text;
  59.  
  60. int main(array<System::String ^> ^args)
  61. {
  62. int n = int::Parse(Console::ReadLine());
  63. Random ^r = gcnew Random();
  64. StreamWriter ^sr = nullptr;
  65. try
  66. {
  67. sr = gcnew StreamWriter(L"wynik.txt", false, Encoding::UTF8);
  68. }
  69. catch (Exception ^e)
  70. {
  71. Console::WriteLine("Błąd!-->{0}", e->Message);
  72. Console::ReadKey();
  73. return -1;
  74. }
  75. for (int i = 0; i < n; i++)
  76. {
  77. sr->WriteLine(r->Next(n));
  78. }
  79. sr->Close();
  80. Console::ReadKey();
  81. return 0;
  82. }
  83.  
  84.  
  85. 3.
  86.  
  87. #include "stdafx.h"
  88.  
  89. using namespace System;
  90. using namespace System::IO;
  91. using namespace System::Text;
  92.  
  93. int main(array<System::String ^> ^args)
  94. {
  95. String ^path = Console::ReadLine();
  96. StreamWriter ^sr = nullptr;
  97. try{
  98. sr = gcnew StreamWriter(path, false, Encoding::UTF8);
  99. }
  100. catch (Exception ^e)
  101. {
  102. Console::WriteLine("Błąd!-->{0}", e->Message);
  103. Console::ReadKey();
  104. return -1;
  105. }
  106. sr->WriteLine("Polskie znaki: ąęćłóśżź");
  107. sr->Close();
  108. return 0;
  109. }
  110.  
  111.  
  112. 4.
  113.  
  114. #include "stdafx.h"
  115.  
  116. using namespace System;
  117. using namespace System::IO;
  118. using namespace System::Text;
  119.  
  120. int main(array<System::String ^> ^args)
  121. {
  122. String ^path = Console::ReadLine();
  123. StreamReader ^sr = nullptr;
  124. try{
  125. sr = gcnew StreamReader(path);
  126. }
  127. catch (Exception ^e)
  128. {
  129. Console::WriteLine("Błąd!-->{0}", e->Message);
  130. Console::ReadKey();
  131. return -1;
  132. }
  133. String ^s = sr->ReadLine();
  134. Console::WriteLine(s);
  135. sr->Close();
  136. return 0;
  137. }
  138.  
  139.  
  140. 5.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement