-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtu22.cpp
83 lines (72 loc) · 1.7 KB
/
tu22.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
76
77
78
79
80
81
82
83
// OOPs - Classes and objects
// C++ --> initially called --> C with classes by stroustroup
// class --> extension of structures (in C)
// structures had limitations
// - members are public
// - No methods
// classes --> structures + more
// classes --> can have methods and properties
// classes --> can make few members as private & few as public
// structures in C++ are typedefed
// you can declare objects along with the class declarion like this:
/* class Employee{
// Class definition
} harry, rohan, lovish; */
// harry.salary = 8 makes no sense if salary is private
// Nesting of member functions
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
class binary
{
void chk_bnry();
string s;
public:
void read();
void one_s();
void display();
};
void binary:: read()
{
cout<<"Enter the binary number "<<endl;
cin>>s;
chk_bnry();
}
void binary :: chk_bnry()
{
for(int i=0;i<s.length();i++)
{
if((s.at(i)!='0') &&(s.at(i)!='1'))
cout<<"Incorrect Value "<<endl;
// exit(0);
}
}
void binary:: one_s()
{
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()
{
cout<<"The one_s complement is:"<<endl;
for(int i=0;i<s.length();i++)
{
cout<<s.at(i);
}
}
int main(){
name();
binary b;
b.read();
// b.chk_bnry();
b.one_s();
b.display();
return 0;
}