-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21nesting.cpp
More file actions
65 lines (63 loc) · 1.07 KB
/
Copy path21nesting.cpp
File metadata and controls
65 lines (63 loc) · 1.07 KB
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
#include <iostream>
using namespace std;
class binary
{
private: //by default, members of a class are private
string s;
void chk_bin();
public:
void read();
void ones();
void display();
};
void binary ::read()
{
cout << "Enter a binary number" << endl;
cin >> s;
}
void binary ::chk_bin()
{
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) != '0' && s.at(i) != '1')
{
cout << "Incorrect binary number" << endl;
exit(0);
}
}
}
void binary ::ones()
{
chk_bin();
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) == '0')
{
s.at(i) = '1';
}
else if (s.at(i) == '1')
{
s.at(i) = '0';
}
}
}
void binary ::display()
{
cout << "Displaying the binary number" << endl;
for (int i = 0; i < s.length(); i++)
{
cout << s.at(i);
}
cout<<endl;
}
int main()
{
binary b;
b.read();
//b.chk_bin();
b.display();
b.ones();
cout << endl;
b.display();
return 0;
}