forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnestingMF.cpp
More file actions
75 lines (61 loc) · 1.3 KB
/
nestingMF.cpp
File metadata and controls
75 lines (61 loc) · 1.3 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
66
67
68
69
70
71
72
73
74
75
#include<iostream>
#include<string>
using namespace std;
class binary
{
private:
string str;
void checkBinary(void);
public:
void inpBinary(void);
void dispBinary(void);
void onesCompliment(void);
};
void binary :: inpBinary(void){
cout<<"Enter the binary number"<<endl;
cin>>str;
}
void binary :: checkBinary(void)
{
for(int i =0; i<str.length(); i++){
if(str.at(i)!='0' && str.at(i)!='1')
{
cout<<"Incorrect Binary input"<<endl;
exit(0);
}
}
}
void binary::dispBinary(void)
{
cout<<"Displaying the binary "<<endl;
for(int i=0; i<str.length(); i++)
{
cout<<str.at(i);
}
cout<<endl;
}
void binary :: onesCompliment(void)
{
checkBinary();
for(int i=0; i<str.length(); i++)
{
if(str.at(i)=='0')
{
str.at(i)='1';
}
else
{
str.at(i)='0';
}
}
}
int main()
{
binary bin;
bin.inpBinary();
bin.onesCompliment();
bin.dispBinary();
// bin.checkBinary(); //its a private data member so that can not be accesed expect the class members only accesedby the member function of the same class
return 0;
}
// *******NESTING OF MEMBER FUNCTION***********