{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

code 1 - void main vector k vector is called...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
vector operator * (double a) { vector r; r.x = x * a; r.y = y * a; return r; } }; void main (void) { vector a, b; a.x = 3; b.y = 5; b = a.its_oposite(); cout << "Vector a : " << a.x << ", " << a.y << endl; cout << "Vector b : " << b.x << ", " << b.y << endl; b.be_oposited(); cout << "Vector b : " << b.x << ", " << b.y << endl; a.be_calculated (7, 8, 3, 2); cout << "Vector a : " << a.x << ", " << a.y << endl; a = b * 2; cout << "Vector a : " << a.x << ", " << a.y << endl; a = b.its_oposite() * 2; cout << "Vector a : " << a.x << ", " << a.y << endl; class vector { public: double x; double y; vector () // same name as class { x = 0; y = 0; } vector (double a, double b) { x = a; y = b;
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } }; void main () { vector k; // vector () is called cout << "vector k : " << k.x << ", " << k.y << endl << endl; vector m (45, 2); // vector (double, double) is called cout << "vector m : " << m.x << ", " << m.y << endl << endl; k = vector (23, 2); // vector created, copied to k, then erased cout << "vector k : " << k.x << ", " << k.y << endl << endl; } It is a good practice to try not to overload the constructors. Best is to declare only one constructor and give it default parameters wherever possible : #include <iostream.h> class vector { public: double x; double y; vector (double a = 0, double b = 0) {}...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern