Tuesday, 24 September 2013

INDEXERS OVERLOADING .

using System;

namespace ConsoleApplication1

{

class student

{

private string[] name = new string[100];

public string this[int index]

{

get

{

return name[index];

}  

set

{

name[index] = value;

}

}

public string this[char firstletter]

{

get

{

return name[firstletter];

}  

set

{

name[firstletter] = value;

}

}

}

class Class1

{ static void Main(string[] args)

{

student s = new student();

s[0] = "uttam";

s[1] = "pathak";

Console.WriteLine(s[0]  + " " + s[1]);

student s2 = new student();

s2['S'] = "uttam";

s2['M'] = "pathak";

Console.WriteLine(s2['S']  + " " + s2['M']);

Console.ReadLine();}}}

Create a Class CUSTOMER with two private members ID and NAME, use this members in another class using PROPERTIES.

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

namespace customer
{
    class customer
    {
        private int cust_id = -1;
        public int ID
        {
            get
            {
                return cust_id;

            }
            set
            {
                cust_id = value;
            }
       
        }
        private string cust_name = string.Empty;
        public string name
        {
            get

            {
                return cust_name;
            }
            set
            {
                cust_name = value;
            }
       
        }


        static void Main(string[] args)
        {

            customer cust = new customer();
            cust.ID = 1;
            cust.name = "raman";

            Console.WriteLine("ID: {0}, Name: {1}", cust.ID, cust.name);

            Console.ReadLine();
        }
   
    }


}


Thursday, 5 September 2013

Tic Tac Toe ( console ) game

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

namespace Tictactest
{
    class Tictactest
    {

        int row,col;
        char player1;
    char player2;
char[,] arr = new char[3, 3];  

 int choice()
 {
  Console.WriteLine("Enter player 1 choice(O/X)");
  player1 = char.Parse(Console.ReadLine());
        Console.WriteLine("Enter player 2 choice(O/X)");
        player2 = char.Parse(Console.ReadLine());
    return 0;
 }

 int inputplayer1()
    {
     Console.WriteLine("player 1 turn");
      Console.WriteLine("enter the row ");
      row=Int32.Parse(Console.ReadLine());
      Console.WriteLine("enter the column ");
      col=Int32.Parse(Console.ReadLine());
   arr[row,col]=player1;
    
   return 0;
    }

 int inputplayer2()
    {
     Console.WriteLine("player 2 turn");
      Console.WriteLine("enter the row ");
      row = Int32.Parse(Console.ReadLine());
      Console.WriteLine("enter the column ");
      col = Int32.Parse(Console.ReadLine());
   arr[row,col]=player2;
    
   return 0;
    }

 int checkplayer( )
 {
     if (arr[0, 0] == 'o' && arr[1, 1] == 'o' && arr[2, 2] == 'o' ||
arr[0, 2] == 'o' && arr[1, 1] == 'o' && arr[2, 0] == 'o' ||
arr[0, 0] == 'o' && arr[0, 1] == 'o' && arr[0, 2] == 'o' ||
arr[1, 0] == 'o' && arr[1, 1] == 'o' && arr[1, 2] == 'o' ||
arr[2, 0] == 'o' && arr[2, 1] == 'o' && arr[2, 2] == 'o' ||
arr[0, 0] == 'o' && arr[1, 0] == 'o' && arr[2, 0] == 'o' ||
arr[0, 1] == 'o' && arr[1, 1] == 'o' && arr[2, 1] == 'o' ||
arr[0, 2] == 'o' && arr[1, 2] == 'o' && arr[2, 2] == 'o')
  {
  Console.WriteLine("BINGO :) Player 1 won ");

  Environment.Exit(0);

  }
  else
  {
      if (arr[0, 0] == 'x' && arr[1, 1] == 'x' && arr[2, 2] == 'x' ||
      arr[0, 2] == 'x' && arr[1, 1] == 'x' && arr[2, 0] == 'x' ||
      arr[0, 0] == 'x' && arr[0, 1] == 'x' && arr[0, 2] == 'x' ||
      arr[1, 0] == 'x' && arr[1, 1] == 'x' && arr[1, 2] == 'x' ||
      arr[2, 0] == 'x' && arr[2, 1] == 'x' && arr[2, 2] == 'x' ||
      arr[0, 0] == 'x' && arr[1, 0] == 'x' && arr[2, 0] == 'x' ||
      arr[0, 1] == 'x' && arr[1, 1] == 'x' && arr[2, 1] == 'x' ||
                arr[0, 2] == 'x' && arr[1, 2] == 'x' && arr[2, 2] == 'x')
      {
          Console.WriteLine(" BINGO :) Player 2 won ");
        
          Environment.Exit(0);
      } 
 
  }

 return 0;
 }


 void display()
 {
 for(row=0;row<3;row++)
 {
 for(col=0;col<3;col++)
 {
 Console.Write(arr[row,col]);
    
 }
 Console.WriteLine("\n");
 }
 }


        static void Main(string[] args)
        {

            Tictactest tic=new Tictactest();
        tic.choice();

      
    tic.inputplayer1();
    Console.Clear();
            tic.display();
   
    tic.inputplayer2();
    Console.Clear();
            tic.display();
   
tic.inputplayer1();
Console.Clear();
            tic.display();
  
            tic.inputplayer2();
    Console.Clear();
            tic.display();

            tic.checkplayer();
            tic.inputplayer1();
         Console.Clear();
            tic.display();
            tic.checkplayer();
            tic.inputplayer2();
            Console.Clear();
            tic.display();
            tic.checkplayer();
            tic.inputplayer1();
            Console.Clear();
            tic.display();
            tic.checkplayer();      
            tic.inputplayer2();         
            Console.Clear();
            tic.display();
            tic.checkplayer();
            tic.inputplayer1();        
            Console.Clear();
            tic.display();

            tic.checkplayer();
                      tic.inputplayer2();
            Console.Clear();
            tic.display();

    }
    }

        }
  

Sunday, 1 September 2013

jagged array .

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

namespace jaggedAreray
{
   class Program
   {
       static void Main(string[] args)
       {
           int[][] jaggedArray = new int[3][];
           jaggedArray[0] = new int[2];
           int i,j;

           jaggedArray[0][0]=1;
           jaggedArray[0][1] =2;

           jaggedArray[1] = new int[1];
           jaggedArray[2] = new int[3] { 3, 4, 5 };


           for (i = 0; i < jaggedArray.Length; i++)
           {
               int[] jagged = jaggedArray[i];

               for (j = 0; j < jagged.Length; j++)
               {
                   Console.WriteLine(jagged[j]+""
);

               }
               Console.WriteLine();
           }



       }
   }
}

sorting of number

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

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

           int[] arr;
           arr = new int[10];
           int i,temp,j;

           Console.WriteLine("enter the element");
           for (i = 1; i < 4; i++)
           {

               arr[i] = Int32.Parse(Console.ReadLine()
);
           }

           for (i = 1; i < 4; i++)
           {
               for (j = 1; j < 4-i;j++ )
                   if (arr[j] > arr[j+1])
                   {
                       temp=arr[j+1];
arr[j+1]=arr[j];
                       arr[j]=temp;




                   }
               }

                   for(i = 1; i < 4; i++)

               Console.WriteLine("array is " + arr[i]);

                           }

       }


}

missing number between 1 -100 ?


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

namespace naturalNumber
{
   class Program
   {
       static void Main(string[] args)
       {
           int[] arr = new int[5];
           int sum = 0,total,miss;
           total = 5*(5+1)/2;
           Console.WriteLine("Enter the value");
           for (int i = 0; i < 5; i++)
           {
               arr[i] = Int32.Parse(Console.ReadLine()
);
               sum = sum + arr[i];


           }
          miss = total - sum;

           Console.WriteLine("number is " + miss);

       }



   }
}

library info ( small program )

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

namespace libraryInfo
{
    class Program
    {
       static void Main(string[] args)
       {
           int choice;
           swat:
           Console.WriteLine("1.Computer Books");
           Console.WriteLine("2.Mathmetical Books");
           Console.WriteLine("3.History Books");
           Console.WriteLine("4.English");
           choice = Int32.Parse(Console.ReadLine());
          
           switch (choice)
           {
               case 1:
                   Console.WriteLine("1.Introducing Windows Server 2012");
                   Console.WriteLine("2.Let Us C");
                   Console.WriteLine("3.Database Fundamentals");
                   Console.WriteLine("4.C# in Depth ");
                   break;
               case 2:
                   Console.WriteLine("1.Abstract Algebra");
                   Console.WriteLine("2.Complex Analysis");
                   Console.WriteLine("3.Applied Mathematics");
                   Console.WriteLine("4.Calculus");
                  

                   break;
               case 3:
                   Console.WriteLine("1.The Origin of Species ");
                   Console.WriteLine("2.The Koran ");
                   Console.WriteLine("3.The Communist Manifesto ");
                   Console.WriteLine("4.The Republic ");
                   Console.WriteLine("5.The Complete Works ");
                   break;
               case 4:
                   Console.WriteLine("1.An Enchanted Evening");
                   Console.WriteLine("2.Battle of Midway");
                   Console.WriteLine("3.Endangered Species");
                   Console.WriteLine("4.Part of their World");
                   break;
               default:
                   Console.WriteLine("Try again");
                   goto swat;   
                   break;
           
           
           
           }
       }
    }
}

call by reference.

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

namespace callByRefer
{
    class Program
    {
       public static void swap(ref int a, ref int b)
       {
           a = a + b;
           b = a - b;
           a = a - b;

           Console.WriteLine("after swapping value of a {0} and b {1}", a, b);
       }


       static void Main(string[] args)
       {
           int c = 10, d = 20;
           Console.WriteLine("before swapping  value of a {0} and b is{1}", c, d);

           swap(ref c, ref d);




       }
    }
}

decimal to binary conversion

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

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

       {
           int number,i=0,j;
           number = Int32.Parse(Console.ReadLine());
           int[] num = new int[50];
                 
           while (number > 0)
           {
               
                   num[i++] = number % 2;
               
                   number = number / 2;
                   
                   
                                 
               }
               for (j =i-1 ; j >= 0; j--)
               {
                   Console.Write("" + num[j]);
               }

           }
         
       }
    }

drac of two number or not?

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

namespace dracula
{
   class Program
   {
       static void Main(string[] args)
       {
           int number,n1,n2,n3,sum;
           Console.WriteLine("Enter the number");
           number = Int32.Parse(Console.ReadLine());
           n1 = number % 10;
           
           number = number / 10;
           n2 = number % 10;
           number = number / 10;
           n3 = number % 10;
           sum = n2 + n3;

           if (sum == n1)
           {

               Console.WriteLine("number is dracula");
           }
           else
           {
               Console.WriteLine("number is not dracula");
           }

       }
   }
}