-
Notifications
You must be signed in to change notification settings - Fork 0
/
class1.cpp
61 lines (59 loc) · 1.24 KB
/
class1.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
#include <iostream>
#include <string.h>
using namespace std;
class binary
{
string a;//by default all this member in class are private which are not in public
// void check(void);//function can be made private but it can not be directly accessible
public:
void value(void);
void check(void);
void ones_compliment(void);
void display(void);
};
void binary::value(void)
{
cout << "enter the value of binary number" << endl;
cin >> a;
}
void binary::check(void)
{
for (int i = 0; i < a.length(); i++)
{
if (a.at(i) != '0' && a.at(i) != '1')
{
cout << "it isn't binary number" << endl;
exit(0);
}
}
}
void binary::ones_compliment()
{ check();//nested member function
for (int i = 0; i < a.length(); i++)
{
if (a.at(i) == '0')
{
a.at(i) = '1';
}
else
{
a.at(i) = '0';
}
}
}
void binary::display()
{ cout<<"it's compliment is "<<endl;
for (int i = 0; i < a.length(); i++)
{
cout<< a.at(i);
}
}
int main()
{
binary b;
b.value();
//b.check();
b.ones_compliment();
b.display();
return 0;
}