Advertisement
Guest User

Untitled

a guest
May 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. //main.cpp
  2. #include <iostream>
  3. #include "Point.h"
  4. #include "Circle.h"
  5.  
  6. int main() {
  7.  
  8.     Point p(1.3, 1.4);
  9.     std::cout << p.print();
  10.     Circle c(p, 0.5);
  11.     std::cout << c.print();
  12.     c.move(1.7, 1.6);
  13.     std::cout << c.print();
  14.  
  15.  
  16.  
  17.     /*
  18.     Point p(4, 5);
  19.     std::cout << p.getX() << std::endl;
  20.     std::cout << p.print();
  21.     p.move(3,4);
  22.     std::cout << p.print();
  23.  
  24.     Point * ptr = new Point(7,9);
  25.     double *fpt = ptr->getX();
  26.     std::cout << ptr->getX() << std::endl;
  27.     std::cout << ptr.print();
  28.     *ptr->move(3,11);
  29.     ptr->move(3,11);
  30.     std::cout << ptr->print();
  31.  
  32.      */
  33.     return 0;
  34. }
  35.  
  36. //circle.cpp
  37. #include "circle.h"
  38.  
  39. //circle.h
  40. #ifndef _POINT_H
  41. #define _POINT_H
  42.  
  43. #include <string>
  44. #include <sstream>
  45.  
  46.  
  47. class Point {
  48.     double x, y;
  49.  
  50. public:
  51.     Point() {
  52.         x = 0;
  53.         y = 0;
  54.     }
  55.     Point(double a, double b) {
  56.         x = a;
  57.         y = b;
  58.     }
  59.     void move(double dx, double dy) {
  60.         x += dx;
  61.         y += dy;
  62.     }
  63.     std::string print(bool zeilenvorschub = true) {
  64.         if(zeilenvorschub) {
  65.             std::ostringstream ss;
  66.             ss << "(" << x << ", " << y << ")" << std::endl;
  67.             return ss.str();
  68.         }
  69.         if (!zeilenvorschub) {
  70.             std::ostringstream ss;
  71.             ss << "(" << x << ", " << y << ")";
  72.             return ss.str();
  73.         }
  74.     }
  75.     double getX() {
  76.         return x;
  77.     }
  78. };
  79.  
  80. #endif // _POINT_H
  81.  
  82. //point.cpp
  83. #include "point.h"
  84.  
  85. //point.h
  86. #ifndef _POINT_H
  87. #define _POINT_H
  88.  
  89. #include <string>
  90. #include <sstream>
  91.  
  92.  
  93. class Point {
  94.     double x, y;
  95.  
  96. public:
  97.     Point() {
  98.         x = 0;
  99.         y = 0;
  100.     }
  101.     Point(double a, double b) {
  102.         x = a;
  103.         y = b;
  104.     }
  105.     void move(double dx, double dy) {
  106.         x += dx;
  107.         y += dy;
  108.     }
  109.     std::string print(bool zeilenvorschub = true) {
  110.         if(zeilenvorschub) {
  111.             std::ostringstream ss;
  112.             ss << "(" << x << ", " << y << ")" << std::endl;
  113.             return ss.str();
  114.         }
  115.         if (!zeilenvorschub) {
  116.             std::ostringstream ss;
  117.             ss << "(" << x << ", " << y << ")";
  118.             return ss.str();
  119.         }
  120.     }
  121.     double getX() {
  122.         return x;
  123.     }
  124. };
  125.  
  126. #endif // _POINT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement