-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.cpp
163 lines (155 loc) · 2.71 KB
/
calc.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
#include <iostream>
#include "calc.h"
#include <string>
using namespace std;
calc::calc()
{
result = 2;
}
calc::switch_function_test(double s,double e,string st)
{
if(st == "prime"){
cout << "1st number -> ";
cin >>s;
cout << "2nd number -> ";
cin >>e ;
this->get_prime(s,e);
}else if(st == "even"){
cout << "1st number -> ";
cin >>s;
cout << "2nd number -> ";
cin >>e ;
this->get_even(s,e);
}else if(st == "quit"){
quit();
}else{
retest();
}
}
calc::switch_function_arithmetic(double y,char c,double p)
{
switch(c)
{
case '+':
sum(y);
break ;
case '-':
minus(y);
break;
case '/':
divided(y);
break;
case '*':
times(y);
break;
case 's':
square(p);
break;
case 'p':
power(p);
break;
default:
cout << "Enter recognizable sign" ;
}
}
void calc::recursion()
{
double y ;
char c ;
double p;
cout << " = " << result << " " ;
cin >> c ;
switch (c)
{
case 'q' :
get_choices();
break;
case 'p' :
cin >> p;
switch_function_arithmetic(y,c,p);
case 's':
cin >> p ;
switch_function_arithmetic(y,c,p);
default:
cin >> y ;
switch_function_arithmetic(y,c,p);
}
}
void calc::sum(double y)
{
result += y;
recursion();
}
void calc::minus(double y)
{
result-= y;
recursion();
}
void calc::divided(double y)
{
result /= y;
recursion();
}
void calc::times(double y)
{
result*= y;
recursion();
}
void calc::power(double p)
{
double cons = result;
for(int i = 1; i < p; i++)
{
result*=cons;
}
recursion();
}
void calc::square(double p)
{
/*
double constant = p ;
cout << "this is the result" << result <<endl;
cout << "this is the constant" << constant <<endl;
cout << "this is the p" << p <<endl;
for(int i = 0; i < p ; i++)
{
result=result / constant;
}
recursion();
*/
}
void calc::get_prime(double s,double e)
{
if(s == 1 || s == 0)
{
s = 2;
}
for(int i = s; i <= e; i++)
{
int count = 0 ;
for(int y = s; y < i ; y++ )
{
if(i % y == 0)
{
count++;
}
}
if(count == 0)
{
cout << i << " is Prime Number "<<endl;
}
}
prime_recap();
}
void calc::get_even(double s,double e)
{
(s == 0)? s = 2: 0 ;
for(int i = s; i <= e; i++)
{
if(i % 2 == 0)
{
cout <<i <<": is even"<<endl;
}
}
even_recap();
}