Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- class Circle
- {
- public:
- int radius;
- int xPoint = rand()%50+1;
- int yPoint = rand()%50+1;
- };
- srand (time(NULL));
- Circle circle1;
- cout<<"please type in radius: "<<endl;
- cin >> circle1.radius;
- cout<<"radius of circle 1 is :" << circle1.radius <<endl;
- Circle circle2;
- cout<<"please type in radius: "<<endl;
- cin >> circle2.radius;
- cout<<"radius of circle 2 is :" << circle2.radius <<endl;
- cout<< "center point of circle 1 is: " << circle1.xPoint << "," << circle1.yPoint<<endl;
- cout<< "center point of circle 2 is: " << circle2.xPoint << "," << circle2.yPoint<<endl;
- return 0;
- }
- // Example program
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <time.h>
- using namespace std;
- class Circle
- {
- public:
- int radius;
- void SetValue();
- private:
- int xPoint = rand()%50+1;
- int yPoint = rand()%50+1;
- };
- void SetValue(int a int b)
- {
- cout << "Accessing private data through public" << endl;
- SetValue(xPoint) = a;
- SetValue(yPoint) = b;
- }
- int main()
- {
- srand (time(NULL));
- Circle circle1;
- cout<<"please type in radius: "<<endl;
- cin >> circle1.radius;
- cout<<"radius of circle 1 is :" << circle1.radius <<endl;
- Circle circle2;
- cout<<"please type in radius: "<<endl;
- cin >> circle2.radius;
- cout<<"radius of circle 2 is :" << circle2.radius <<endl;
- cout<< "center point of circle 1 is: " << circle1.xPoint << "," << circle1.yPoint<<endl;
- cout<< "center point of circle 2 is: " << circle2.xPoint << "," << circle2.yPoint<<endl;
- cout << "lets play a game!" << endl;
- double distance = sqrt(((circle2.xPoint - circle1.xPoint) * (circle2.xPoint - circle1.xPoint)) + ((circle2.yPoint - circle1.yPoint) * (circle2.yPoint - circle1.yPoint)));
- cout<< " distance between two radii is: " << distance << endl;
- if(distance < (circle1.radius + circle2.radius))
- {
- cout<<"you win!"<<endl;
- }
- else
- {
- cout<< "you lose try again!" << endl;
- }
- cout<< "thanks for playing!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement