Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. class Diem{
  6. private:
  7. int x,y;
  8. public:
  9. Diem(){
  10. x=y=0;
  11. }
  12. Diem(int a,int b){
  13. x=a;
  14. y=b;
  15. }
  16. void nhap(){
  17. cout<<"hoanh do la";cin>>x;
  18. cout<<"tung do la :";cin>>y;
  19. }
  20. friend istream &operator>>(istream &in,Diem &a);
  21. friend ostream &operator<<(ostream &out,Diem &a);
  22. double kc();
  23.  
  24. };
  25.  
  26. istream &operator>>(istream &in,Diem &a){
  27. cout<<"hoanh do la :";in>>a.x;
  28. cout<<"tung do la:";in>>a.y;
  29. return in;
  30. }
  31. ostream &operator<<(ostream &out,Diem &a){
  32. out<<"("<<a.x<<","<<a.y<<")";
  33. return out;
  34. }
  35. double Diem::kc(){
  36. return sqrt(x*x+y*y);
  37. }
  38. int main()
  39. {
  40. int n;
  41. Diem *a;
  42. cout<<"nhap n diem:";cin>>n;
  43. a=new Diem[n+1];
  44. for(int i=1;i<=n;i++){
  45. cout<<"nhap diem thu "<<i<<":";
  46. a[i].nhap();
  47. }
  48.  
  49. int max=a[1].kc();
  50. for(int i=2;i<=n;i++){
  51. if(max<a[i].kc()) max=a[i].kc();
  52. }
  53. cout<<"cac diem xa goc toa dom nhat ";
  54. for(int i=1;i<=n;i++){
  55. if(max==a[i].kc()) cout<<a[i];
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement