C#.NET Program 21

Output:




















Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Question_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       
        Question_2.Student S = new Question_2.Student();
        Question_2.Faculty F = new Question_2.Faculty();

        
        private void button1_Click(object sender, EventArgs e)
        {
            string s1, s2;
            int n1;

            s1 = textBox1.Text;
            s2 = textBox2.Text;
            n1 = int.Parse(textBox3.Text);

            S.show_details(s1,s2,n1);
            MessageBox.Show("First Name: " + s1 + "\n" + "Last Name : " + s2 + "\n" + "Age :" + n1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string s1, s2;
            int n1;

            s1 = textBox4.Text;
            s2 = textBox5.Text;
            n1 = int.Parse(textBox6.Text);

            F.show_details(s1, s2, n1);
            MessageBox.Show("First Name: " + s1 + "\n" + "Last Name : " + s2 + "\n" + "Age :" + n1);
        }
    }
}

Person Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Question_2
{
    public abstract class Person
    {
        public string First_Name;
        public string Last_Name;
        public int Age;
        public abstract void show_details(string x, string y, int z);
    }
    public class Student : Person
    {
        public override void show_details(string x, string y, int z)
        {
            First_Name = x;
            Last_Name = y;
            Age = z;
        }
    }
    public class Faculty : Person
    {
        public override void show_details(string x, string y, int z)
        {
            First_Name = x;
            Last_Name = y;
            Age = z;
        }
    }
}

No comments:

Post a Comment