Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Modul5_final
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Instances of student classes
- Student student1 = new Student("Danihel", "Dee", "2.6.6521", "Cosmic Lanes", "Jupiter Liar", "New Old New York", "Federal Dominium Province no. 7", "800500", "United Human States");
- Student student2 = new Student("Danihel", "John", "16.3.1862", "Street long street", "Venezuela", "Caracas", "South Planes", "156", "Long country");
- Student student3 = new Student("Dan", "Dohn", "11.5.1958", "Javorova street", "Austria", "Wien", "Prater", "362", "Autro-Hungaria");
- // Course instance, and using AddStudent method to add students to the array in course
- Course course1 = new Course("Programming with C#");
- course1.AddStudent(student1);
- course1.AddStudent(student2);
- course1.AddStudent(student3);
- // Teacher instance, and using AddTeacher method to add a teacher to the array in course
- Teacher teacher1 = new Teacher("Joh", "Malkovitch", "TNT");
- course1.AddTeacher(teacher1);
- // Degree instance and adding the course
- Degree degree1 = new Degree("Bachelor of Science");
- degree1.AddCourse(course1);
- // UProgram instance and adding the degree
- UProgram program1 = new UProgram("Information Technology");
- program1.AddDegree(degree1);
- // Writing the information out to the console
- Console.WriteLine("The {0} program contains the {1} degree", program1.Name, degree1.Name);
- Console.WriteLine();
- Console.WriteLine("The {0} degree contains the course {1}", degree1.Name, course1.Name);
- Console.WriteLine();
- Console.WriteLine("The {0} course contains {1} student(s)", course1.Name, Student.Counter.ToString());
- Console.WriteLine("Press any key...");
- Console.ReadKey();
- }
- }
- class Student
- {
- static int counter = 0;
- #region overload constructor
- // Overload constructor
- public Student(string firstName, string lastName, string birthDate, string addressLine1, string addressLine2, string city, string stateProvince, string zipPostal, string country)
- {
- FirstName = firstName;
- LastName = lastName;
- BirthDate = birthDate;
- AddressLine1 = addressLine1;
- AddressLine2 = addressLine2;
- City = city;
- StateProvince = stateProvince;
- ZipPostal = zipPostal;
- Country = country;
- counter++;
- }
- #endregion
- #region accessor function
- // Accessors functions
- public string FirstName
- {
- get { return _firstName; }
- set { _firstName = value; }
- }
- public string LastName
- {
- get { return _lastName; }
- set { _lastName = value; }
- }
- public string BirthDate
- {
- get { return _birthDate; }
- set { _birthDate = value; }
- }
- public string AddressLine1
- {
- get { return _addressLine1; }
- set { _addressLine1 = value; }
- }
- public string AddressLine2
- {
- get { return _addressLine2; }
- set { _addressLine2 = value; }
- }
- public string City
- {
- get { return _city; }
- set { _city = value; }
- }
- public string StateProvince
- {
- get { return _stateProvince; }
- set { _stateProvince = value; }
- }
- public string ZipPostal
- {
- get { return _zipPostal; }
- set { _zipPostal = value; }
- }
- public string Country
- {
- get { return _country; }
- set { _country = value; }
- }
- public static int Counter
- {
- get { return counter; }
- set { counter = value; }
- }
- #endregion
- #region member variables
- // Member variables
- private string _firstName;
- private string _lastName;
- private string _birthDate;
- private string _addressLine1;
- private string _addressLine2;
- private string _city;
- private string _stateProvince;
- private string _zipPostal;
- private string _country;
- #endregion
- }
- class Teacher
- {
- #region overload constructor
- // Overload constructor
- public Teacher(string firstName, string lastName, string degree)
- {
- FirstName = firstName;
- LastName = lastName;
- Degree = degree;
- }
- #endregion
- #region accessor functions
- // Accessor functions
- public string FirstName
- {
- get { return _firstName; }
- set { _firstName = value; }
- }
- public string LastName
- {
- get { return _lastName; }
- set { _lastName = value; }
- }
- public string Degree
- {
- get { return _degree; }
- set { _degree = value; }
- }
- #endregion
- #region member variables
- // Member variables
- private string _firstName;
- private string _lastName;
- private string _degree;
- #endregion
- }
- class UProgram
- {
- #region overload constructor
- // Overload constructor
- public UProgram(string name)
- {
- Name = name;
- }
- #endregion
- #region method
- //adding degree
- public void AddDegree(Degree degree)
- {
- Degree = degree;
- }
- #endregion
- #region accessor functions
- // Accessor functions
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- public Degree Degree
- {
- get { return _degree; }
- set { _degree = value; }
- }
- #endregion
- #region member variables
- // Member variables
- private string _name;
- private Degree _degree;
- #endregion
- }
- class Degree
- {
- #region overload constructor
- // Overload constructor
- public Degree(string name)
- {
- Name = name;
- }
- #endregion
- #region method
- //adding degree
- public void AddCourse(Course course)
- {
- Course = course;
- }
- #endregion
- #region accessor functions
- // Accessor functions
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- public Course Course
- {
- get { return _course; }
- set { _course = value; }
- }
- #endregion
- #region member variables
- // member variables
- private string _name;
- private Course _course;
- #endregion
- }
- class Course
- {
- #region overload constructor
- // Overload constructor
- public Course(string name)
- {
- Name = name;
- students = new Student[3];
- teachers = new Teacher[3];
- }
- #endregion
- #region Methods
- // FirstFreeIndexStudent
- public int FirstFreeIndexStudent(Student[] array)
- {
- int index = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] is Student)
- {
- index++;
- }
- }
- return index;
- }
- // FirstFreeIndexTeacher
- public int FirstFreeIndexTeacher(Teacher[] array)
- {
- int index = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] is Teacher)
- {
- index++;
- }
- }
- return index;
- }
- // AddStudent Method
- public void AddStudent(Student student)
- {
- int index = FirstFreeIndexStudent(students);
- students[index] = student;
- }
- // AddTeacher Method
- public void AddTeacher(Teacher teacher)
- {
- int index = FirstFreeIndexTeacher(teachers);
- teachers[index] = teacher;
- }
- #endregion
- #region accessor functions
- // Accessor functions
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- public Student[] Students
- {
- get { return students; }
- set { students = value; }
- }
- public Teacher[] Teacher
- {
- get { return teachers; }
- set { teachers = value; }
- }
- #endregion
- #region member variables
- // member variables
- private string _name;
- private Student[] students;
- private Teacher[] teachers;
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement