Document 1
Document 1
Document 1
ASSIGNMENT
2
t.show();
}
________________________________________________________
#include <iostream>
class test
{
private:
int n;
public:
test()
{
n=0;
}
void show()
{
cout<< "n = " << n <<endl;
}
void operator --()
{
n--;
}
3
};
int main()
{
test t;
t.show();
--t;
t.show();
}
________________________________________________________
#include <iostream>
class test
{
private:
int n;
public:
test()
{
n=0;
}
void show()
{
cout<< "n = " << n <<endl;
4
}
void operator ++(int)
{
n++;
}
};
int main()
{
test t;
t.show();
t++;
t.show();
}
________________________________________________________
____
#include <iostream>
class test
{
private:
int n;
public:
test()
5
{
n=0;
}
void show()
{
cout<< "n = " << n <<endl;
}
void operator --(int)
{
n--;
}
};
int main()
{
test t;
t.show();
t--;
t.show();
}
________________________________________________________
___
#include<iostream>
using namespace std;
class test
6
{
private:
int n;
public:
void gettest(int x)
{
n=x;
}
void displaytest(void)
{
cout << "value of n is: " << n;
}
int main()
{
test num;
7
num.gettest(10);
-num;
num.displaytest();
cout << endl;
return 0;
}
________________________________________________________
_
#include <iostream>
class add
private:
int a , b;
public:
8
add()
a=b=0;
void input()
}
add operator +(add p)
9
{ add temp;
temp.a=p.a+a;
temp.b=p.b+b;
return temp;
};
int main()
add x,y,z ;
x.input();
y.input();
z=x+y;
x.show();
y.show();
z.show();
}
________________________________________________________
#include <iostream>
10
using namespace std;
class sub
private:
int a , b;
public:
sub()
a=b=0;
11
void input()
}
sub operator -(sub p)
{ sub temp;
temp.a=p.a-a;
temp.b=p.b-b;
return temp;
};
12
int main()
sub x,y,z ;
x.input();
y.input();
z=y-x;
x.show();
y.show();
z.show();
}
________________________________________________________
#include <iostream>
class product
13
{
private:
int a , b;
public:
product()
a=b=0;
void input()
14
void show()
{
cout << "A = " << a << endl;
cout << "B = " << b << endl;
}
product operator *(product p)
{ product temp;
temp.a=p.a*a;
temp.b=p.b*b;
return temp;
};
int main()
product x,y,z ;
x.input();
y.input();
z=y*x;
15
x.show();
y.show();
z.show();
}
________________________________________________________
#include <iostream>
class divide
private:
float a , b;
public:
16
divide()
a=b=0;
void input()
}
divide operator /(divide p)
17
{ divide temp;
temp.a=p.a/a;
temp.b=p.b/b;
return temp;
};
int main()
divide x,y,z ;
x.input();
y.input();
z=y/x;
x.show();
y.show();
z.show();
}
________________________________________________________
18
#include <iostream>
class mod
private:
19
int a , b;
public:
mod()
a=b=0;
20
void input()
cin>>a;
cin>>b;
void show()
21
cout << "B = " << b << endl;
{ mod temp;
temp.a=p.a%a;
temp.b=p.b%b;
return temp;
22
};
int main()
mod x,y,z ;
x.input();
y.input();
z=y%x;
x.show();
y.show();
z.show();
23
}
24