Advertisement
Istiach

DEV204x Programming with C# module 5

Apr 28th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Modul5_final
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Instances of student classes
  14.             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");
  15.             Student student2 = new Student("Danihel", "John", "16.3.1862", "Street long street", "Venezuela", "Caracas", "South Planes", "156", "Long country");
  16.             Student student3 = new Student("Dan", "Dohn", "11.5.1958", "Javorova street", "Austria", "Wien", "Prater", "362", "Autro-Hungaria");
  17.  
  18.             // Course instance, and using AddStudent method to add students to the array in course
  19.             Course course1 = new Course("Programming with C#");
  20.             course1.AddStudent(student1);
  21.             course1.AddStudent(student2);
  22.             course1.AddStudent(student3);
  23.  
  24.             // Teacher instance, and using AddTeacher method to add a teacher to the array in course
  25.             Teacher teacher1 = new Teacher("Joh", "Malkovitch", "TNT");
  26.             course1.AddTeacher(teacher1);
  27.  
  28.             // Degree instance and adding the course
  29.             Degree degree1 = new Degree("Bachelor of Science");
  30.             degree1.AddCourse(course1);
  31.  
  32.             // UProgram instance and adding the degree
  33.             UProgram program1 = new UProgram("Information Technology");
  34.             program1.AddDegree(degree1);
  35.  
  36.             // Writing the information out to the console
  37.             Console.WriteLine("The {0} program contains the {1} degree", program1.Name, degree1.Name);
  38.             Console.WriteLine();
  39.             Console.WriteLine("The {0} degree contains the course {1}", degree1.Name, course1.Name);
  40.             Console.WriteLine();
  41.             Console.WriteLine("The {0} course contains {1} student(s)", course1.Name, Student.Counter.ToString());
  42.             Console.WriteLine("Press any key...");
  43.             Console.ReadKey();
  44.         }
  45.     }
  46.  
  47.     class Student
  48.     {
  49.         static int counter = 0;
  50.  
  51.         #region overload constructor
  52.         // Overload constructor
  53.         public Student(string firstName, string lastName, string birthDate, string addressLine1, string addressLine2, string city, string stateProvince, string zipPostal, string country)
  54.         {
  55.             FirstName = firstName;
  56.             LastName = lastName;
  57.             BirthDate = birthDate;
  58.             AddressLine1 = addressLine1;
  59.             AddressLine2 = addressLine2;
  60.             City = city;
  61.             StateProvince = stateProvince;
  62.             ZipPostal = zipPostal;
  63.             Country = country;
  64.             counter++;
  65.         }
  66.         #endregion
  67.  
  68.         #region accessor function
  69.         // Accessors functions
  70.         public string FirstName
  71.         {
  72.             get { return _firstName; }
  73.             set { _firstName = value; }
  74.         }
  75.  
  76.         public string LastName
  77.         {
  78.             get { return _lastName; }
  79.             set { _lastName = value; }
  80.         }
  81.  
  82.         public string BirthDate
  83.         {
  84.             get { return _birthDate; }
  85.             set { _birthDate = value; }
  86.         }
  87.  
  88.         public string AddressLine1
  89.         {
  90.             get { return _addressLine1; }
  91.             set { _addressLine1 = value; }
  92.         }
  93.  
  94.         public string AddressLine2
  95.         {
  96.             get { return _addressLine2; }
  97.             set { _addressLine2 = value; }
  98.         }
  99.  
  100.         public string City
  101.         {
  102.             get { return _city; }
  103.             set { _city = value; }
  104.         }
  105.  
  106.         public string StateProvince
  107.         {
  108.             get { return _stateProvince; }
  109.             set { _stateProvince = value; }
  110.         }
  111.  
  112.         public string ZipPostal
  113.         {
  114.             get { return _zipPostal; }
  115.             set { _zipPostal = value; }
  116.         }
  117.  
  118.         public string Country
  119.         {
  120.             get { return _country; }
  121.             set { _country = value; }
  122.         }
  123.  
  124.         public static int Counter
  125.         {
  126.             get { return counter; }
  127.             set { counter = value; }
  128.         }
  129.         #endregion
  130.  
  131.         #region member variables
  132.         // Member variables
  133.         private string _firstName;
  134.         private string _lastName;
  135.         private string _birthDate;
  136.         private string _addressLine1;
  137.         private string _addressLine2;
  138.         private string _city;
  139.         private string _stateProvince;
  140.         private string _zipPostal;
  141.         private string _country;
  142.         #endregion
  143.     }
  144.  
  145.     class Teacher
  146.     {
  147.         #region overload constructor
  148.         // Overload constructor
  149.         public Teacher(string firstName, string lastName, string degree)
  150.         {
  151.             FirstName = firstName;
  152.             LastName = lastName;
  153.             Degree = degree;
  154.         }
  155.         #endregion
  156.  
  157.         #region accessor functions
  158.         // Accessor functions
  159.         public string FirstName
  160.         {
  161.             get { return _firstName; }
  162.             set { _firstName = value; }
  163.         }
  164.  
  165.         public string LastName
  166.         {
  167.             get { return _lastName; }
  168.             set { _lastName = value; }
  169.         }
  170.  
  171.         public string Degree
  172.         {
  173.             get { return _degree; }
  174.             set { _degree = value; }
  175.         }
  176.         #endregion
  177.  
  178.         #region member variables
  179.         // Member variables
  180.         private string _firstName;
  181.         private string _lastName;
  182.         private string _degree;
  183.         #endregion
  184.     }
  185.  
  186.     class UProgram
  187.     {
  188.         #region overload constructor
  189.         // Overload constructor
  190.         public UProgram(string name)
  191.         {
  192.             Name = name;
  193.         }
  194.         #endregion
  195.  
  196.         #region method
  197.         //adding degree
  198.         public void AddDegree(Degree degree)
  199.         {
  200.             Degree = degree;
  201.         }
  202.         #endregion
  203.  
  204.         #region accessor functions
  205.         // Accessor functions
  206.         public string Name
  207.         {
  208.             get { return _name; }
  209.             set { _name = value; }
  210.         }
  211.  
  212.         public Degree Degree
  213.         {
  214.             get { return _degree; }
  215.             set { _degree = value; }
  216.         }
  217.         #endregion
  218.  
  219.         #region member variables
  220.         // Member variables
  221.         private string _name;
  222.         private Degree _degree;
  223.         #endregion
  224.     }
  225.  
  226.     class Degree
  227.     {
  228.         #region overload constructor
  229.         // Overload constructor
  230.         public Degree(string name)
  231.         {
  232.             Name = name;
  233.         }
  234.         #endregion
  235.  
  236.         #region method
  237.         //adding degree
  238.         public void AddCourse(Course course)
  239.         {
  240.             Course = course;
  241.         }
  242.         #endregion
  243.  
  244.         #region accessor functions
  245.         // Accessor functions
  246.         public string Name
  247.         {
  248.             get { return _name; }
  249.             set { _name = value; }
  250.         }
  251.  
  252.         public Course Course
  253.         {
  254.             get { return _course; }
  255.             set { _course = value; }
  256.         }
  257.         #endregion
  258.  
  259.         #region member variables
  260.         // member variables
  261.         private string _name;
  262.         private Course _course;
  263.         #endregion
  264.     }
  265.  
  266.     class Course
  267.     {
  268.         #region overload constructor
  269.         // Overload constructor
  270.         public Course(string name)
  271.         {
  272.             Name = name;
  273.             students = new Student[3];
  274.             teachers = new Teacher[3];
  275.         }
  276.         #endregion
  277.  
  278.         #region Methods
  279.         // FirstFreeIndexStudent
  280.         public int FirstFreeIndexStudent(Student[] array)
  281.         {
  282.             int index = 0;
  283.             for (int i = 0; i < array.Length; i++)
  284.             {
  285.                 if (array[i] is Student)
  286.                 {
  287.                     index++;
  288.                 }
  289.             }
  290.             return index;
  291.         }
  292.  
  293.         // FirstFreeIndexTeacher
  294.         public int FirstFreeIndexTeacher(Teacher[] array)
  295.         {
  296.             int index = 0;
  297.             for (int i = 0; i < array.Length; i++)
  298.             {
  299.                 if (array[i] is Teacher)
  300.                 {
  301.                     index++;
  302.                 }
  303.             }
  304.             return index;
  305.         }
  306.  
  307.         // AddStudent Method
  308.         public void AddStudent(Student student)
  309.         {
  310.             int index = FirstFreeIndexStudent(students);
  311.             students[index] = student;
  312.         }
  313.  
  314.         // AddTeacher Method
  315.         public void AddTeacher(Teacher teacher)
  316.         {
  317.             int index = FirstFreeIndexTeacher(teachers);
  318.             teachers[index] = teacher;
  319.         }
  320.         #endregion
  321.  
  322.         #region accessor functions
  323.         // Accessor functions
  324.         public string Name
  325.         {
  326.             get { return _name; }
  327.             set { _name = value; }
  328.         }
  329.  
  330.         public Student[] Students
  331.         {
  332.             get { return students; }
  333.             set { students = value; }
  334.         }
  335.  
  336.         public Teacher[] Teacher
  337.         {
  338.             get { return teachers; }
  339.             set { teachers = value; }
  340.         }
  341.         #endregion
  342.  
  343.         #region member variables
  344.         // member variables
  345.         private string _name;
  346.         private Student[] students;
  347.         private Teacher[] teachers;
  348.         #endregion
  349.     }
  350. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement