-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP.ts
142 lines (104 loc) · 3.08 KB
/
OOP.ts
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
// The idea was provided by sir hamzah syed .
// from the video link, provided on discord.
// university Student management system:
// using Object Oriented Programming (OOP);
// parent of students & instructors
class person {
name: string;
age: number;
constructor(name: string, age: number) {
this.age = age;
this.name = name;
}
}
// inherit of person
class student extends person {
static staticRollNumber: number = 0;
rollnumber: number;
courses: course[] = [];
// public method
RegisterForCourse(course: course) {
this.courses.push(course);
}
constructor(name: string, age: number) {
super(name, age);
this.rollnumber = ++student.staticRollNumber;
}
// method of registration for courses
registerForCourses(course: course, crs4: course) {
this.courses.push(course);
}
}
// inherit of person
class instructor extends person {
// salary :number= 38000;
salary: number;
course: course[] = [];
constructor(name: string, age: number, salary: number) {
super(name, age);
this.salary = salary;
}
// method of assigning course
assignCourse(courses: course) {
this.course.push(courses);
}
}
// Its a better practice to use methods outside console.
// courses
class course {
id: number;
name: string;
students: student[] = [];
instructors: instructor[] = [];
constructor(id: number, name: string) {
this.id = id;
this.name = name;
}
// add student
addStudent(std: student) {
this.students.push(std);
}
// Add instructor
addInstructor(Inst: instructor) {
this.instructors.push(Inst);
}
}
class Department {
name:string;
courses :course[]= [];
constructor(name:string) {
this.name = name;
}
AddCourse(course:course){
this.courses.push(course);
}
}
// courses
const crs1 = new course(1, "Web 3.0 ");
const crs2 = new course(2, "Metaverse");
const crs3 = new course(3, "blockChain");
const crs4 = new course(4, "Gen AI eng");
// students
const std1 = new student("Hedda", 20);
const std2 = new student("Terry", 24);
const std3 = new student("Pascal", 32);
const std4 = new student("Kakearika", 20);
const std5 = new student("doe", 28);
std1.RegisterForCourse(crs1); //hedda is now regitered for web 3.0
// instructors
const inst1 = new instructor("darren", 38, 56000);
const inst2 = new instructor("jenny", 31, 49000);
const inst3 = new instructor("Spike", 40, 60000);
crs1.addInstructor(inst1); // darren is now the instructor of the course 1 (web3.0)
std5.rollnumber, std5.registerForCourses(crs2, crs4);
// Department
const dept1 = new Department("Computer Science" );
const dept2 = new Department("Information Technology");
const dept3 = new Department("Internal relations");
dept1.AddCourse(crs1);
dept1.AddCourse(crs2);
dept1.AddCourse(crs3);
crs1.addStudent(std5);
crs1.addInstructor(inst2);
console.log(dept1.courses);
// Sir gave us a task at the end of the session (organize code ), Already done * shrugs *