-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20classes_pub_pvt.cpp
More file actions
58 lines (53 loc) · 1.44 KB
/
Copy path20classes_pub_pvt.cpp
File metadata and controls
58 lines (53 loc) · 1.44 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
#include <iostream>
using namespace std;
class Employee
{
private: // this stores private information and only a public function can access them
int a, b, c;
public: // this stores public information that can be directly accessed to
int d, e;
void setData(int x, int y, int z); // here the function declarated or prototyped
void getData() // here the function is created
{
cout << "The value of a is " << a << endl;
cout << "The value of b is " << b << endl;
cout << "The value of c is " << c << endl;
cout << "The value of d is " << d << endl;
cout << "The value of e is " << e << endl;
}
};
void Employee ::setData(int x, int y, int z) // syntax for any function of a class so that it could be accessed
{
a = x;
b = y;
c = z;
}
// it is better to create prototyped functions in the classes to maintain clarity
class Animal
{
private:
char genus[15];
char family[15];
public:
char type[15];
char sound[15];
void soundmade();
};
void Animal :: sound(char &sound[15])
{
cout<<"The sound "<<" gives is "<<sound<<endl;
}
int main()
{
// class is a kind of structure which can be protected and can store functions
Employee vasu;
// vasu.a = 1; accessing private data results in error
vasu.d = 12;
vasu.e = 5;
vasu.setData(1, 2, 3);
vasu.getData();
Animal dog;
dog.sound = "bark";
dog.sound("bark");
return 0;
}