Advertisement
F22

Untitled

F22
Jan 22nd, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. /*1. Wczytać rekordy o polach całkowitych (x, y) do tablic dynamicznych a[n] i b[m] (n oraz m należy przedtem wczytać).
  2. Z tablicy a wydrukować wszystkie punkty leżące najdalej od środka (0,0), ale wewnątrz okręgu o promieniu R1 (R1 – stała)
  3. i środku w (0,0), zaś z tablicy b wydrukować wszystkie punkty leżące najdalej od środka (0,0),
  4. ale wewnątrz okręgu o promieniu r2 (r2 należy przedtem wczytać) i środku w (0,0).*/
  5.  
  6. #include <iostream>
  7. using namespace std;
  8. const int R1=7;
  9. struct Spunkt
  10. {
  11.     int x;
  12.     int y;
  13. };
  14. void wymiar(int &roz)
  15. {
  16.     cout<<"Podaj rozmiar: ";
  17.     cin>>roz;
  18. }
  19. void stworz(Spunkt *&tab, int roz)
  20. {
  21.     tab=new Spunkt[roz];
  22. }
  23. void wypelnianie(Spunkt *&tab, int roz)
  24. {
  25.     cout<<endl;
  26.     for(int i=0; i<roz; i++)
  27.     {
  28.         int x, y;
  29.         cout<<"Podaj x: ";
  30.         cin>>x;
  31.         cout<<"Podaj y: ";
  32.         cin>>y;
  33.         tab[i].x=x;
  34.         tab[i].y=y;
  35.         cout<<endl;
  36.     }
  37. }
  38. void drukujtab(Spunkt *&tab, int roz)
  39. {
  40.     for(int i=0; i<roz; i++)
  41.     {
  42.         cout<<"X: "<<tab[i].x<<endl;
  43.         cout<<"Y: "<<tab[i].y<<endl<<endl;
  44.     }
  45. }
  46. void szukanie(Spunkt *&tab, int roz, Spunkt &max, int ograniczenie)
  47. {
  48.     max.x=0;
  49.     max.y=0;
  50.     for(int i=0; i<roz; i++)
  51.     {
  52.         if(tab[i].x<ograniczenie&&tab[i].y<ograniczenie)
  53.         {
  54.             if((tab[i].x>max.x)&&(tab[i].y>max.y))
  55.                 max.x=tab[i].x;
  56.                 max.y=tab[i].y;
  57.         }
  58.     }
  59. }
  60. void drukujwynik(Spunkt max, int ograniczenie)
  61. {
  62.     if((max.x==0)&&(max.y==0))
  63.     {
  64.         cout<<"Brak maxa."<<endl;
  65.         return;
  66.     }
  67.     cout<<"Wspolrzedne max ("<<ograniczenie<<")"<<endl;
  68.     cout<<"x: "<<max.x<<endl;
  69.     cout<<"y: "<<max.y<<endl;
  70. }
  71. void usun(Spunkt *&tab)
  72. {
  73.     delete []tab;
  74. }
  75.  
  76. int main()
  77. {
  78. Spunkt *tab1, *tab2, max1, max2;
  79. int n, m, r2;
  80. cout<<"[Pierwsza Tablica]"<<endl;
  81. wymiar(n);
  82. cout<<"[Druga Tablica]"<<endl;
  83. wymiar(m);
  84. stworz(tab1, n);
  85. stworz(tab2, m);
  86. cout<<"[Pierwsza Tablica]"<<endl;
  87. wypelnianie(tab1, n);
  88. cout<<"[Druga Tablica]"<<endl;
  89. wypelnianie(tab2, m);
  90. cout<<"[Pierwsza Tablica]"<<endl;
  91. szukanie(tab1, n, max1, R1);
  92. cout<<"Podaj r2: ";
  93. cin>>r2;
  94. szukanie(tab2, n, max2, r2);
  95. drukujwynik(max1, R1);
  96. drukujwynik(max2, r2);
  97. usun(tab1);
  98. usun(tab2);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement