-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_classes1.cpp
54 lines (51 loc) · 1.05 KB
/
4_classes1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by Varsha on 21-03-2023.
//
//Write a class to do all 4 arithmetic functions. Depending on the user's choice, one
//of the operation is performed.
#include <iostream>
using namespace std;
class calculator{
private:
int a,b;
public:
void getdata(){
cout<<"Enter the numbers: ";
cin>>a>>b;
}
int add(){
return a+b;
}
int sub(){
return a-b;
}
int mul(){
return a*b;
}
float div(){
return (float)a/b;
}
};
int main(){
calculator ob;
int choice;
ob.getdata();
cout<<"Enter the choice: \n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n";
cin>>choice;
switch(choice){
case 1:
cout<<"Sum: "<<ob.add();
break;
case 2:
cout<<"Difference: "<<ob.sub();
break;
case 3:
cout<<"Product: "<<ob.mul();
break;
case 4:
cout<<"Quotient: "<<ob.div();
break;
default:
cout<<"Invalid choice";
}
}