Pages

Tuesday, June 23, 2015

Program to Implement Linear Search Algorithm

#include<iostream.h>
#include<constream.h>
void read(int a[10],int n)
{
                cout<<"reading\n";
                for(int i=0;i<n;i++)
                                cin>>a[i];
}
void display(int a[10],int n)
{
                for(int i=0;i<n;i++)
                                cout<<a[i]<<"\t";
}
void linearsearch ( int a[10],int n  )
{
                int k,flag=0;
                read(a,n);
                display(a,n);
                cout<<"\nenter an element to be search\n";
                cin>>k;
                for(int i=0;i<n;i++)
                {
                                if(a[i]==k)
                                                flag=1;
                                break;
                }
                if(flag==1)
                                cout << "\nsearching is  successful,element is found at position " << i +1<<endl;
                else
                                cout<<"searching not successful\n";
}
void main()
{
                int a[10], n;
                clrscr();
                cout<<"enter n value..\n";
                cin>>n;
                linearsearch(a,n);
                getch();
}


Saturday, June 20, 2015

How to Use Key Event Args in C#


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

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            label1.Text = "Alt " + (e.Alt ? "Yes" : "No") + "\n" + " Shift"
                + (e.Shift ? " Yes" : "No") + " Ctrl " + (e.Control ? " Yes" : " No")
                + "\n" + "Key Code " + e.KeyCode + "\n" + "Key Value "
                + e.KeyValue + "\n" + "Key Data " + e.KeyData + "\n";

           
        }
    }
}



C# Program to Implement Binary Search Tree using Linked List

using System;
using System.Collections.Generic;
using System.Text;
namespace TreeSort
{
    class Node
    {
        public int item;
        public Node leftc;
        public Node rightc;
        public void display()
        {
            Console.Write("[");
            Console.Write(item);
            Console.Write("]");
        }
    }
    class Tree
    {
        public Node root;
        public Tree()
        {
            root = null;
        }
        public Node ReturnRoot()
        {
            return root;
        }
        public void Insert(int id)
        {
            Node newNode = new Node();
            newNode.item = id;
            if (root == null)
                root = newNode;
            else
            {
                Node current = root;
                Node parent;
                while (true)
                {
                    parent = current;
                    if (id < current.item)
                    {
                        current = current.leftc;
                        if (current == null)
                        {
                            parent.leftc = newNode;
                            return;
                        }
                    }
                    else
                    {
                        current = current.rightc;
                        if (current == null)
                        {
                            parent.rightc = newNode;
                            return;
                        } } } }
        }
        public void Preorder(Node Root)
        {
            if (Root != null)
            {
                Console.Write(Root.item + " ");
                Preorder(Root.leftc);
                Preorder(Root.rightc);
            }
        }
        public void Inorder(Node Root)
        {
            if (Root != null)
            {
                Inorder(Root.leftc);
                Console.Write(Root.item + " ");
                Inorder(Root.rightc);
            }
        }
        public void Postorder(Node Root)
        {
            if (Root != null)
            {
                Postorder(Root.leftc);
                Postorder(Root.rightc);
                Console.Write(Root.item + " ");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Tree theTree = new Tree();
            theTree.Insert(20);
            theTree.Insert(25);
            theTree.Insert(45);
            theTree.Insert(15);
            theTree.Insert(67);
            theTree.Insert(43);
            theTree.Insert(80);
            theTree.Insert(33);
            theTree.Insert(67);
            theTree.Insert(99);
            theTree.Insert(91);           
            Console.WriteLine("Inorder Traversal : ");
            theTree.Inorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Preorder Traversal : ");
            theTree.Preorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Postorder Traversal : ");
            theTree.Postorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.ReadLine();
        }
    }

}

Thursday, June 18, 2015

How To Create Array of Structures

#include <iostream>
#include <string>
#include<conio.h>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int year;
} films [3];

void printmovie (movies_t movie);

int main ()
{
  string mystr;
  int n;

  for (n=0; n<3; n++)
  {
    cout << "Enter title: ";
    getline (cin,films[n].title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> films[n].year;
  }

  cout << "\nYou have entered these movies:\n";
  for (n=0; n<3; n++)
    printmovie (films[n]);
  return 0;
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}

Wednesday, June 17, 2015

Statistical Analysis and Histogram


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

namespace Statistiacal_Analysis
{
    class data
    {
        //Function  for Mean-----------------------------------------------------------------------------------------
        public int mean(int[] arr, int num)
        {
            int me = 0;
            for (int i = 0; i < num; i++)
            {
                me = me + arr[i];
            }
            me = me / num;
            return me;
        }

        //------------------------------------------------------------------------------------------------------------------
        //Function for Median----------------------------------------------------------------------------------------
        public void median(int[] arr, int num)
        {
            int me = 0;
            // For Even Size Of The Array----------------------------------------------------------------------------
            if (num % 2 == 0)
            {
                me = ((arr[(num / 2) - 1]) + (arr[num / 2])) / 2;

                Console.WriteLine("The Median Is : " + me);
                Console.WriteLine("=======================================================");
            }
            // For Odd  Size Of The Array---------------------------------------------------------------------------
            else
            {
                me = arr[((num + 1) / 2) - 1];

                Console.WriteLine("The Median is : " + me);
                Console.WriteLine("=======================================================");
            }

        }

        //-----------------------------------------------------------------------------------------------------------------
        //Function  for Mode-------------------------------------------------------------------------------------
        public void mode(int[] array, int size)
        {

            int counter = 1;
            int max = 0;
            int Mode = array[0];
            for (int pass = 0; pass < size - 1; pass++)
            {
                if (array[pass] == array[pass + 1])
                {
                    counter++;
                    if (counter > max)
                    {
                        max = counter;
                        Mode = array[pass];
                    }
                }
                else
                    counter = 1; // reset counter.
            }
            Console.WriteLine("The mode is: " + Mode);
            Console.WriteLine("========================================================");
        }

        //------------------------------------------------------------------------------------------------------------------
        //Function for Standerd Deviation--------------------------------------------------------------------------
        public void stanDev(int[] arr, int num)
        {

            double sd = 0.0;
            double power = 2.0;
            double val = 0.0;
            int Mean = mean(arr, num);
            for (int i = 0; i < num; i++)
            {
                val = (arr[i] - Mean);
                sd = sd + (Math.Pow(val, power)) / (num - 1);
            }

            Console.WriteLine("The Standerd Deviation Is : " + (Math.Sqrt(sd)));
            Console.WriteLine("=======================================================");
        }
        //-----------------------------------------------------------------------------------------------------------------
        //Function For Printing Histogram---------------------------------------------------------------------------
        public void histogram(int[] arr, int num)
        {
            string[][] a = new string[num][];
            for (int i = 0; i < num; i++)
            {
                a[i] = new string[arr[i]];
            }
            Console.Write("Element\t\tValue\t\tHistogram\n");
            Console.WriteLine();
            for (int i = 0; i < num; i++)
            {
                Console.Write(i + "\t\t" + arr[i] + "\t\t");
                for (int j = 0; j < arr[i]; j++)
                {
                    if (j % 4 == 0 && j != 0)
                    {
                        a[i][j] += "|";
                    }
                    else
                    {
                        a[i][j] += "*";
                    }
                   
                    Console.Write(a[i][j]);
                }
                Console.WriteLine();
            }
        }
        //-----------------------------------------------------------------------------------------------------------------
    }
}
//------------------------------------------------- Class data ends here---------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Statistiacal_Analysis
    class Program
    {
        //DRIVER METHOD--------------------------------------------------------------------------------------
        static void Main(string[] args)
        {
            data z = new data();
            string s="";
            // Declarations Of  Variables -----------------------------------------------------------------------
            Random r = new Random();
            int a=0;
            // Dynamically Generated Size In  Array-------------------------------------------------------------
            Console.WriteLine("=======================================================");
            Console.WriteLine("\t\t\t      STAISTICAL DATA ANALYSIS");
            Console.WriteLine("=======================================================");
            Console.Write("Enter The Size OF The Array : ");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("-------------------------------------------------------------------------------");
            int []N=new int[a];

            // Random Numbers Assigned To The Array-----------------------------------------------------------
            for (int i = 0; i < a; i++)
            {
                N[i] = r.Next(0, 9);
                
                Console.WriteLine("The Collected Sample # "+ i +" Is : " + N[i]);                
            }
            Console.WriteLine("=======================================================");
            for (int i = 0; i < a; i++)
            {
                //Sorting The Array In Order To Calculate Mode---------------------------------------------------
                Array.Sort(N);

                //Printing The Sorted Array----------------------------------------------------------------------------
                Console.WriteLine("The Sorted Data Is : " + N[i]);               
            }
          
            //---------------------------------------------------------------------------------------------------------------

            //function call for Mean------------------------------------------------------------------------------------
            Console.WriteLine("=======================================================");
            Console.WriteLine("The Mean Is : "+z.mean(N,a));
            Console.WriteLine("=====================================================");
            //---------------------------------------------------------------------------------------------------------------

            //function call for Median----------------------------------------------------------------------------------
            z.median(N,a);            
            //--------------------------------------------------------------------------------------------------------------
            //function call for Mode------------------------------------------------------------------------------------
            z.mode(N, a);
            //--------------------------------------------------------------------------------------------------------------
            //function call for Standerd Deviation-------------------------------------------------------------------           
            z. stanDev(N, a);            
            //---------------------------------------------------------------------------------------------------------------

            //function call for Histogram-------------------------------------------------------------------------------
            Console.Write("FOR HISTOGRAM PRESS H OR TO CLOSE PRESS ENTER :  ");
            s=Console.ReadLine();
            if (s == "h")
            {
                z.histogram(N, a);
            }
            else
            {
                Environment.Exit(0);
            }

            Console.ReadLine();
            
        }
    }
}

Monday, June 15, 2015

A C# Program To Explain Get Set Accessor


using System;

namespace Example2
{
  class input
   {
     private static int num1, num2, result;
     public void add()
      {
        result = num1 + num2;
        Console.WriteLine("\n\nAdd = {0}", result);
        Console.ReadLine();
      }

     // Creating property for storing value in num1
     public int Number1
      {
        get
         {
           return num1;
         }
        set
         {
           num1 = value;
         }
      }

     // Creating property for storing value in num2
     public int Number2
      {
        get
         {
           return num2;
         }
        set
         {
           num2 = value;
         }
      }
   }

  class Program
   {
     static void Main(string[] args)
      {
        input inp = new input();
        Console.Write("Enter number 1st:\t");
        inp.Number1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter number 2nd:\t");
        inp.Number2 = Convert.ToInt32(Console.ReadLine());

        inp.add();
      }
   }
}

Saturday, June 13, 2015

Write a program to demonstrate private access specifier?


using System;

namespace Example1
{
  class Program
   {
     private void add()
      {
        int num1, num2, result;
        Console.Write("Enter a number:\t");
        num1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("\nEnter second number:\t");
        num2 = Convert.ToInt32(Console.ReadLine());

        result = num1 + num2;
        Console.WriteLine("{0} + {1} = {2}", num1, num2,           result);
      }
     static void Main(string[] args)
      {
        Program p = new Program();
        p.add(); //It is valid, because private add() is           in same class
        Console.ReadLine();
      }
   }
}

Friday, June 12, 2015

Example of Multi Dimension Array

using System;

namespace multi_dimensional_array
{
  class Program
   {
     static void Main(string[] args)
      {
        int i, j;
        //Declaring multi dimensional array
        string[,] Books = new string[3,3];
        for (i = 0; i < 3; i++)
         {
           for (j = 0; j < 3; j++)
            {
              Console.Write("\nEnter Book Name for {0}.                   Row and {1}. column:\t",i+1,j+1);
              Books[i,j] = Console.ReadLine();
            }
         }

        Console.WriteLine("\n\n=========================");
        Console.WriteLine("All the element of Books array            is:\n\n");

        //Formatting Output
        Console.Write("\t1\t2\t3\n\n");
        //outer loop for accessing rows
        for (i = 0; i < 3; i++)
         {
           Console.Write("{0}.\t", i + 1);

           //inner or nested loop for accessing column                of each row
           for (j = 0; j < 3; j++)
            {
              Console.Write("{0}\t", Books[i,j]);
            }
           Console.Write("\n");
         }
        Console.WriteLine("\n\n=========================");
        Console.ReadLine();
      }
   }
}

Thursday, June 11, 2015

Word Processor



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;
using System.Drawing.Printing;

using System.IO;
namespace Word_Processer
{
    public partial class WordPadForm : Form
    {
        public WordPadForm()
        {
            InitializeComponent();
        }

        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Clear();       //Clears the WordNote(RichTextBox)
        }
       
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog opd = new OpenFileDialog();
            opd.DefaultExt = "rtf";
            opd.ShowHelp = true;
            DialogResult result = opd.ShowDialog();
            if (result == DialogResult.OK)
            {
                string filename = opd.FileName;
                //Open File Dialog Can Be Used To Open A File But With RTF Extension
                WordNote.LoadFile(filename);
            }
        }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            //Save File Dialog Can Be Used To Save A File But With RTF Extension
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = "rtf";
            sfd.ShowHelp = true;
            DialogResult res = sfd.ShowDialog();
            if (res == DialogResult.OK)
            {
                string filename = sfd.FileName;
                WordNote.SaveFile(filename);
            }
        }

        private void printToolStripButton_Click(object sender, EventArgs e)
        {
            PrintDocument docToPrint = new PrintDocument();//Print Document Object  //-> Thanks To MSDN
            PrintDialog pd = new PrintDialog(); //Print Dialog Object   //-> Thanks To MSDN
            //Properties Of Print Dialog Are Initially False, Changed To True So That They Can Be Used
            pd.AllowSomePages = true;
            pd.AllowPrintToFile = true;
            pd.AllowSelection = true;
            pd.AllowCurrentPage = true;
            pd.ShowHelp = true;
            pd.Document = docToPrint;
            DialogResult result = pd.ShowDialog();

            if (result == DialogResult.OK)
            {
                docToPrint.Print();
            }
        }
        private void helpToolStripButton_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.mswordhelp.com/"); 
            // Help Website Will Open In The Default Browser         
        }
        private void Bold_Click(object sender, EventArgs e)
        {
            Font font=WordNote.SelectionFont;//Sets The Selected Font To The Font Variable
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style ^ FontStyle.Bold);
        }
        private void Italic_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style ^ FontStyle.Italic);
        }
        private void UnderLine_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size,font.Style^ FontStyle.Underline);
        }

        private void StrikeOut_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size,font.Style ^ FontStyle.Strikeout);            
        }
        private void Regular_Click(object sender, EventArgs e)
        {
            Font font = WordNote.SelectionFont;
            //Selection Font Is Used So That The Font Style Can Be Applied To The SelectedText
            WordNote.SelectionFont = new Font(font.FontFamily, font.Size, FontStyle.Regular);
        }
        private void Center_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Center;
        }
        private void RightAlign_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Right;
        }
        private void LeftAlign_Click(object sender, EventArgs e)
        {
            //Selection Font Is Used So That The Alignment Can Be Applied To The SelectedText
            WordNote.SelectionAlignment = HorizontalAlignment.Left;
        }
        private void Color_Click(object sender, EventArgs e)
        {
            //Color Dialog Is Used Here To Change The Font Color
            ColorDialog cd = new ColorDialog();//Object Of Color Dialog
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            cd.Color = WordNote.ForeColor;
            DialogResult result = cd.ShowDialog();
            if (result == DialogResult.OK)
            {
                WordNote.ForeColor = cd.Color;
                //Color Button's BackColor Is Set With The Fore Color Of The RichTextBox (WordNote)
                Color.BackColor = WordNote.ForeColor;
            }        
        }
        private void Fontsize_SelectedIndexChanged(object sender, EventArgs e)
        {
           //Fontsize ComboBox Is Used Here to Select The Desired Font Size
            string value = Fontsize.SelectedItem.ToString();
            float size = Single.Parse(value);
            WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, size, WordNote.Font.Style);
        }
        private void Fontfamily_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Fontfamily ComboBox Is Used Here to Select The Desired Font Family
            string value = Fontfamily.SelectedItem.ToString();
            WordNote.SelectionFont = new Font(value,WordNote.Font.Size, WordNote.Font.Style);          
        }
        private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //PageSetupDialog Is Used Here To Change The Page Settings
            //->Thanks To MSDN
            PageSetupDialog a = new PageSetupDialog();
            a.PageSettings =   new PageSettings();
            a.PrinterSettings =   new PrinterSettings();
 a.MinMargins = new Margins();a.AllowMargins = true;  a.AllowOrientation = true;
 a.AllowPaper = true;a.AllowPrinter = true;a.ShowNetwork = true;  a.ShowHelp = true;
            a.ShowDialog();          
        }
        private void fontSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Font Dialog For The Format Menu
            FontDialog a = new FontDialog();
            a.ShowHelp = true;
            a.ShowApply = true;
            DialogResult result = a.ShowDialog();
            if (result == DialogResult.OK)
            {
                Font font = a.Font;
             WordNote.SelectionFont = new Font(font.FontFamily, font.Size, font.Style);
            }
        }     
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Open Dialog For the Tool Strip as a Menu Item
            OpenFileDialog opd = new OpenFileDialog();
            opd.DefaultExt = "rtf";
            opd.ShowHelp = true;
            DialogResult result = opd.ShowDialog();
            if (result == DialogResult.OK)
            {
                string filename = opd.FileName;
                //Open File Dialog Can Be Used To Open A File But With RTF Extension
                WordNote.LoadFile(filename);
            }        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Save File Dialog For the Tool Strip as a Menu Item
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = "rtf";
            sfd.ShowHelp = true;
            DialogResult res = sfd.ShowDialog();
            if (res == DialogResult.OK)
            {
                string filename = sfd.FileName;
                //Save File Dialog Can Be Used To Save A File But With RTF Extension
                WordNote.SaveFile(filename);
            }        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrintDocument docToPrint = new PrintDocument();
            //Print Document Object  //-> Thanks To MSDN
            PrintDialog pd = new PrintDialog(); //Print Dialog Object   --> Thanks To MSDN
            //Properties Of Print Dialog Are Initially False, Changed To True So That They Can Be Used                
pd.AllowSomePages = true;pd.AllowPrintToFile = true;  pd.AllowSelection = true;
     pd.AllowCurrentPage = true;            pd.ShowHelp = true;
     pd.Document = docToPrint;   DialogResult result = pd.ShowDialog();

            if (result == DialogResult.OK)
            {
                docToPrint.Print();
            }        }
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();     //To Close The Application
        } 
        private void BulletindentButton_Click(object sender, EventArgs e)
        {
            //Bullet Toggle Button
            if (WordNote.SelectionBullet == false)
            {
                WordNote.SelectionBullet = true;
       WordNote.BulletIndent = 20;  //Indent Is The Space Between The Bullet and The Text          
            }
            else
            {
                WordNote.SelectionBullet = false;
            }        }

        private void DecreasefontSizeButton_Click(object sender, EventArgs e)
        {
            //Font Size Decrease Using The Selected Index
            if (Fontsize.SelectedIndex != -1)
            {
                int a = Fontsize.SelectedIndex--;
                float f = Single.Parse(a.ToString());
                WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, f, WordNote.Font.Style);
            }
            else if(Fontsize.SelectedIndex ==-1)
            {               
               MessageBox.Show("Font Size Connot Be Less than 9", "Font Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void IncreasefontSizeButton_Click(object sender, EventArgs e)
        {
            //Font Size Increase Using The Selected Index
            if (Fontsize.SelectedIndex<33)
            {
                int a = Fontsize.SelectedIndex++;
                float f = Single.Parse(a.ToString());
                WordNote.SelectionFont = new Font(WordNote.Font.FontFamily, f, WordNote.Font.Style);
            }
            else if (Fontsize.SelectedIndex>32)
            {
                MessageBox.Show("Font Size Connot Be Greater Than 42", "Font Size", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //The Help Website Will Open In The Default Browser
            System.Diagnostics.Process.Start("http://www.mswordhelp.com/");
        } 
        private void ClearPageButton_Click(object sender, EventArgs e)
        {
            WordNote.Clear();   //To Clear The Page(RichTextBox)                
        }


        private void cutToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Cut();//RichTextBox Built in Function for Cut Operation
        }

        private void copyToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Copy();//RichTextBox Built in Function for Copy Operation
        }

        private void pasteToolStripButton_Click(object sender, EventArgs e)
        {
            WordNote.Paste();//RichTextBox Built in Function for Paste Operation
        }

        private void paintToolStripMenuItem_Click(object sender, EventArgs e)
        {
           System.Diagnostics.Process.Start("mspaint");//To Start The .exe file Of Paint
        }
        private void symbolsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("charmap");//To Start The .exe file Of Character Map           
        }
        private void FindButton_Click(object sender, EventArgs e)
        {
            WordNote.Find(FindTextBox.ToString());//Built in Function To Find The Desired Word           
        }
        private void UndoButton_Click(object sender, EventArgs e)
        {
            WordNote.Undo();    //Built in Function To Undo The Work           
        }
        private void designToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Color Dialog Is Used Here To Change The BackGround Color Of The RichTextBox
            ColorDialog cd = new ColorDialog();//Object of The ColorDialog
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            cd.Color = WordNote.ForeColor;
            DialogResult result = cd.ShowDialog();
            if (result == DialogResult.OK)
            {
                WordNote.BackColor = cd.Color;              
            }       
        }       
    }

}

Tuesday, June 9, 2015

Visual Calculator in C# Using Classes




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 visual_calculator
{
    class Methods
    {
        public  int Factorial(int input)
        {
            int answer = 0;
            int count = 0;
            if (input > 0)
            {
                count = 1;
                while (count <= input)
                {
                    if (count == 1)
                    {
                        answer = 1;
                        count++;
                    }
                    else
                    {
                        answer = count * answer;
                        count++;
                    }
                }
            }
            else
            {
                MessageBox.Show("Please enter only a positive integer.");
            }

            return answer;
        }
        public  void toBin(int dec)
        {
            int count = 0;
            int[] bin = new int[100];

            while (dec > 0)
            {
                bin[count] = dec % 2;    //store Binary value in array bin
                count++;
                dec = dec / 2;  //for moving from unit to ten's or next
            }
            for (int j = count - 1; j >= 0; j--)//for loop for printing the array elements in reverse

                Console.Write(bin[j]);
        }
        //--------------------------------------------------------------------------------------------------------
        public  void toOct(int dec)
        {
            int count = 0;
            int[] oct = new int[100];

            while (dec > 0)
            {
                oct[count] = dec % 8;    //store octal in oct array
                count++;
                dec = dec / 8;           //for moving from unit to ten's or next
            }
            for (int j = count - 1; j >= 0; j--)//for loop for printing the array elements in reverse
            {
                Console.Write(oct[j]);
            }
        }

        //--------------------------------------------------------------------------------------------------------
        public  int toHex(int dec)
        {
            int count = 0;
            int[] hex = new int[100];
            while (dec > 0)
            {
                hex[count] = dec % 16; //store stuff in array hex
                count++;
                dec = dec / 16;
            }
            for (int j = count - 1; j >= 0; j--)    //for loop for printing the array elements in reverse
                if (hex[j] < 10)                //if array element is less than 10 then printing the array element
                {
                    Console.Write(hex[j]);
                }
                else
                    switch (hex[j])   //if array element is greater than 10 then replace 10 with A uptill 15 which is F
                    {
                        case 10:
                            Console.Write('A');
                            break;
                        case 11:
                            Console.Write('B');
                            break;
                        case 12:
                            Console.Write('C');
                            break;
                        case 13:
                            Console.Write('D');
                            break;
                        case 14:
                            Console.Write('E');
                            break;
                        case 15:
                            Console.Write('F');
                            break;
                    }
            return hex[count];
        }
        //------------------------------------------------------------------------------
        public  int BintoDecimal(int des)
        {

            int d;
            double num = 0;
            for (int i = 0; des != 0; i++)
            {
                d = des % 10;
                num += (d) * (Math.Pow(2, i));  //Multiplying number with power of 2 increasing from left to right
                des = des / 10;
            }
            return Convert.ToInt32(num);
        }

        public  void BintoOct(int oct)
        {
            toOct(oct);
        }
        public  void BintoHexa(int oct)
        {
            toHex(oct);
        }
        //-------------------------------------------------------------------------------
        public  int OcttoDes(int des)
        {
            int d;
            double num = 0;
            for (int i = 0; des != 0; i++)
            {
                d = des % 10;
                num += d * (Math.Pow(8, i)); //Multiplying number with power of 8 increasing from left to right
                des = des / 10;
            }
            return Convert.ToInt32(num);
        }
       
        //-------------------------------------------------------------------------------
    }
}

Source code:form1.cs
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 visual_calculator
{
    public partial class CalculateForm : Form
    {
        int input1,sum=0,sub=0,pro=0,div=0,fact=0,sin=0,cos=0,tan=0,cosec=0,sec=0,cot=0,des,log,oct,pow,tenpow,bin,squ,ans;
        int destohex,mod;
        string hexValue;
        double answer,trig = 0;
        Methods m = new Methods();
        public CalculateForm()
        {
            InitializeComponent();
        }      
      
        private void SqrtButton_Click(object sender, EventArgs e)
        {
            double a=double.Parse(textBox3.Text);
            textBox3.Text = Math.Sqrt(a).ToString();
        }

        private void ReciprocalButton_Click(object sender, EventArgs e)
        {
            float a = 0;
            a = float.Parse(textBox3.Text);
            a = 1 / a;
            textBox3.Text = a.ToString();
        }

        private void PowerButton_Click(object sender, EventArgs e)
        {
            pow = 1;
            input1 = int.Parse(textBox3.Text);
            textBox3.Text = "";           
        }
           private void TenPowButton_Click(object sender, EventArgs e)
        {
                tenpow = 1;
            input1 = int.Parse(textBox3.Text);
            textBox3.Text = "";              
        } 
        private void DivideButton_Click(object sender, EventArgs e)
        {
            div = 1;
            input1 = Convert.ToInt32(textBox3.Text);
            textBox3.Text = "";
        }

        private void MultiplyButton_Click(object sender, EventArgs e)
        {
            pro = 1;
            input1 = Convert.ToInt32(textBox3.Text);
        }

        private void SubtractButton_Click(object sender, EventArgs e)
        {
            sub = 1;
            input1 = Convert.ToInt32(textBox3.Text);
            textBox3.Text = "";
       
            }

        private void AddButton_Click(object sender, EventArgs e)
        {
           
            sum = 1;
           input1= Convert.ToInt32( textBox3.Text); 
            textBox3.Text="";
        }
        private void FactButton_Click(object sender, EventArgs e)
        {
            fact = 1;
            input1 = Convert.ToInt32(textBox3.Text);
        }
        private void ModButton_Click(object sender, EventArgs e)
        {
            mod = 1;
            input1 = Convert.ToInt32(textBox3.Text);
            textBox3.Text = "";

        }
        private void ClearButton_Click(object sender, EventArgs e)
        {
            textBox3.Text = "";
            textBox3.Clear();
        }

        private void ModulasButton_Click(object sender, EventArgs e)
        {
            double a = 0;
            a = double.Parse(textBox3.Text) % double.Parse(textBox3.Text);
           textBox3.Text= a.ToString();
        }
        private void SinButton_Click(object sender, EventArgs e)
        {
            sin = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }     

       private void OneButton_Click(object sender, EventArgs e)
        {
            textBox3.Text +="1";
        }

        private void TwoButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "2";
        }

        private void ThreeButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "3";

        }

        private void button21_Click(object sender, EventArgs e)
        {
            textBox3.Text += "4";

        }

        private void button22_Click(object sender, EventArgs e)
        {
            textBox3.Text += "5";

        }

        private void button23_Click(object sender, EventArgs e)
        {
            textBox3.Text += "6";

        }

        private void button12_Click(object sender, EventArgs e)
        {
            textBox3.Text += "7"; 
        }

        private void button13_Click(object sender, EventArgs e)
        {
            textBox3.Text +="8";
        }

        private void button14_Click(object sender, EventArgs e)
        {
            textBox3.Text += "9";
        }

        private void ZeroButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "0";
        }

        private void AnsButton_Click(object sender, EventArgs e)
        {
        if (sum==1)
            {
                ans = input1 + Convert.ToInt32(textBox3.Text);
                textBox3.Text = ans.ToString();
               
            }
        else if(sub==1)
        {
             ans = input1 - Convert.ToInt32(textBox3.Text);
             textBox3.Text = ans.ToString();

        }
        else if (div == 1)
        {
            ans = input1 / Convert.ToInt32(textBox3.Text);
            textBox3.Text = ans.ToString();
        }
        else if (pro == 1)
        {
            ans = input1 * Convert.ToInt32(textBox3.Text);
            textBox3.Text = ans.ToString();
        }
        else if(mod==1)
        {
            ans = input1 % Convert.ToInt32(textBox3.Text);
            textBox3.Text = ans.ToString();
        }
        else if (fact == 1)
        {
            ans = m.Factorial(int.Parse(textBox3.Text));
            textBox3.Text = ans.ToString();
        }
        else if (pow == 1)
        {
            double a = Convert.ToDouble(input1);
            double b = Convert.ToDouble(textBox3.Text);
            answer= Math.Pow(a,b);
            textBox3.Text = answer.ToString();
        }
        else if(tenpow==1)
        {
            double a=Math.Pow(10,Convert.ToDouble(input1));
            textBox3.Text=a.ToString();
        }
        else if (sin == 1)
        {
            answer = Math.Sin(trig);
            textBox3.Text = answer.ToString();
        }
        else if (cos == 1)
        {
            answer = Math.Cos(trig);
            textBox3.Text = answer.ToString();
        }
        else if (tan == 1)
        {
            answer = Math.Tan(trig);
            textBox3.Text = answer.ToString();
        }
        else if (sec == 1)
        {
            answer = 1/Math.Cos(trig);
            textBox3.Text = answer.ToString();
        }
        else if (cosec == 1)
        {
            answer = 1 / Math.Sin(trig);
            textBox3.Text = answer.ToString();
        }
        else if (cot == 1)
        {
            answer = 1 / Math.Tan(trig);
            textBox3.Text = answer.ToString();
        }
        else if (des == 1)
        {
            textBox3.Text = ans.ToString();
        }
     
        else if (destohex == 1)
        {
            textBox3.Text = hexValue;
        }
        else if (oct == 1)
        {
            textBox3.Text = ans.ToString();
        }
        else if (bin == 1)
        {
            textBox3.Text = hexValue;
        }
        else if (squ == 1)
        {
            double a = Math.Pow(Convert.ToDouble(input1), 2);
            textBox3.Text = a.ToString();
        }
        else if (log == 1)
        {
            double a = Math.Log(trig);
            textBox3.Text = a.ToString();
        }
        }

        private void HexaRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            destohex = 1;
            input1 = int.Parse(textBox3.Text);
            hexValue = input1.ToString("X");
          

          }

        private void OctalRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            oct = 1;
            ans = Convert.ToInt32(textBox3.Text, 8);          
        }

        private void BinaryRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            bin = 1;
            input1 = int.Parse(textBox3.Text);
            hexValue=Convert.ToString(input1,2);
        }
        private void DecimalRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            des = 1;
            input1 = int.Parse(textBox3.Text);
            ans = m.BintoDecimal(input1);

        }

        private void AButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "A";
        }

        private void BButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "B";
        }

        private void CButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "C";
        }

        private void DButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "D";
        }

        private void EButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "E";
        }

        private void FButton_Click(object sender, EventArgs e)
        {
            textBox3.Text += "F";
        }

        private void BackspaceButton_Click(object sender, EventArgs e)
        {
          textBox3.Text = textBox3.Text.Remove(textBox3.Text.Length - 1, 1);
        }

        private void SquareButton_Click(object sender, EventArgs e)
        {
            squ = 1;
            input1 = Convert.ToInt32(textBox3.Text);
            textBox3.Text = "";
        }

        private void CosButton_Click(object sender, EventArgs e)
        {
            cos = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }

        private void TanButton_Click(object sender, EventArgs e)
        {
            tan = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }

        private void SecButton_Click(object sender, EventArgs e)
        {
            sec = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }

        private void CotanButton_Click(object sender, EventArgs e)
        {
            cot = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }

        private void CosecButton_Click(object sender, EventArgs e)
        {
            cosec = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }

        private void LogButton_Click(object sender, EventArgs e)
        {
            log = 1;
            trig = Convert.ToDouble(textBox3.Text);
        }
    }

}