-
Notifications
You must be signed in to change notification settings - Fork 0
/
binaryClass.cpp
73 lines (65 loc) · 1.11 KB
/
binaryClass.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
#include <iostream>
#include <string>
using namespace std;
//program to take a binary string from user and return its ones compliment
class binary
{
private:
string s;
void chck_bin();
bool stopp = false;
public:
void binaryinp()
{
cout << "Enter a binary String: ";
cin >> s;
}
void ones_comp();
};
void binary ::ones_comp()
{
chck_bin();
if (!stopp)
{
int i = 0;
while (i < s.length())
{
if (s[i] == '1')
{
s[i] = '0';
}
else
{
s[i] = '1';
}
i++;
}
cout <<"Ones compliment is: "<<s;
}
else{
cout<<"Exit from program";
}
}
void binary ::chck_bin()
{
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '0' || s[i] == '1')
{
stopp = false;
}
else
{
cout << "Invalid Binary"<<endl;
stopp = true;
break;
}
}
}
int main()
{
binary bin;
bin.binaryinp();
bin.ones_comp();
return 0;
}