-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic_member.cpp
More file actions
50 lines (37 loc) · 999 Bytes
/
Static_member.cpp
File metadata and controls
50 lines (37 loc) · 999 Bytes
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
#include <iostream>
#include <cstring>
class Student {
private:
int roll_no;
char name[20];
int marks[3];
static int student_count;
int total() const {
return marks[0] + marks[1] + marks[2];
}
public:
Student(int r, const char* n, int m1, int m2, int m3) {
roll_no = r;
strncpy(name, n, 20);
marks[0] = m1;
marks[1] = m2;
marks[2] = m3;
student_count++;
}
static int get_student_count() {
return student_count;
}
void display_data() const;
};
int Student::student_count = 0;
inline void Student::display_data() const {
std::cout << "Roll No: " << roll_no << ", Name: " << name << ", Total Marks: " << total() << std::endl;
}
int main() {
Student s1(1, "John", 85, 90, 88);
Student s2(2, "Jane", 78, 82, 80);
s1.display_data();
s2.display_data();
std::cout << "Total number of students: " << Student::get_student_count() << std::endl;
return 0;
}