示例#1
0
        static void Main(string[] args)
        {
            // 5.Run the same code in Program.cs from Module 5 to create instances of your classes so that you can setup a single course that is part of a program and a degree path. Be sure to include at least one Teacher and an array of Students.
            student student1 = new student();
            student1.Firstname = "Tony";
            student1.Lastname = "Stark";
            student1.Dateofbirth = "1st Jan 1969";
            student1.Grades.Push(90);
            student1.Grades.Push(100);
            student1.Grades.Push(90);
            student1.Grades.Push(75);
            student1.Grades.Push(60);

            student student2 = new student();
            student2.Firstname = "Steve";
            student2.Lastname = "Rodgers";
            student2.Dateofbirth = "1st Feb 1920";
            student2.Grades.Push(90);
            student2.Grades.Push(100);
            student2.Grades.Push(90);
            student2.Grades.Push(75);
            student2.Grades.Push(60);

            student student3 = new student();
            student3.Firstname = "Bruce";
            student3.Lastname = "Banner";
            student3.Dateofbirth = "1st April 1975";
            student3.Grades.Push(90);
            student3.Grades.Push(100);
            student3.Grades.Push(90);
            student3.Grades.Push(75);
            student3.Grades.Push(60);

            //2.Instantiate a Course object called Programming with C#.
            course ProgrammingCourses = new course();
            ProgrammingCourses.CourseTitle = "Programming with C#";
            ProgrammingCourses.CourseLength = 3;
            ProgrammingCourses.CourseCredits = 90;

            //3.Add your three students to this Course object
            ProgrammingCourses.students.Add(student1);
            ProgrammingCourses.students.Add(student2);
            ProgrammingCourses.students.Add(student3);

            //4.Instantiate at least one Teacher object.
            teacher teacher1 = new teacher();
            teacher1.Firstname = "Stan";
            teacher1.Lastname = "Winston";
            teacher1.Dateofbirth = "1st Dec 1919";

            //5.Add that Teacher object to your Course object
            ProgrammingCourses.teachers[0] = teacher1;

            //6.Instantiate a Degree object, such as Bachelor.
            degree degree1 = new degree();
            degree1.DegreeName = "Bachelor";

            //7.Add your Course object to the Degree object.
            degree1.degreecourse = ProgrammingCourses;

            //8.Instantiate a UProgram object called Information Technology.
            uprogram uprogram1 = new uprogram();
            uprogram1.Programtitle = "Information Technology";

            //9.Add the Degree object to the UProgram object.
            uprogram1.Programdegree = degree1;

            //10.Using Console.WriteLine statements, output
            //Console.WriteLine("The {0} program contains the {1} degree", uprogram1.Programtitle, degree1.DegreeName);
            //Console.WriteLine("The {0} degree contains the course {1}", degree1.DegreeName, ProgrammingCourses.CourseTitle);
            //Console.WriteLine("The {0} course contains {1} students(s)", ProgrammingCourses.CourseTitle, ProgrammingCourses.CourseTitle);

            ProgrammingCourses.ListStudents();
        }
示例#2
0
        static void Main(string[] args)
        {
            #region Module 5 Code
            //Instantiate a Course object called Programming with C#
            course programmingWithCSharp = new course();
            programmingWithCSharp.CourseName = "Programming in C#";

            //Instantiate three student objects and add them to the course object
            programmingWithCSharp.Students = new student[3];
            for (int i = 0; i < 3; i++)
            {
                programmingWithCSharp.Students[i] = new student();
                student.StudentCount++;
            }

            student student1 = new student();
            try
            {
                student1.TakeTest();
            }
            catch (NotImplementedException notImplemented)
            {
                Console.WriteLine(notImplemented.Message);
            }

            //Instantiate at least one Teacher object
            teacher teacher1 = new teacher();

            //Add that Teacher object to your Course object - only 1 instructor for this module
            programmingWithCSharp.Instructor = new teacher[1] { teacher1 };

            //Instantiate a Degree object
            degree bachelorDegree = new degree();

            //Add your Course object to the Degree object
            bachelorDegree.Course = programmingWithCSharp;

            //Instantiate a UProgram object called Information Technology
            uprogram informationTechnology = new uprogram();

            //Add the Degree object to the UProgram object
            informationTechnology.Degrees = bachelorDegree;
            //These are added for readability and testing in output
            informationTechnology.ProgramName = "Information Technology";
            informationTechnology.Degrees.DegreeName = "ISAT";

            //Console Output
            Console.WriteLine("The name of the Program is {0} and the Degree is {1}.", informationTechnology.ProgramName, informationTechnology.Degrees.DegreeName);
            Console.WriteLine("The name of the Course is {0}.", informationTechnology.Degrees.Course.CourseName);
            Console.WriteLine("The number of students enrolled is {0}", student.StudentCount);

            #endregion

            #region Challenge Code
            //Create an instance of a Person object in code
            person person1 = new person();
            //Create an instance of a Student object in code
            student student2 = new student();
            //Assign the Student object to the Person object
            person1 = student2;
            //Access the properties of the Person instance you created
            person1.FirstName = "Thomas";

            //This doesn't work because person1 is an instance of the person class
            //When we assign an inherited class back to a parent object, we lose the
            //functionality of the inherited class.

            //person1.TakeTest();

            Console.WriteLine(person1.FirstName);
            #endregion
        }