Advertisement
xTheEc0

2. Assignment. (Circle length, coordinates)

Feb 25th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <cstdlib>  // Standard General Utilities Library
  2. #include <iostream> // Input output stream
  3.  
  4. using namespace std;
  5.  
  6. #define pi 3.14
  7.  
  8. // Classes
  9. class circle {
  10. private:
  11.     float x, y, r;
  12. public:
  13.     circle();
  14.     circle(float);
  15.     circle(float, float);
  16.     circle(float, float, float);
  17.  
  18.     float length(); //2 pi r
  19.     void assign(float, float, float);
  20.     void print();
  21. };
  22.  
  23. // Methods
  24. circle::circle() {
  25.     x = 0;
  26.     y = 0;
  27.     r = 1;
  28. }
  29.  
  30. circle::circle(float var1) {
  31.     x = var1;
  32.     y = var1;
  33.     r = 1;
  34. }
  35.  
  36. circle::circle(float var1, float var2) {
  37.     x = var1;
  38.     y = var2;
  39.     r = 1;
  40. }
  41.  
  42. circle::circle(float var1, float var2, float var3) {
  43.     x = var1;
  44.     y = var2;
  45.     r = var3;
  46. }
  47.  
  48. void circle::assign(float var1, float var2, float var3) {
  49.     x = var1;
  50.     y = var2;
  51.     r = var3;
  52. }
  53.  
  54. float circle::length() {
  55.     return 2 * pi * r;
  56. }
  57.  
  58. void circle::print() {
  59.     cout << "C = (" << x << ", " << y << ");" << endl;
  60.     cout << "r = " << r << endl;
  61.     cout << "L = " << length() << endl;
  62. }
  63.  
  64. // Function prototypes
  65.  
  66. // Main program
  67. int main(int argc, char *argv[]) {
  68.     circle A(1, 3, 3);
  69.     A.print();
  70.  
  71.     cout << " " << endl;
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement