-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht26.cpp
More file actions
83 lines (76 loc) · 1.99 KB
/
t26.cpp
File metadata and controls
83 lines (76 loc) · 1.99 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
76
77
78
79
80
81
82
83
// nesting of member function
// oops classes and objects
// c++ intialy called c with classes by stroustroup
// class extention of structure
// structure had limitation
// ----> members are public
//-----> no methods
// classes = structure +more
// classes can have methods and property
// classes can make few member as private and public
// structure in c++ are typedef
// u can declare object along with class declaration
/*class Employee{
// class defination }
prince,harry,rohan */
// prince.salary it dont make any sence if salary is private
// nesting of member function
#include <iostream>
#include <string>
using namespace std;
class binary
{
private://if u not write public then also it will be fine as it is considerd private by default
string s;
public:
void read(void);//will read wether the no is binary or not
void chk_bin(void);//will check wheter it is binary or not
void ones(void);//will change 1 to 0 and 0 to 1
void display(void); //will display the no
};
void binary ::read(void)
{
cout << "enter a binary number" << endl;
cin >> s;
}
void binary :: chk_bin(void)
{
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) != '0' && s.at(i) != '1')
{
cout << "incorrect binary format" << endl;
exit(0);
}
}
}
void binary:: ones(void) //understand ones as compliment
{
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<<"displaying your binary number "<<endl;
for (int i = 0; i < s.length(); i++)
{
cout<<s.at(i);
}
}
int main()
{
binary b;
b.read();
b.chk_bin();
b.display();
b.ones();
b.display();
return 0;
}