コード例 #1
0
        static void Main(string[] args)
        {
            string dept;
            int    RegNum;
            string name;

            Console.Write("Please enter your name: ");
            name = Console.ReadLine();

            Console.Write("Please enter your registration number: ");
            RegNum = Convert.ToInt32(Console.ReadLine());

            Console.Write("Please enter your department: ");
            dept = Console.ReadLine();

            if (dept == "SCI")
            {
                Student scienceStudent = new Student(name, RegNum);
                Console.WriteLine(scienceStudent);
            }
            else if (dept == "COMM")
            {
                CommercialStudent commercialStudent = new CommercialStudent(name, RegNum);
                Console.WriteLine(commercialStudent.ToString());
            }
            else
            {
                Console.WriteLine("Invalid entry!!! Please try again.");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Student Details: ");
            Console.WriteLine("Enter Student Name");
            string StudentName = Console.ReadLine();

            Console.WriteLine("Enter Student Registration Number: ");
            string StudentRegNumber = Console.ReadLine();

            Console.WriteLine("Enter Department-- SCI or COM: ");
            string StudentDepartment = Console.ReadLine();

            ScienceStudent sciencestudent = new ScienceStudent(StudentName, StudentRegNumber, 50, 65, 70);

            CommercialStudent commercialstudent = new CommercialStudent(StudentName, StudentRegNumber, 56, 70, 80);

            if (StudentDepartment == "SCI")
            {
                Console.WriteLine(sciencestudent.ToString());
            }
            else if (StudentDepartment == "COM")
            {
                Console.WriteLine(commercialstudent.ToString());
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }