/******************* EDITOR VISUAL STUDIO CODE **********************/
J_3_P_3
/*********************************************************************************
Create a class vector that has arr[3] as data member and void getd() & void putd()
as member functions. Overload >> and << operators to get and display value through
object-name & these operators.
**********************************************************************************/
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class vector
{
public:
int arr[3];
public:
int getd()
{
cin >> *this; // call operator>>() function
return 0;
}
int putd()
{
cout << *this; //call operator<<() function
return 0;
}
friend ostream &operator<<(ostream &out, vector &v)
{
int i;
for (i = 0; i < 3; i++)
{
out << endl
<< v.arr[i];
}
return out;
}
friend istream &operator>>(istream &in, vector &v)
{
int i;
for ( i = 0; i < 3; i++)
{
cout << "Enter any number : ";
in >> v.arr[i];
}
return in;
}
};
int main()
{
system("cls");
vector obj;
obj.getd();
obj.putd();
// cin >> obj; call operator>>() function
// cout << obj; call operator<<() function
getch();
return 0;
}
Comments
Post a Comment