Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace ModuleSevenAssignment
  7. {
  8.     class Program
  9.     {
  10.         //how many students to add according to specs
  11.         const int initialNumStudents = 3;
  12.        
  13.         //how many grades according to the specs
  14.         const int gradesPerStudent = 5;
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             //create course
  19.             Course course = new Course("Programming with C#");
  20.  
  21.             //add students to course
  22.             for (int i = 0; i < initialNumStudents; i++)
  23.             {
  24.                 Student student = new Student("Student", "Name");
  25.  
  26.                 //add grades for student
  27.                 for (int j = 0; j < gradesPerStudent; j++)
  28.                 {
  29.                     student.Grades.Push(100);
  30.                 }
  31.  
  32.                 course.AddStudent(student);
  33.             }
  34.  
  35.             course.ListStudents();
  36.            
  37.             Console.ReadKey();
  38.         }
  39.  
  40.         //Contains first name and last name.
  41.         class Person
  42.         {
  43.             public string FName { get; set; }
  44.             public string LName { get; set; }
  45.  
  46.             public Person(string firstName, string lastName)
  47.             {
  48.                 FName = firstName;
  49.                 LName = lastName;
  50.             }
  51.         }
  52.  
  53.         class Student : Person
  54.         {
  55.             public static int StudentsEnrolledInSchool = 0;
  56.  
  57.             public Stack<int> Grades { get; set; }
  58.  
  59.             //Use the Person class's constructor to instantiate
  60.             public Student(string firstName, string lastName)
  61.                 : base(firstName, lastName)
  62.             {
  63.                 Grades = new Stack<int>();
  64.                 StudentsEnrolledInSchool++;
  65.             }
  66.  
  67.             public void TakeTest()
  68.             {
  69.                 Console.WriteLine("{0} {1} took a test!", FName, LName);
  70.             }
  71.         }
  72.         class Teacher : Person
  73.         {
  74.             //Use the Person class's constructor to instantiate
  75.             public Teacher(string firstName, string lastName) : base(firstName, lastName) { }
  76.  
  77.             public void GradeTest()
  78.             {
  79.                 Console.WriteLine("{0} {1} graded a test!", FName, LName);
  80.             }
  81.         }
  82.  
  83.         //Contains teacher, students, and title
  84.         class Course
  85.         {
  86.             public Teacher Teacher { get; set; }
  87.             public ArrayList Students { get; set; }
  88.             public string Title { get; set; }
  89.  
  90.             public Course(string title)
  91.             {
  92.                 Title = title;
  93.                 Students = new ArrayList();
  94.             }
  95.  
  96.             public void AddStudent(Student s)
  97.             {
  98.                 Students.Add(s);
  99.             }
  100.  
  101.             public void ListStudents()
  102.             {
  103.                 foreach (Student s in Students)
  104.                 {
  105.                     Console.WriteLine("{0} {1}", s.FName, s.LName);
  106.                 }
  107.             }
  108.         }
  109.  
  110.         //Contains courses and title
  111.         class Degree
  112.         {
  113.             public string Title { get; set; }
  114.             public List<Course> Courses { get; set; }
  115.  
  116.             public Degree(string title)
  117.             {
  118.                 Title = title;
  119.                 Courses = new List<Course>();
  120.             }
  121.  
  122.             public void AddCourse(Course course)
  123.             {
  124.                 Courses.Add(course);
  125.             }
  126.         }
  127.  
  128.         //Contains degrees and title
  129.         class UProgram
  130.         {
  131.             public string Title { get; set; }
  132.             public List<Degree> Degrees { get; set; }
  133.  
  134.             public UProgram(string title)
  135.             {
  136.                 Title = title;
  137.                 Degrees = new List<Degree>();
  138.             }
  139.  
  140.             public void AddDegree(Degree degree)
  141.             {
  142.                 Degrees.Add(degree);
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement