C# Simple calculator on Windows application

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 MY_first_windows_form_application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
       

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int num1, num2, res;
            num1 = Convert.ToInt32(textBox1.Text);
            num2 = Convert.ToInt32(textBox2.Text);
            res = num1 + num2;
            label3.Text = res.ToString();
         
        }

        private void button2_Click(object sender, EventArgs e)
        {

            int num1, num2, res;
            num1 = Convert.ToInt32(textBox1.Text);
            num2 = Convert.ToInt32(textBox2.Text);
            res = num1 - num2;
            label3.Text = res.ToString();


        }

        private void button3_Click(object sender, EventArgs e)
        {
            int num1, num2, res;
            num1 = Convert.ToInt32(textBox1.Text);
            num2 = Convert.ToInt32(textBox2.Text);
            res = num1 * num2;
            label3.Text = res.ToString();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            int num1, num2, res;
            num1 = Convert.ToInt32(textBox1.Text);
            num2 = Convert.ToInt32(textBox2.Text);
            res = num1 / num2;
            label3.Text = res.ToString();

        }

        private void button5_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
    }
}

OUTPUT




Continue Reading

c# how to create exception by itself

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

namespace exceptionhandling_02{

    public class book:ApplicationException{
        public book(string issued)
            : base(issued)
        {
       
        }
       
    }
    public class gain_info {
   
        public string  iss;
        public void get_info()
        {


            Console.WriteLine("WELCOME TOO OXFORD LIBRARY");
            Console.WriteLine("enter your book name");
            iss = Console.ReadLine();
            if (iss == "C#" || iss == "c#")
            {
                throw (new book("OOP BOOK CANT BE ISSUED"));
               
            }
            else
            {

                Console.WriteLine("you have issued this book :{0}", iss);

            }



        }
 
    }
    class program
    {

       
        static void Main(string[] args)
        {
            shuru:
            gain_info obj = new gain_info();

            try {

                obj.get_info();
           
            }
            catch(book e)
            {
                Console.WriteLine("exception caught ",e.Message);
            }
           
            goto shuru;
         

        }
    }
}

OUTPUT



Continue Reading

C# how to use delegetion in your code

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


delegate void player();

namespace delegationkeyword
{

    class players
    {
       public  static int choice;
       public  static void list() {
            Console.WriteLine("HERE IS THE LIST OF FIVE PLAYERS");
       Console.WriteLine("1- VIRAT KOHLI   \n 2- STEVEN SMITH \n 3- JOE ROOT \n 4- YOUNUS KHAN  \n 5- kANE WILLIAMSOM");
       Console.WriteLine("now enter favourite player input ");
       choice = Convert.ToInt32(Console.ReadLine());
       if (choice == 1)
       {
       Console.WriteLine("MATCHES= 12  RUNS=1215       AVERAGE= 75.93             S-R=60.41");

      
       }
            if(choice==2){
           
              Console.WriteLine("MATCHES=11   RUNS=1079       AVERAGE=71.93              S-R=58.73");


           
            }
             if(choice==3){

                 Console.WriteLine("MATCHES=17   RUNS=1477          AVERAGE=49.23              S-R=60.70");


           
            }
             if (choice == 4)
             {
                 Console.WriteLine("MATCHES=10   RUNS=673           AVERAGE=37.38              S-R=50.48");


            
            
             }
             if (choice == ){
                 Console.WriteLine("MATCHES=10   RUNS=753           AVERAGE=47.06              S-R=53.4 }

        }  


        static void Main(string[] args)
        {
            player abc = new player(list);
            list();
            Console.ReadKey();
        }
    }

}
OUTPUT



Continue Reading

C# how to use enum keyword

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

namespace enumkeyword
{
    class Program
    {
        enum traffic { red, yellow, green }
        static void Main(string[] args)
        {

            int trafstart = (int)traffic.red;
            int trafmiddle = (int)traffic.yellow;
            int trafend = (int)traffic.green;
            Console.WriteLine("Red {0}",trafstart);
            Console.WriteLine("Yellow {0}", trafmiddle);
            Console.WriteLine("Green {0}",trafend);
          
            Console.ReadKey();

        }
    }

}
Output


Continue Reading

C# how TOO USE exception handling divided by zero expression


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

namespace exception_handling_1
{
    class Program
    {
        static void Main(string[] args)
        {

           start :

            Console.WriteLine("WELCOME TOO EXCEPTION HANDLING");
            try
            {

                float a, b,result;
                Console.WriteLine("enter your first number");
                a = float.Parse(Console.ReadLine());
                Console.WriteLine("enter second number");
                b = float.Parse(Console.ReadLine());
                if (b == 0)
                {

                    throw new DivideByZeroException();

                }
                else
                    result = a / b;
                Console.WriteLine("your ans is after division : {0}", result);
            }
           
            catch
            {

                Console.WriteLine("SORRY  Number can't divide by zero ");

            }
            finally {

                Console.WriteLine("thankx for using our calculator");
           
            }
            goto start;

        

        }
    }

}

OUTPUT

Continue Reading

Function Overloading

Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>


using namespace std;// not discussed yet.
// Prototype, Declaration
int Tax_Amount(int house_Sq);
int Tax_Amount(int house_Sq, int Vehicle_CC);
int Tax_Amount(int house_Sq, int Vehicle_CC, char Comercial);

void main(void)
{
int hsq;
int VCC;
char com;
cout<<"\n\n_________Well Come to CDGK Taxation Department System __________ ";
cout<<"\n\n Plesae Enter House SQ :";
cin>>hsq;
cout<<"\n\n Please Enter Vehicle CC : { Enter 0 for N/A } ";
cin>>VCC;
cout<<"\n\n Are These Property Use as Comercial:  { Press y = yes, n = no } ";
    cin>>com;
   // Function Calling Work:
if(VCC==0 && com=='n')
{
   int tax_Payable = Tax_Amount(hsq);
cout<<" \n\n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}
if(VCC>0 && com=='n')
{
   int tax_Payable = Tax_Amount(hsq,VCC);
cout<<" \n\n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}
if(VCC>0 && com=='y')
{
   int tax_Payable = Tax_Amount(hsq,VCC,com);
cout<<" \n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}

}

//Function Defination

int Tax_Amount(int house_Sq)
{
int Tax=(house_Sq*1000);
return Tax;

}

int Tax_Amount(int house_Sq, int Vehicle_CC)
{
     int Tax=(house_Sq*1000)+(Vehicle_CC*100);
return Tax;

}

int Tax_Amount(int house_Sq, int Vehicle_CC, char Comercial)
{
int Tax=(house_Sq*2000)+(Vehicle_CC*200);
return Tax;
}

Continue Reading

Generate Randam Number

Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<cstdlib>
using namespace std;

int random(int);// Prototype
void main()
{
int a;
cout<<"\n Please enter how many random number you want to generate :";
    cin>>a;
random(a);
getch();

}

int random(int num)
{

if(num<=0)
{
return 0;
}
cout<<"\n ==>> "<<rand();
num--;
random(num);
}
Output:


Continue Reading