-
Notifications
You must be signed in to change notification settings - Fork 1
/
oop_tut02.cpp
75 lines (65 loc) · 1.27 KB
/
oop_tut02.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
#include <iostream>
#include <string>
using namespace std;
class binary
{
private:
string s;
void check_bin(void);
public:
void read(void);
void ones_compliment(void);
void display(void);
};
void binary ::read(void)
{
cout << "Enter your number : " << endl;
cin >> s;
}
void binary ::check_bin(void)
{
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) != '0' && s.at(i) != '1')
{
cout << "please ! Enter correct binary format . " << endl;
exit(0);
cout << endl;
}
}
}
void binary ::ones_compliment(void)
{
check_bin(); /*--> Nesting of memeber funtion .( Recal a private function
within a function ) */
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) == '0')
{
s.at(i) = '1';
}
else
{
s.at(i) = '0';
}
}
}
void binary ::display(void)
{
cout << "Display your Binary number : " << endl;
for (int i = 0; i < s.length(); i++)
{
cout << s.at(i);
}
cout << endl;
}
int main()
{
binary b;
b.read();
// b.check_bin(); --> Error ! ceck-bin is private .
b.display();
b.ones_compliment();
b.display();
return 0;
}