C++ program to overload ++ increment operator for vectors using member function.

#include<iostream.h>
#include<conio.h>
class vector{
float x,y,z;
public:
vector(){
x=y=z=0;
}
vector(float x1,float y1,float z1){
x=x1;
y=y1;
z=z1;
}
void display(){
cout<<"( "<<x<<")i+ ("<<y<<")j+("<<z<<")k"<<endl;
}
void operator++();
};
void vector::operator++(){
x=++x;
y=++y;
z=++z;
}
void main(){
vector v1(3,7,5);
clrscr();
v1.display();
++v1;
v1.display();
getch();
}

No comments:

Post a Comment