Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Design student class, marks class, inherits it in result class and access it using form using C#

Here we have designed a student form in which the user have to enter the Name, ID, Marks1, Marks2 and then after clicking on Click for result the total marks and the percentage will be displayed.


Code - 

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

namespace Exp4
{
    public partial class Form1 : Form
    {
        public static int add;
        public static double percentage;
        public static int total;
        public static int s1;
        public static int s2;
        public static int id;
        public static double perce;
        
        
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        interface Student
        {
            void GetData(int id, string Name);
        }
        interface Marks
        {
            int GetMarks(int m1, int m2);
        }

        class Result: Student,Marks
        {
            public void GetData(int a, string b)
            {
                Console.WriteLine("Student ID: " + a);
                Console.WriteLine("Student Name: " + b);
            }
            public int GetMarks(int m1, int m2)
            {
                add = s1 + s2;
                return add;
            }
            public double GetPercentage()
            {
                percentage = (add * 100) / 2;
                return percentage;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Name = textBox1.Text;
            try
            {
                id = int.Parse(textBox2.Text);
                s1 = int.Parse(textBox3.Text);
                s2 = int.Parse(textBox4.Text);
            }
            catch(FormatException)
            {
                Console.WriteLine("Invalid");
            }
            Result result = new Result();
            result.GetData(id, Name);
            result.GetMarks(s1, s2);
            total = result.GetMarks(s1, s2);
            textBox5.Text = total.ToString();
            perce = result.GetPercentage();
            textBox6.Text = perce.ToString();

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}


Output -

Post a Comment

0 Comments

Ad Code

Responsive Advertisement