Title: Classes 2
1Classes 2
2Class Declaration
class Vector public Vector() x y z
0 Vector (double,double,double)
double getX() const return x double getY()
const return y double getZ() const return
z double magnitude() const private
double x,y,z friend istream operator gtgt
(istream, Vector) friend ostream operator
ltlt (ostream, const Vector)
Constructors
Prototypes of member functions
Data Members
Prototypes of friend functions
3Using our New Function
// v1 and v2 are objects of class Vector cout ltlt
"adding " ltlt endl v1.adding(v2) cout ltlt v1
4New Function
- In our example we had 4 member functions.
- We are adding a new member
double getX() const return x double
getY() const return y double getZ() const
return z double magnitude() const
- - remember this function is called
- in a way similar to
- v1.adding(v2)
- x, y and z are v1s attributes
- v1 is being modified
- vec2s members are referenced by using dot (.)
Prototype void adding(Vector) Function void
Vectoradding(Vector vec2) xxvec2.x
yyvec2.y zzvec2.z