-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelec mecha classes.cpp
167 lines (111 loc) · 2.79 KB
/
elec mecha classes.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
using namespace std;
class Mechatronics;
class Electrical{
friend class Mechatronics;
private:
string name;
double marks;
public:
Electrical();
Electrical(string name);
Electrical(double marks);
Electrical(string name, double marks);
void set();
void average(Electrical e2);
friend void average(Electrical e1, Electrical e2, Mechatronics m1, Mechatronics m2);
~Electrical();
};
class Mechatronics {
private:
string name;
double marks;
public:
Mechatronics();
Mechatronics(string name);
Mechatronics(double marks);
Mechatronics(string name, double marks);
void set();
void average(Mechatronics m2);
void average(Electrical e1, Electrical e2, Mechatronics m2);
friend void average(Electrical e1, Electrical e2, Mechatronics m1, Mechatronics m2);
~Mechatronics();
};
int main(){
Electrical e1, e2;
Mechatronics m1, m2;
cout<<"Electrical Department"<<endl;
cout<<"\nStudent 1: "<<endl;
e1.set();
cout<<"\nStudent 2: "<<endl;
e2.set();
cout<<endl;
e1.average(e2);
cout<<"\n___________________________________________"<<endl;
cout<<"\nMechatronics Department"<<endl;
cout<<"\nStudent 1: "<<endl;
m1.set();
cout<<"\nStudent 2: "<<endl;
m2.set();
cout<<endl;
m1.average(m2);
cout<<"\n___________________________________________"<<endl;
cout<<endl;
m1.average(e1, e2, m2);
cout<<endl;
average(e1, e2, m1, m2);
cout<<endl;
return 0;
}
Electrical :: Electrical(){
name = " ";
marks = 0;
}
Electrical :: Electrical(string name){
}
Electrical :: Electrical(double marks){
}
void Electrical :: set(){
cout<<"\nEnter your name: ";
cin>>name;
cout<<"Enter your marks: ";
cin>>marks;
}
void Electrical :: average(Electrical e2){
double average;
average = (marks + e2.marks)/2;
cout<<"Average for Electrical Department: "<<average;
}
Mechatronics :: Mechatronics(){
name = " ";
marks = 0;
}
Mechatronics :: Mechatronics(string name){
}
Mechatronics :: Mechatronics(double marks){
}
void Mechatronics :: set(){
cout<<"\nEnter your name: ";
cin>>name;
cout<<"Enter your marks: ";
cin>>marks;
}
void Mechatronics :: average(Mechatronics m2){
double average;
average = (marks + m2.marks)/2;
cout<<"Average marks for Electrical Department: "<<average;
}
void Mechatronics :: average(Electrical e1, Electrical e2, Mechatronics m2){
double average;
average = (e1.marks + e2.marks + marks + m2.marks)/4;
cout<<"Average marks for University (using class Mechatronics): "<<average;
}
void average(Electrical e1, Electrical e2, Mechatronics m1, Mechatronics m2){
double average;
average = (e1.marks + e2.marks +m1.marks + m2.marks)/4;
cout<<"Average marks for University (using friend function): "<<average;
}
Electrical :: ~Electrical(){
}
Mechatronics :: ~Mechatronics(){
}