fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const float PI = 3.14;
  7.  
  8. class DuongTron
  9. {
  10. private:
  11. int x, y;
  12. float r;
  13. public:
  14. DuongTron();
  15. DuongTron(int toaDoX, int toaDoY, float banKinh);
  16. void nhap();
  17. void xuat();
  18. double dienTich();
  19. double chuVi();
  20. ~DuongTron();
  21. };
  22.  
  23. DuongTron::DuongTron() : x(0), y(0), r(1) {}
  24.  
  25. DuongTron::DuongTron(int toaDoX, int toaDoY, float banKinh)
  26. : x(toaDoX), y(toaDoY), r(banKinh) {}
  27.  
  28. void DuongTron::nhap()
  29. {
  30. cout << "Nhap toa do x: ";
  31. cin >> x;
  32. cout << "Nhap toa do y: ";
  33. cin >> y;
  34. cout << "Nhap ban kinh r: ";
  35. cin >> r;
  36. }
  37.  
  38. void DuongTron::xuat()
  39. {
  40. cout << "Chu vi: " << chuVi() << endl;
  41. cout << "Dien tich: " << dienTich() << endl;
  42. }
  43.  
  44. double DuongTron::dienTich()
  45. {
  46. return PI * r * r;
  47. }
  48.  
  49. double DuongTron::chuVi()
  50. {
  51. return 2 * PI * r;
  52. }
  53.  
  54. DuongTron::~DuongTron()
  55. {
  56.  
  57. }
  58.  
  59. int main()
  60. {
  61. DuongTron a;
  62. a.nhap();
  63. a.xuat();
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Nhap toa do x: Nhap toa do y: Nhap ban kinh r: Chu vi: 6.28
Dien tich: 3.14