Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class Point {
- int x;
- int y;
- int distance() {
- double rez;
- rez = sqrt((double)(x * x) + (double)(y * y));
- return rez;
- }
- public:
- Point() {
- x = 0;
- y = 0;
- }
- Point(int x1, int y1) {
- x = x1;
- y = y1;
- }
- void setX(int x1) {
- x = x1;
- }
- void setY(int y1) {
- y = y1;
- }
- int getX() {
- return x;
- }
- int getY() {
- return y;
- }
- void print() {
- cout << "x: " << x << " ";
- cout << "y: " << y << " ";
- cout << endl;
- if (distance() == 0) {
- cout << "Point is centered.";
- }
- else {
- cout << "Distance: " << distance();
- }
- cout << endl;
- }
- };
- int main()
- {
- Point p1;
- Point p2(20, 20);
- p1.setX(5);
- p1.setY(10);
- p1.print();
- p2.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement