-
Notifications
You must be signed in to change notification settings - Fork 548
/
Copy path10_03.cpp
47 lines (38 loc) · 845 Bytes
/
10_03.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
#include <bits/stdc++.h>
using namespace std;
class Person {
protected:
// Act as private for outsiders
// But inherited children can see it
string name = "Mostafa";
string email = "most@gmail";
public:
bool IsValidEmailFormat() {
return true;
}
};
class Student: public Person {
private:
double GPA;
public:
void PrintGrades() {
// Now we can see name again, but outsiders can't
cout << name << " GPA=" << GPA << "\n";
}
void SetGpa(double gpa) {
GPA = gpa;
}
};
int main() {
Student student;
// Student is a person.
student.SetGpa(3.5);
student.IsValidEmailFormat();
student.PrintGrades();
//Person is not necessarily a student
Person person;
//person.email; // can't: protected is like private for outsiders
person.IsValidEmailFormat();
//person.PrintGrades(); // no nothing about student!
return 0;
}