Answer to Question #257978 in C++ for Amit

Question #257978

Write a program to overload unary (-) operator.


1
Expert's answer
2021-10-29T00:54:44-0400


SOLUTION FOR ABOVE QUESTION


#include <iostream>

using namespace std;

#include<conio.h>

class complex {

//declarare three variables

  int variable_1, variable_2, c;

public:


  complex() {

  }

   

   //A function to get value from the user

  void getvalue() {

    cout << "Enter the Two Numbers:";

    cin >> variable_1>>variable_2;

  }


  void operator++() {

    variable_1 = ++variable_1;

    variable_2 = ++variable_2;

  }


  void operator--() {

    variable_1 = --variable_1;

    variable_2 = --variable_2;

  }

 //Definition of a method for dispaly/ show

  void display() {

    cout << variable_1 << "+\t" << variable_2 << "i" << endl;

  }

};


//definition of the main method


void main() {

  clrscr();

  complex my_object;

  my_object.getvalue();

  my_object++;

  cout << "Increment Complex Number\n";

  my_object.display();

  my_object--;

  cout << "Decrement Complex Number\n";

  my_object.display();

  getch();

  return 0;

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS