-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCALCULATOR.CPP
100 lines (90 loc) · 1.86 KB
/
CALCULATOR.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
using namespace std;
class calculator
{
float n1,n2;
public:
void getdata()
{
cout << "Enter two number: " << endl;
cin >> n1 >> n2 ;
}
void getfdata()
{
cout << "Enter a number more than zero: " << endl;
cin >> n1 ;
}
float add()
{
return n1+n2;
}
float sub()
{
return n1-n2;
}
float mul()
{
return n1*n2;
}
float div()
{
return n1/n2;
}
int rem()
{
int c = (int) n1 % (int) n2 ;
return c;
}
float fact()
{
float f=1;
for(int i=2;i<=n1;i++)
f*=i;
return f;
}
};
int main()
{
int n;
char ch;
calculator c1;
do
{
cout << "What do you want to do ?" << endl;
cout << "1. Add\t2. Sub\t3. Mul\n4. Div\t5. Rem\t6. Fact" << endl;
cin >> n;
switch(n)
{
case 1:
c1.getdata();
cout << "The sum is " << c1.add() << endl;
break;
case 2:
c1.getdata();
cout << "The difference is "<< c1.sub() << endl;
break;
case 3:
c1.getdata();
cout << "The product is " << c1.mul() << endl;
break;
case 4:
c1.getdata();
cout << "The quotient is " << c1.div() << endl;
break;
case 5:
c1.getdata();
cout << "The remainder is " << c1.rem() << endl;
break;
case 6:
c1.getfdata();
cout << "The factorial is " << c1.fact() << endl;
break;
default:
cout << "Invalid choice !" << endl;
}
cout << "Do you want to continue ?" << endl;
cout << "Enter y for yes !" << endl;
cin >> ch;
} while (ch == 'y');
return 0;
}