Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

SUBMITTED BY: ARIBA DASTGIR

SUBMITTED TO: MA’AM HINA SATTAR

DEPARTMENT: COMPUTER SCIENCE

ROLL NO. BSCS/FA22/015

SEMESTER: 2 ND

SUBJECT: OBJECT ORIENTED

PROGRAMMING
ASSIGNMENT NO.1

C++ program to use arithmetic operations with the help of operator


overloading and switch statement.

#include <iostream>
using namespace std;
class Arithmetic{
private:
double a;
public:
void input(){
cout<<"Enter you value:";
cin>>a;}
Arithmetic operator +(Arithmetic obj){
Arithmetic b;
b.a=a+obj.a;
return(b);
}
void display(){
cout<<"Sum of your numbers:"<<a;}
Arithmetic operator -(Arithmetic obj){
Arithmetic b;
b.a=a-obj.a;
return(b);
}
void display1(){
cout<<"Difference of your numbers:"<<a;}
Arithmetic operator /(Arithmetic obj){
Arithmetic b;
b.a=a/obj.a;
return(b);
}
void display2(){
cout<<"Quotent of your numbers:"<<a;}
Arithmetic operator *(Arithmetic obj){
Arithmetic b;
b.a=a*obj.a;
return(b);
}
void display3(){
cout<<"Product of your numbers:"<<a;}
};
int main(){
int c;
Arithmetic object1;
Arithmetic object2;
Arithmetic object3;
cout<<"Following are the options:\n 1. Sum \n 2. Difference \n 3. Quotient \n
4. Product "<<endl;
cout<<"Choose one of the following by values:";
cin>>c;
switch(c){
case 1:
{object1.input();
object2.input();
object3=object1+object2;
object3.display();
break;
}
case 2:
{object1.input();
object2.input();
object3=object1-object2;
object3.display1();
break;}
case 3:
{object1.input();
object2.input();
object3=object1/object2;
object3.display2();
break;}
case 4:
{object1.input();
object2.input();
object3=object1*object2;
object3.display3();
break;}
default:
{cout<<"INVALID INPUT! Choose from 1 to 4.";
break;}
}
}

OUTPUT:

You might also like