0% found this document useful (0 votes)
2 views

Assignment N4

The document presents an assignment on overloading the unary decrement operator in C++. It defines a class 'unarydemo' with three integer variables and implements the operator to decrement their values. The main function demonstrates the functionality before and after overloading the operator, showing the changes in variable values.

Uploaded by

shreya.d2829
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment N4

The document presents an assignment on overloading the unary decrement operator in C++. It defines a class 'unarydemo' with three integer variables and implements the operator to decrement their values. The main function demonstrates the functionality before and after overloading the operator, showing the changes in variable values.

Uploaded by

shreya.d2829
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No:5

Name: Shreya Ravindra Desai


Roll No:9354
//Q: Write OOP to overload unary - -operator to
decrement value of variable

include<iostream.h>
#include<conio.h>
class unarydemo
{
int x,y,z;
public:
unarydemo(int,int,int);
void display();
void operator - -();
};
unarydemo :: unarydemo(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void unarydemo:: display()
{
cout<<"\n x="<<x;
cout<<"\n y="<<y;
cout<<"\n z="<<z;
}
void unarydemo:: operator- -()
{
x= - -x;
y= - -y;
z= - -z;
}
void main()
{
unarydemo d(10,20,30);
cout<<"\n Before overloading:";
d.display();
- -d;
cout<<"\n After overloading:";
d.display();
getch();
}
/*
Before overloading:
x=10
y=20
z=30
After overloading:
x= 9
y= 19
z= 29
*/

You might also like