Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.string;
- class School {
- Classroom[] classes;
- void addClass(ref Classroom classroom) {
- //classroom.school = this;
- this.classes ~= classroom;
- }
- void invite(string className, ref Teacher teacher) {
- Classroom classroom = getClassByName(className);
- if (classroom !is null)
- classroom.teachers ~= teacher;
- }
- void invite(string className, ref Student student) {
- Classroom classroom = getClassByName(className);
- if (classroom !is null)
- classroom.students ~= student;
- }
- void invite(string className, Teacher[] teachers) {
- foreach(ref teacher; teachers) {
- invite(className, teacher);
- }
- }
- void invite(string className, Student[] students) {
- foreach(ref student; students) {
- invite(className, student);
- }
- }
- Classroom getClassByName(string className) {
- if (isDefined(className)) {
- foreach(classroom; this.classes) {
- if (classroom.name == className)
- return classroom;
- }
- }
- return null;
- }
- Classroom newClassroom(string name, ref Teacher teacher) {
- auto classroom = new Classroom(name, teacher);
- addClass(classroom);
- return classroom;
- }
- bool isDefined(string className) {
- foreach(classroom; this.classes) {
- if (classroom.name == className)
- return true;
- }
- return false;
- }
- void printClasses() {
- foreach(classroom; this.classes) {
- writeln(classroom);
- }
- }
- }
- class Teacher: User {
- string lesson;
- this(string firstName, string lastName, short age, string lesson) {
- super(firstName, lastName, age);
- this.role = "Teacher";
- this.lesson = lesson;
- }
- }
- class Student: User {
- this(string firstName, string lastName, short age) {
- super(firstName, lastName, age);
- this.role = "Student";
- }
- }
- class Classroom {
- private School _school;
- string name;
- Teacher formMaster;
- Teacher[] teachers;
- Student[] students;
- this(string name, ref Teacher teacher) {
- this.name = name;
- this.formMaster = teacher;
- }
- @property void school(ref School school) {
- this._school = school;
- }
- override string toString() const {
- string text = format("Class %s. Teacher %s. %d students: \n", this.name, this.formMaster.name, this.students.length);
- foreach(student; this.students) {
- text ~= "\t" ~ student.toString() ~ "\n";
- }
- return text;
- }
- }
- class User {
- Classroom classroom;
- string firstName;
- string lastName;
- string role;
- short age;
- this(string firstName, string lastName, short age) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- }
- @property string name() const {
- return format("%s %s", this.firstName, this.lastName);
- }
- override string toString() const {
- return format("%s %s. Age %d.", this.role, this.name, this.age);
- }
- }
- void main() {
- auto students = [
- new Student("Henry", "El", 16),
- new Student("Nicol", "Mi", 16),
- new Student("Leo", "Ef", 11)
- ];
- auto teacher = new Teacher("Marry", "Elezabet", 43, "Russian Language");
- auto school = new School();
- school.newClassroom("10A", teacher);
- school.newClassroom("6B", teacher);
- school.invite("10A", students[0..2]);
- school.invite("6B", students[2]);
- school.printClasses();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement