-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1INHHYBR.CPP
117 lines (117 loc) · 2.18 KB
/
1INHHYBR.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
class student
{
private: //s,m example shows thta private members arent inherited
double r;
char n[20];
public:
void setname()
{
cout<<"enter student name";
scanf("%s",&n);
}
void setrollno()
{
cout<<"enter roll no";
cin>>r;
}
void showrollno()
{
cout<<"\nstudent's roll no is";
cout<<r;
}
void showname()
{
cout<<"\nstudent name is";
printf("%s",n);
}
};
class test:public student
{
private:
double m;
protected:
double s;
public:
/*double gets() //protected member accessible by same class member function
{return s;}*/
void setmarks()
{
cout<<"\nenter science and maths marks";
cin>>s>>m;
}
void showmarks()
{
cout<<"\nscience="<<s<<"\nmaths="<<m;
}
double totalmarks()
{
double z;
z=s+m;
return(z);
}
};
class sports
{
private:
double h,c;
public:
void setscore()
{
cout<<"\nenter score of hockey and cricket of student";
cin>>h>>c;
}
void showscore()
{
cout<<"\nhockey score="<<h<<"\ncricket score="<<c;
}
double totalscore()
{
double y;
y=h+c;
return(y);
}
};
class result: public test, public sports
{
private:
double t;
public:
/*double getm() //yaha m ki value inherit hui hi nhi kyuki private toh
{return(m);} */ //variables inherit nhi hote m test class me private bana
double gets() //rakha h toh ye error dega par s protected member h
{ //toh s inherit ho jayega result class ke protected part me
return(s); //s variable test class ke member function se accessible
} //hoga ya phir koi class jo ki test class se immediately
void total() //derive hui h us class ke member function se
{
t=totalscore()+totalmarks();
cout<<"\ntotal="<<t;
}
};
class C:public result
{
public:
double gets()
{return s;}
};
void main()
{
clrscr();
result R;
R.setname();
R.setrollno();
R.setmarks();
R.setscore();
R.showname();
R.showmarks();
R.showscore();
R.total();
cout<<"\n science marks"<<R.gets();
/*cout<<"\n"<<R.getm(); */
C obj;
cout<<"\ngarbage value"<<obj.gets(); //gives garbage value kyuki protected immediately
getch(); //derived class me se hi access ho skta h
}