Advertisement
szdani96

Untitled

Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Vector {
  7. double x,y;
  8. public:
  9. Vector(double,double);
  10. Vector();
  11. void print();
  12. double abs();
  13. };
  14.  
  15. Vector::Vector(double x, double y) {
  16. this->x = x;
  17. this->y = y;
  18. }
  19.  
  20. Vector::Vector() {
  21. cin >> x >> y;
  22. }
  23.  
  24. void Vector::print() {
  25. cout << "(" << x << "," << y << ")";
  26. }
  27.  
  28. double Vector::abs() {
  29. return sqrt(x*x+y*y);
  30. }
  31. class ColorVector:Vector{
  32. double x,y;
  33. char * szin;
  34. public:
  35. ColorVector(double,double,char *);
  36. void print();
  37. };
  38. ColorVector::ColorVector(double x,double y,char * szin):Vector(x,y){
  39. this->szin=szin;
  40.  
  41. }
  42. void ColorVector::print(){
  43. cout<<"("<<x<<","<<y<<")["<<szin<<"]";
  44. }
  45. int main(int argc, char** argv) {
  46. /*Vector *v = new Vector();
  47. v->print();
  48. cout << v->abs();
  49. delete v;
  50. //Vector v;
  51. //v.print();
  52. //cout << v.abs();*/
  53. cout<< std::endl;
  54. ColorVector *k=new ColorVector(1,2,"piros");
  55. k->print();
  56. delete k;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement