-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_orianted_programing_basic.cpp
More file actions
64 lines (55 loc) · 1.48 KB
/
object_orianted_programing_basic.cpp
File metadata and controls
64 lines (55 loc) · 1.48 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
#include <string>
#include <iostream>
using namespace std;
class binary
{
private:
string s;
public:
void getdata(void);
void chk_num();
};
void binary ::getdata(void)
{
cout << "Enter the number :" << endl;
cin >> s;
}
void binary :: chk_num(void){
for (int i = 0; i < s.length() ; i++)
{
if (s.at(i)!='0' && s.at(i)!='1')
{
cout<<"Enter number is not binary"<<endl;
exit(0);
}
else{
if (s.at(i)=='0')
{
s.at(i)='1';
}
else{
s.at(i)='0';
}
}
}
cout<<s<<endl;
}
int main()
{
// OOPS - Classes and objects
// class --> extension of structures (in c)
// structures had limitions like
// -all members are public
// -no methods
// classes --> structures + more + can have methods and properties
// classes --> it contains private and public
// structures in C++ are typedefed
// you can also declare objects along with the class declarion like this:
/* class Student{
// Class definition
}Aditya,Gitajali,Rushya;
*/
binary num ;
num.getdata();
num.chk_num();
}