Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. Czy punkt jest w okręgu
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5. #include <cstdlib>
  6. #include <math.h>
  7. using namespace std;
  8. double dlugosc;
  9.  
  10. struct kolo{
  11. int x;
  12. int y;
  13. int r;
  14.  
  15. };
  16.  
  17. struct punkt{
  18. int x1;
  19. int y1;
  20.  
  21. };
  22. int okreg(kolo a, punkt* b, int e)
  23. {
  24. int z=0;
  25. int dlugosc;
  26. for(int i=0;i<e;i++)
  27. {
  28. dlugosc = sqrt(((b[i].x1 - a.x)*(b[i].x1 - a.x)) +((b[i].y1 - a.y)*(b[i].y1 - a.y))) ;
  29. if(dlugosc<a.r)
  30. z++;
  31. }
  32.  
  33.  
  34.  
  35. return z;
  36. }
  37.  
  38. int main()
  39.  
  40. {
  41.  
  42. kolo a;
  43. a.x=4;
  44. a.y=5;
  45. a.r=6;
  46. punkt b[5];
  47.  
  48. b[0]={3,2};
  49. b[1]={2,6};
  50. b[2]={3,4};
  51. b[3]={3,8};
  52. b[4]={3,2};
  53.  
  54.  
  55. cout<<okreg(a,b,5);
  56.  
  57. return 0;
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. LOSOWE LICZBY SUMA WARIANCJA
  66.  
  67. // Example program
  68. #include <iostream>
  69. #include <string>
  70. #include <cstdlib>
  71. using namespace std;
  72. int main()
  73. {
  74. srand(time(NULL));
  75. int a;
  76. int b;
  77. float suma=0;
  78. int tab[100];
  79. double srednia;
  80. float wariancja;
  81. cout<<"Podaj przedzial: " <<endl;
  82. cin>>a;
  83. cin>>b;
  84. cout <<endl;
  85.  
  86. for(int i=0; i<99; i++)
  87. {
  88. tab[i]=rand()%(a+b-1)+a;
  89. cout<<tab[i]<<"\a"<<endl;
  90. suma=suma+tab[i];
  91. srednia=suma/100;
  92. }
  93. for(int i=0; i<99; i++)
  94. {
  95. wariancja += (tab[i]-srednia)*(tab[i]-srednia);
  96. wariancja /= 99;
  97. }
  98.  
  99.  
  100.  
  101. cout<<"Wariancja to: " <<wariancja<<endl;
  102. cout<<"Suma to: "<< suma <<endl;
  103. cout <<"Srednia to: " <<srednia<<endl;
  104. }
  105.  
  106.  
  107.  
  108.  
  109. KTORY PUNKT LEZY NAJBLIZEJ
  110.  
  111.  
  112.  
  113.  
  114. #include <iostream>
  115. #include <math.h>
  116. #include <cstdlib>
  117. #include <math.h>
  118. using namespace std;
  119. double dlugosc;
  120.  
  121. struct kolo{
  122. int x;
  123. int y;
  124. int r;
  125.  
  126. };
  127.  
  128. struct punkt{
  129. int x1;
  130. int y1;
  131.  
  132. };
  133. int okreg(kolo a, punkt* b, int e)
  134. {
  135. int z=0;
  136. float dlugosc[5];
  137. for(int i=0;i<e;i++)
  138. {
  139. dlugosc[i] = sqrt(((b[i].x1 - a.x)*(b[i].x1 - a.x)) +((b[i].y1 - a.y)*(b[i].y1 - a.y))) ;
  140. if(dlugosc[i]<a.r)
  141. {z++;
  142. }
  143. }
  144. if(dlugosc[0]<dlugosc[1]&&dlugosc[0]<dlugosc[2]&&dlugosc[0]<dlugosc[3]&&dlugosc[0]<dlugosc[4])
  145. {cout<<"pierwszy lezy najblizej"<<endl;}
  146. if(dlugosc[1]<dlugosc[0]&&dlugosc[1]<dlugosc[2]&&dlugosc[1]<dlugosc[3]&&dlugosc[1]<dlugosc[4])
  147. {cout<<"drugi lezy najblizej"<<endl;}
  148. if(dlugosc[2]<dlugosc[0]&&dlugosc[2]<dlugosc[1]&&dlugosc[2]<dlugosc[3]&&dlugosc[2]<dlugosc[4])
  149. {cout<<"trzeci lezy najblizej"<<endl;}
  150. if(dlugosc[3]<dlugosc[0]&&dlugosc[3]<dlugosc[1]&&dlugosc[3]<dlugosc[2]&&dlugosc[3]<dlugosc[4])
  151. {cout<<"czwarty lezy najblizej"<<endl;}
  152. if(dlugosc[4]<dlugosc[0]&&dlugosc[4]<dlugosc[2]&&dlugosc[4]<dlugosc[3]&&dlugosc[4]<dlugosc[1])
  153. {cout<<"piaty lezy najblizej"<<endl;}
  154.  
  155.  
  156. return z;
  157. }
  158.  
  159. int main()
  160.  
  161. {
  162.  
  163. kolo a;
  164. a.x=0;
  165. a.y=0;
  166. a.r=6;
  167. punkt b[5];
  168.  
  169. b[0]={12,12};
  170. b[1]={1,1};
  171. b[2]={3,4};
  172. b[3]={3,8};
  173. b[4]={3,2};
  174.  
  175.  
  176.  
  177. PROGRAM PODMIENIAJACY MALA LITERE NA DUZA
  178.  
  179.  
  180. #include <iostream>
  181. #include <math.h>
  182. #include <cstdlib>
  183. #include <math.h>
  184. #include <string>
  185. using namespace std;
  186. int podmieniacz(char tab[]) {
  187. int licznikPodmienionychSlow = 0;
  188. for (int i = 0; i<sizeof(tab)+1; i++) {
  189. if (islower(tab[i])) {
  190. tab[i] = toupper(tab[i]);
  191. licznikPodmienionychSlow++;
  192. }
  193. }
  194. return licznikPodmienionychSlow;
  195. }
  196.  
  197.  
  198.  
  199. int main()
  200.  
  201. {
  202.  
  203. char tab[] = "SlOwO";
  204. int dlugoscSlowa = sizeof(tab);
  205. cout << "W slowie " << tab << " zamienionych na duze litery zostalo " << podmieniacz(tab) << " liter." << endl;
  206. system("pause");
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement