#include using namespace std; class CVector {  int x,y;  public:  CVector () {};  CVector (int,int);  CVector operato

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 22SA
icon
Related questions
Question

include a functionality to overload stream extraction operator

Include a functionality to overload stream insertion operator

Overload power operator

 

 

#include <iostream>

using namespace std;

class CVector {

 int x,y;

 public:

 CVector () {};

 CVector (int,int);

 CVector operator + (CVector);

 void print();

 

};

void CVector::print()

{

              cout <<x << "," << y;

}

CVector::CVector (int x, int y) {

 this->x = x;

 this->y = y;

}

CVector CVector::operator+ (CVector param) {

 CVector temp;

 temp.x = this->x + param.x;

 temp.y = this->y + param.y;

 return temp;

}

int main () {

 CVector a (3,1);

 CVector b (4,9);

 CVector c;

 c = a.operator +(b);

 c.print();

 return 0;

}

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning