Write a program to use unary operator overloading with constructor


 

/* Write a program to use unary operator overloading with constructor*/

#include<iostream.h>

#include<conio.h>

class score

{

int val;

public:

score()

{

val=0;

}

void increment()

{

val=val+1;

}

int show()

{

return(val);

}};

void main()

{

clrscr();

score s1,s2;

cout<<“value of s1=”<<s1.show()<<endl;

cout<<“value of s2=”<<s2.show()<<endl;

s1.increment();

s1.increment();

s2.increment();

cout<<“value of s1=”<<s1.show()<<endl;

cout<<“value of s2=”<<s2.show();

getch();

}

/*output:

value of s1=0

value of s2=0

value of s1=2

value of s2=1*/

Related Posts

Comments are closed.