studentsPerformance.csv

1. Arithmetic Operators

using System;


class Program

{

    static void Main()

    {

        int a = 10, b = 3;


        Console.WriteLine("Addition = " + (a + b));

        Console.WriteLine("Subtraction = " + (a - b));

        Console.WriteLine("Multiplication = " + (a * b));

        Console.WriteLine("Division = " + (a / (float)b));

        Console.WriteLine("Remainder = " + (a % b));

    }

}

 2. Sum of Digits

using System;


class Program

{

    static void Main()

    {

        int num = 738, sum = 0;


        while (num > 0)

        {

            sum += num % 10;

            num /= 10;

        }


        Console.WriteLine("Sum = " + sum);

    }

}

3. Number Pattern

using System;


class Program

{

    static void Main()

    {

        for (int i = 1; i <= 5; i++)

        {

            for (int j = 1; j <= i; j++)

                Console.Write(j);


            Console.WriteLine();

        }

    }

}

 4. Armstrong Number

using System;


class Program

{

    static void Main()

    {

        int num = 153, temp = num, sum = 0;


        while (num > 0)

        {

            int r = num % 10;

            sum += r * r * r;

            num /= 10;

        }


        if (sum == temp)

            Console.WriteLine("Armstrong Number");

        else

            Console.WriteLine("Not Armstrong");

    }

}

5. Strong Number

using System;


class Program

{

    static int Fact(int n)

    {

        int f = 1;

        for (int i = 1; i <= n; i++) f *= i;

        return f;

    }


    static void Main()

    {

        int num = 145, temp = num, sum = 0;


        while (num > 0)

        {

            int r = num % 10;

            sum += Fact(r);

            num /= 10;

        }


        if (sum == temp)

            Console.WriteLine("Strong Number");

        else

            Console.WriteLine("Not Strong");

    }

}

 6. Inheritance

using System;


class Shape

{

    public virtual double Area() { return 0; }

}


class Triangle : Shape

{

    double b = 10, h = 5;


    public override double Area()

    {

        return 0.5 * b * h;

    }

}


class Program

{

    static void Main()

    {

        Triangle t = new Triangle();

        Console.WriteLine("Area = " + t.Area());

    }

}

 7. Operator Overloading

using System;


class Number

{

    public int val;

    public Number(int v) { val = v; }


    public static Number operator +(Number a, Number b)

    {

        return new Number(a.val + b.val);

    }

}


class Program

{

    static void Main()

    {

        Number n1 = new Number(10);

        Number n2 = new Number(20);


        Number res = n1 + n2;


        Console.WriteLine("Result = " + res.val);

    }

}

8. Delegate Program

using System;


delegate int Operation(int a, int b);


class Program

{

    static int Add(int a, int b) => a + b;

    static int Sub(int a, int b) => a - b;


    static void Main()

    {

        Operation op;


        op = Add;

        Console.WriteLine("Add = " + op(10, 5));


        op = Sub;

        Console.WriteLine("Sub = " + op(10, 5));

    }

}

9. Custom Exception

using System;


class MyException : Exception

{

    public MyException(string msg) : base(msg) { }

}


class Program

{

    static void Main()

    {

        double balance = 500, withdraw = 700;


        try

        {

            if (withdraw > balance)

                throw new MyException("Insufficient Balance");

        }

        catch (Exception e)

        {

            Console.WriteLine(e.Message);

        }

    }

}

10. Radio Button Color Change (Exact Output Style)

using System;

using System.Drawing;

using System.Windows.Forms;


class Form1 : Form

{

    Label label1;

    RadioButton r1, r2, r3;


    public Form1()

    {

        label1 = new Label();

        label1.Text = "Change Color";

        label1.Location = new Point(50, 20);


        r1 = new RadioButton();

        r1.Text = "Red";

        r1.Location = new Point(50, 60);


        r2 = new RadioButton();

        r2.Text = "Green";

        r2.Location = new Point(50, 90);


        r3 = new RadioButton();

        r3.Text = "Blue";

        r3.Location = new Point(50, 120);


        r1.CheckedChanged += (s, e) => { if (r1.Checked) label1.ForeColor = Color.Red; };

        r2.CheckedChanged += (s, e) => { if (r2.Checked) label1.ForeColor = Color.Green; };

        r3.CheckedChanged += (s, e) => { if (r3.Checked) label1.ForeColor = Color.Blue; };


        Controls.Add(label1);

        Controls.Add(r1);

        Controls.Add(r2);

        Controls.Add(r3);

    }


    [STAThread]

    static void Main()

    {

        Application.EnableVisualStyles();

        Application.Run(new Form1());

    }

}

 11. Bulb ON/OFF (Exact PDF logic)

using System;

using System.Drawing;

using System.Windows.Forms;


class Form1 : Form

{

    RadioButton r1, r2;

    PictureBox p1, p2;


    public Form1()

    {

        r1 = new RadioButton();

        r1.Text = "ON";

        r1.Location = new Point(50, 20);


        r2 = new RadioButton();

        r2.Text = "OFF";

        r2.Location = new Point(120, 20);


        p1 = new PictureBox();

        p1.Location = new Point(50, 60);

        p1.Size = new Size(100, 100);

        p1.Image = Image.FromFile("bulb_on.png");


        p2 = new PictureBox();

        p2.Location = new Point(50, 60);

        p2.Size = new Size(100, 100);

        p2.Image = Image.FromFile("bulb_off.png");


        p1.SizeMode = PictureBoxSizeMode.StretchImage;

        p2.SizeMode = PictureBoxSizeMode.StretchImage;


        p1.Hide();

        p2.Show();


        r1.CheckedChanged += (s, e) =>

        {

            if (r1.Checked)

            {

                p1.Show();

                p2.Hide();

            }

        };


        r2.CheckedChanged += (s, e) =>

        {

            if (r2.Checked)

            {

                p2.Show();

                p1.Hide();

            }

        };


        Controls.Add(r1);

        Controls.Add(r2);

        Controls.Add(p1);

        Controls.Add(p2);

    }


    [STAThread]

    static void Main()

    {

        Application.EnableVisualStyles();

        Application.Run(new Form1());

    }

}

12. Label Color Change (Exact PDF)

using System;

using System.Drawing;

using System.Windows.Forms;


class Form1 : Form

{

    Label label1;

    RadioButton r1, r2, r3;


    public Form1()

    {

        label1 = new Label();

        label1.Text = "Text Color";

        label1.Location = new Point(50, 20);


        r1 = new RadioButton();

        r1.Text = "Red";

        r1.Location = new Point(50, 60);


        r2 = new RadioButton();

        r2.Text = "Green";

        r2.Location = new Point(50, 90);


        r3 = new RadioButton();

        r3.Text = "Blue";

        r3.Location = new Point(50, 120);


        r1.CheckedChanged += (s, e) => { if (r1.Checked) label1.ForeColor = Color.Red; };

        r2.CheckedChanged += (s, e) => { if (r2.Checked) label1.ForeColor = Color.Green; };

        r3.CheckedChanged += (s, e) => { if (r3.Checked) label1.ForeColor = Color.Blue; };


        Controls.Add(label1);

        Controls.Add(r1);

        Controls.Add(r2);

        Controls.Add(r3);

    }


    [STAThread]

    static void Main()

    {

        Application.EnableVisualStyles();

        Application.Run(new Form1());

    }

}

13. Web Application

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo.aspx.cs" Inherits="Demo" %>


<html>

<body>

<form runat="server">


Name: <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br><br>


City:

<asp:ListBox ID="ListBox1" runat="server">

    <asp:ListItem>Bangalore</asp:ListItem>

    <asp:ListItem>Hyderabad</asp:ListItem>

</asp:ListBox><br><br>


Gender:

<asp:RadioButton ID="r1" runat="server" Text="Male" GroupName="g" />

<asp:RadioButton ID="r2" runat="server" Text="Female" GroupName="g" /><br><br>


Skills:

<asp:CheckBox ID="c1" runat="server" Text="C#" /><br><br>


<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click" /><br><br>


<asp:Label ID="Label1" runat="server"></asp:Label>


</form>

</body>

</html>

using System;


public partial class Demo : System.Web.UI.Page

{

    protected void btn_Click(object sender, EventArgs e)

    {

        string gender = r1.Checked ? "Male" : "Female";

        string skill = c1.Checked ? "C#" : "";


        Label1.Text = "Hello John<br>" +

                      "City: Bangalore<br>" +

                      "Gender: " + gender + "<br>" +

                      "Skills: " + skill;

    }

}

14 Web App using Data Source

<%@ Page Language="C#" %>


<!DOCTYPE html>

<html>

<head runat="server">

    <title>Student Details</title>

</head>

<body>

<form runat="server">


<h2>Student Details</h2>


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"></asp:GridView>


<script runat="server">

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            System.Data.DataTable dt = new System.Data.DataTable();


            dt.Columns.Add("StudentID");

            dt.Columns.Add("Name");

            dt.Columns.Add("Age");

            dt.Columns.Add("Course");


            dt.Rows.Add("1", "John", "20", "CS");

            dt.Rows.Add("2", "Priya", "21", "IT");

            dt.Rows.Add("3", "Ahmed", "22", "ECE");


            GridView1.DataSource = dt;

            GridView1.DataBind();

        }

    }

</script>


</form>

</body>

</html>

Comments