Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <math.h>
  5. #include <time.h>
  6. using namespace std;
  7. int main()
  8. {
  9.     class Circle
  10.     {
  11.    
  12.     public:
  13.     int radius;
  14.     int xPoint = rand()%50+1;
  15.     int yPoint = rand()%50+1;
  16.    
  17.        
  18.     };
  19.    
  20.     srand (time(NULL));
  21.     Circle circle1;
  22.    
  23.     cout<<"please type in radius: "<<endl;
  24.     cin >> circle1.radius;
  25.     cout<<"radius of circle 1 is :" << circle1.radius <<endl;
  26.    
  27.      Circle circle2;
  28.    
  29.     cout<<"please type in radius: "<<endl;
  30.     cin >> circle2.radius;
  31.     cout<<"radius of circle 2 is :" << circle2.radius <<endl;
  32.    
  33.     cout<< "center point of circle 1 is: " << circle1.xPoint << "," << circle1.yPoint<<endl;
  34.     cout<< "center point of circle 2 is: " << circle2.xPoint << "," << circle2.yPoint<<endl;
  35.     return 0;
  36. }
  37. // Example program
  38. #include <iostream>
  39. #include <string>
  40. #include <math.h>
  41. #include <time.h>
  42. using namespace std;
  43.  
  44.     class Circle
  45.     {
  46.    
  47.     public:
  48.     int radius;
  49.     void SetValue();
  50.     private:
  51.     int xPoint = rand()%50+1;
  52.     int yPoint = rand()%50+1;
  53.    
  54.        
  55.     };
  56.     void SetValue(int a int b)
  57.     {
  58.         cout << "Accessing private data through public" << endl;
  59.         SetValue(xPoint) = a;
  60.         SetValue(yPoint) = b;
  61.         }
  62. int main()
  63. {
  64.     srand (time(NULL));
  65.     Circle circle1;
  66.    
  67.     cout<<"please type in radius: "<<endl;
  68.     cin >> circle1.radius;
  69.     cout<<"radius of circle 1 is :" << circle1.radius <<endl;
  70.    
  71.      Circle circle2;
  72.    
  73.     cout<<"please type in radius: "<<endl;
  74.     cin >> circle2.radius;
  75.     cout<<"radius of circle 2 is :" << circle2.radius <<endl;
  76.    
  77.     cout<< "center point of circle 1 is: " << circle1.xPoint << "," << circle1.yPoint<<endl;
  78.     cout<< "center point of circle 2 is: " << circle2.xPoint << "," << circle2.yPoint<<endl;
  79.    
  80.     cout << "lets play a game!" << endl;
  81.    
  82.     double distance = sqrt(((circle2.xPoint - circle1.xPoint) * (circle2.xPoint - circle1.xPoint)) + ((circle2.yPoint - circle1.yPoint) * (circle2.yPoint - circle1.yPoint)));
  83.     cout<< " distance between two radii is: " << distance << endl;
  84.    
  85.     if(distance < (circle1.radius + circle2.radius))
  86.     {
  87.     cout<<"you win!"<<endl;    
  88.     }
  89.     else
  90.     {
  91.     cout<< "you lose try again!" << endl;    
  92.        
  93.     }
  94.    
  95.     cout<< "thanks for playing!" << endl;
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement