0% found this document useful (0 votes)
53 views25 pages

Document 1

The document contains code submissions for an object oriented programming assignment. It includes 14 code snippets demonstrating the overloading of operators like increment, decrement, addition, subtraction, multiplication, division and modulo for a class. Each code snippet contains a class with private data members and public member functions to set and get values and overload an operator. They are submitted by a student named Adeel Ahmad for their 3rd semester BSSE class.

Uploaded by

haseeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views25 pages

Document 1

The document contains code submissions for an object oriented programming assignment. It includes 14 code snippets demonstrating the overloading of operators like increment, decrement, addition, subtraction, multiplication, division and modulo for a class. Each code snippet contains a class with private data members and public member functions to set and get values and overload an operator. They are submitted by a student named Adeel Ahmad for their 3rd semester BSSE class.

Uploaded by

haseeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

OBJECT ORIENTED PRGRAMMING

ASSIGNMENT

NAME : ADEEL AHMAD


ROLL No. : 8909
CLASS : BSSE (3rd SEMESTER)

SUBMITTED TO = MAAM HIRA ASHFAQ


1
#include <iostream>
using namespace std;
class test
{
private:
int n;
public:
test()
{
n=0;
}
void show()
{
cout<< "n = " << n <<endl;
}
void operator ++()
{
n++;
}
};
int main()
{
test t;
t.show();
++t;

2
t.show();

}
________________________________________________________
#include <iostream>

using namespace std;

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>

using namespace std;

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>

using namespace std;

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;
}

void operator - (void)


{
n=-n;
}
};

int main()
{
test num;

7
num.gettest(10);
-num;
num.displaytest();
cout << endl;
return 0;

}
________________________________________________________
_
#include <iostream>

using namespace std;

class add

private:

int a , b;

public:

8
add()

a=b=0;

void input()

cout<< "Enter value of A " <<endl;


cin>>a;
cout<< "Enter value of B " <<endl;
cin>>b;
}
void show()
{
cout << "A = " << a << endl;
cout << "B = " << b << endl;

}
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()

cout<< "Enter value of A " <<endl;


cin>>a;
cout<< "Enter value of B " <<endl;
cin>>b;
}
void show()
{
cout << "A = " << a << endl;
cout << "B = " << b << endl;

}
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>

using namespace std;

class product

13
{

private:

int a , b;

public:

product()

a=b=0;

void input()

cout<< "Enter value of A " <<endl;


cin>>a;
cout<< "Enter value of B " <<endl;
cin>>b;
}

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>

using namespace std;

class divide

private:

float a , b;

public:

16
divide()

a=b=0;

void input()

cout<< "Enter value of A " <<endl;


cin>>a;
cout<< "Enter value of B " <<endl;
cin>>b;
}
void show()
{
cout << "A = " << a << endl;
cout << "B = " << b << endl;

}
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>

using namespace std;

class mod

private:

19
int a , b;

public:

mod()

a=b=0;

20
void input()

cout<< "Enter value of A " <<endl;

cin>>a;

cout<< "Enter value of B " <<endl;

cin>>b;

void show()

cout << "A = " << a << endl;

21
cout << "B = " << b << endl;

mod operator %(mod p)

{ 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy