-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calculator.cpp
180 lines (164 loc) · 3.65 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include<iostream>
#include<math.h>
using namespace std;
int add()
{
int nos[20],i,limit,sum=0;
cout<<"How many nos to be added-";
cin>>limit;
cout<<"Enter the nos-";
for(i=1;i<=limit;i++)
{
cin>>nos[i];
sum=sum+nos[i];
}
cout<<"Sum is "<<sum;
}
int subtract()
{
int nos[20],i,limit,diff=0;
cout<<"How many nos to be subtracted-";
cin>>limit;
cout<<"Enter the nos-";
for(i=1;i<=limit;i++)
{
cin>>nos[i];
diff=nos[i]-diff;
}
cout<<"Difference is "<<diff;
}
int multiply()
{
int nos[20],i,limit,prod=1;
cout<<"How many nos to be multiplied-";
cin>>limit;
cout<<"Enter the nos-";
for(i=1;i<=limit;i++)
{
cin>>nos[i];
prod=prod*nos[i];
}
cout<<"Product is "<<prod;
}
int divide()
{
int nos[20],i,limit;
float quo=1;
cout<<"How many nos to be divided-";
cin>>limit;
cout<<"Enter the nos-";
for(i=1;i<=limit;i++)
{
cin>>nos[i];
quo=nos[i]/quo;
}
cout<<"Quotient is "<<quo;
}
int logarithm()
{
int base,no;
float val;
cout<<"\nEnter base and argument-";
cin>>base>>no;
val=(log(no))/(log(base));
cout<<val;
}
int trig()
{
float angle,base,perp,hyp,val1,val2,val3;
int opt2,opt3;
cout<<"\nDo you have angle(1) or sides(2)-";
cin>>opt2;
if(opt2==1)
{
cout<<"Enter angle in degree";
cin>>angle;
angle=9((22/7)*angle)/180;
cout<<"Do you want sin(1),tan(2),cos(3)-";
cin>>opt3;
switch(opt3)
{
case 1:{val3=sin(angle);
cout<<"Sine value- "<<val3;
break;
}
case 2:{val3=cos(angle);
cout<<"Cosine value- "<<val3;
break;
}
case 3:{val3=tan(angle);
cout<<"Sine value- "<<val3;
break;
}
}
(val1=sin(angle);
cout<<val1;
}
else
{
cout<<"Enter base and perpendicular length-";
cin>>base>>perp;
cout<<"Do you want sin(1),tan(2),cos(3)-";
hyp=sqrt(((base)*(base))+(perp*perp));
cin>>opt2;
switch(opt2)
{
case 1:{val2=perp/hyp;
cout<<"Sine value- "<<val2;
break;
}
case 2:{val2=base/hyp;
cout<<"Cosine value- "<<val2;
break;
}
case 3:{val2=perp/base;
cout<<"Tangent value- "<<val2;
break;
}
default:{cout<<"Invalid option.";
break;
}
}
}
}
int power()
{
float x,y;
cout<<"Enter 2 nos";
cin>>x>>y;
cout<<pow(x,y);
}
int main()
{
int opt;
cout<<"Calculator-";
cout<<"\n1. Add";
cout<<"\n2. Subtract";
cout<<"\n3. Multiply";
cout<<"\n4. Divide";
cout<<"\n5. Logarithm";
cout<<"\n6. Trigonometric fn";
cout<<"\n7. Power";
cout<<"\nEnter option-";
cin>>opt;
switch(opt)
{
case 1:{add();
break;}
case 2:{subtract();
break;}
case 3:{multiply();
break;}
case 4:{divide();
break;}
case 5:{logarithm();
break;}
case 6:{trig();
break; }
case 7:{power();
break;}
default:{cout<<"Invalid option";
break;}
}
return 0;
}