-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnew24.cpp
66 lines (61 loc) · 985 Bytes
/
new24.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
#include<iostream>
#include<cstring>
using namespace std;
class binary
{
string s;
public:
void read(void);
int check_binary(void);
void display(void);
void ones_complement(void);
};
void binary::ones_complement(void)
{
for (int i = 0; i < s.length(); i++)
{
if(s.at(i)=='0')
s.at(i)='1';
else
s.at(i)='0';
}
cout<<"ones complement is"<<s<<endl;
}
void binary::read(void)
{
cout<<"enter a binary no.";
cin>>s;
}
int binary::check_binary(void)
{
for (int i = 0; i < s.length(); i++)
{
if(s.at(i)!='0' && s.at(i)!='1' )
{
cout<<"the no. is not binary"<<endl;
exit(0);
}
}
return 0;
}
void binary::display(void)
{
cout<<"the original no. is"<<s<<endl;
}
int main()
{
binary b;
int z;
b.read();
z = b.check_binary();
if(z==0)
{
cout<<"the no. is binary"<<endl;
}
else
exit(0);
cout<<"hello";
b.display();
b.ones_complement();
return 0;
}