ODD One out Quiz

Friday, 1 August 2014

To Format SD card Partitions

How to format SD card partitions by using Command Prompt.

try this commands which are written on the image in command prompt as Administrator.

Be sure to select the right disk number, you don't want to accidentally clean out one of your hard drives.


Saturday, 21 June 2014

Program to Convert a number to Word In C

Program to Convert a number to word in C
Source Code in C:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
char old[70];
char ne[70];
char a[10][10]={"one ","two ","three ","four ","five ","six ","seven ","eight ","nine "};
char b[10][10]={"eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","ninteen "};
char c[10][10]={"ten ","twenty ","thirty ","fourty ","fifty ","sixty ","seventy ","eighty ","ninty "};
char d[4][10]={"hundred ","thousand ","lac ","crore "};
void func1(int);
void main()
{
 int value;
 long int r,num,x,i=1;
 unsigned long int number,n1,rev=0;
 int digit;
  while(1)
  {
  clrscr();
printf("*******To illustrate the concept of Convert a number to   word********");
  printf("\n\n1. To convert into a number into its notations like 'one thousand'");
  printf("\n\n2. To convert into a number into its in English Notaton like'One four six three'");
  printf("\n\n3. Exit option");
  printf("\n \n Enter Your Choice");
  scanf("%d",&value);
   switch(value)
   {
    case 1:
    {
    clrscr();
    strcpy(old," ");
    printf("Enter the number between 0 to 999999999 \n");
    scanf("%ld",&num);
    if(num>999999999)
    {
    exit(1);
    }
    else
    {
    x=num;
    r=x%100;
    x=x/100;
    if(r>0)
    func1(r);
    r=x%10;
    strcpy(old,ne);
    strcpy(ne,"");
     if(r>0)
       {
       strcpy(ne,a[r-1]);
       strcat(ne,d[0]);
       }
    strcat(ne,old);
    x=x/10;
    while(x>0)
    {
     strcpy(old,"");
     strcpy(old,ne);
     strcpy(ne,"");
     r=x%100;
      if(r<=0)
      i++;
      else
      {
      func1(r);
      strcat(ne,d[i++]);//hundred,lac,crore
      }
     strcat(ne,old);
     x=x/100;
    }
    printf("Your number is (in figure) =%ld \n",num);
    printf("\nResult is(In Words)= %s",strupr(ne));
    getch();
    }
          }
    break;
   case 2:
   {
    clrscr();
    printf("\n Enter a positive integer\n");
    scanf("%lu",&number);
    if(number==0)
    {
    printf("\n Zero");
    getch();
    return;
    }
    n1=number;
    while(n1!=0)
    {
    digit=n1%10;
    rev=(rev*10)+digit;
    n1=n1/10;
    }
    printf("Your number is (in figure) =%lu\n",number);
    printf("Your number is (in Word) = ");
    while(rev!=0)
    {
     digit=rev%10;
     switch(digit)
     {
     case 0:
     printf(" Zero");
     break;
     case 1:
     printf(" One");
     break;
     case 2:
     printf(" Two");
     break;
     case 3:
     printf(" Three");
     break;
     case 4:
     printf(" Four");
     break;
     case 5:
     printf(" Five");
     break;
     case 6:
     printf(" Six");
     break;
     case 7:
     printf(" Seven");
     break;
     case 8:
     printf(" Eight");
     break;
     case 9:
     printf(" Nine");
     break;
     }
     rev=rev/10;
    }
   getch();
   }
   break;
   case 3:
   exit(1);
   break;
   }
 }
getch();
}
void func1(int r)
{
 if(r<10)
 strcpy(ne,a[r-1]);        //last digit
 else if((r%10==0))
 {
 strcpy(ne,c[(r/10)-1]);
 //printf("%s \n",c[(r/10)-1]);      //fifty
 }
 else if(r>10&&r<20)
 strcpy(ne,b[r-11]);                   //fourteen
 else
 {
 strcpy(ne,c[(r/10)-1]);
 strcat(ne,a[(r%10)-1]);   //sixty nine
 }
}

This program gets a number from the user and converts it into according to user choice option. If the user chose 1 option, it converts the number in words like ‘crores thousand or lacs’. . If the user chose 2 option, it converts the number in words like that ‘one four three two nine’.


Wednesday, 7 May 2014

Delegate Example in C#

Code of Delegate Example in C# in windows based application


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 DelegateExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        delegate double process(double a, double b);

        static double Multiply(double a, double b)
    {
        return a * b;
    }
        static double divide(double a, double b)
        {
            return a / b;
        }

       
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(textBox1.Text);
            double b = Convert.ToDouble(textBox2.Text);
            process obj;
            if (comboBox1.SelectedIndex == 0)
            {
                obj = new process(Multiply);
            }
            else
            {
                obj = new process(divide);
            }
            MessageBox.Show("Result :" + Convert.ToString(obj(a, b)));
        }

    }

}

Program to find the sum of two 2D matrices.. Each element of the matrix to be entered by the user using textbox.

Program to find the sum of two 2D matrices.. Each element of the matrix to be entered by the user using textbox.

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 Two_D_Array
{
public partial class Form1 : Form
{
int row, col;// size of first array
int row1, col1; // size of second array
int i = 0, j = 0;
int k = 0, l = 0;
int m = 0, n = 0;
int[,] a;
int[,] a1;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void label4_Click(object sender, EventArgs e)
{

}

private void button4_Click(object sender, EventArgs e)
{
row1 = Convert.ToInt32(textBox7.Text);
col1 = Convert.ToInt32(textBox6.Text);
a1 = new int[row1, col1];
}

private void button3_Click(object sender, EventArgs e)
{
try
{

if (m < row1)
{
if (n < col1)
{
a1[m, n] = Convert.ToInt32(textBox5.Text);
textBox5.Text = "";
listBox2.Items.Add(a1[m, n]);
textBox8.Text += a1[m, n].ToString() + "\t";
n++;

}
else
{
m++;
n = 0;
textBox8.Text += "\n";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void button2_Click_1(object sender, EventArgs e)
{
try
{
if (i < row)
{
if (j < col)
{
a[i, j] = Convert.ToInt32(textBox3.Text);
textBox3.Text = "";
listBox1.Items.Add(a[i, j]);
textBox4.Text += a[i, j].ToString() + "\t";
j++;

}
else
{
i++;
j = 0;
textBox4.Text += "\n";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void button1_Click_1(object sender, EventArgs e)
{
row = Convert.ToInt32(textBox1.Text);
col = Convert.ToInt32(textBox2.Text);
a = new int[row, col];
//MessageBox.Show("size is set");

}

private void textBox9_TextChanged(object sender, EventArgs e)
{

}

private void button5_Click(object sender, EventArgs e)
{
try
{
int[,] sum = new int[row, col];
if (row == row1 && col == col1)
{
if (k < row)
{
if (l < col)
{

sum[k, l] = a[k, l] + a1[k, l];
textBox9.Text += sum[k, l].ToString() + "\t";
l++;

}
else
{
k++;
l = 0;
textBox9.Text += "\n";
}
}
}

}

catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

}

}
}


Login Database Connectivity

Login Database Connectivity
1)      Add three labels and add two textboxes in windows form
2)      Name the first label as “Enter username” and second label as “Enter password”
3)      Add two buttons. First button named as “Add record ” and second button named as “Connect Database”.



4)      Now double click on connect database button and it will go to source code file.
5)      Now then add two namespaces on the top of code.
using System.Data.Sql;
using System.Data.SqlClient;

6)  Then write the code in Connect database button click

7)  try
8)              {
9)   
10)                 conn.ConnectionString = "Data Source=(localdb)\\Projects;Initial Catalog=Login;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False";
11)                 conn.Open();
12)  
13)                 if (conn.State == ConnectionState.Open)
14)                 {
15)  
16)                     label3.Text = label3.Text + "\r\n" + "SQL Server Connection Successful.";
17)                     
18)                 }
19)                 else
20)                 {
21)                     label3.Text = label3.Text + "\r\n" + "Error in SQL Connection!";
22)  
23)                 }
24)             }
25)             catch (Exception te)
26)             {
27)                 label3.Text = label3.Text + "\r\n" + te.ToString();
28)  
29)  
30)             }



After this you can run the program and check whether sql server connection is successful created or not.
Then click connect database button.
See the picture

To add or Insert a record in database. Double click on add record button and write the code

try
            {

                string sSQL = "INSERT INTO record (username,password)VALUES (@user,@pass)";
                SqlCommand objCmd = new SqlCommand(sSQL, conn);


              
                objCmd.Parameters.Add("@user", SqlDbType.VarChar, 50);
                objCmd.Parameters.Add("@pass", SqlDbType.VarChar, 50);

               
                objCmd.Parameters["@user"].Value = textBox1.Text;
                objCmd.Parameters["@pass"].Value = textBox2.Text;
               
                objCmd.ExecuteNonQuery();

                              MessageBox.Show("Record Added");

               
            }

            catch (Exception ex)
            {
                label3.Text = label3.Text + "\r\n" + ex.ToString();
            }

Then add datagridview control in windows form...



Add one button named as “show record” and then double click on it and write the following code.

try
            {

                string sSQL = "select username,password from record";

                SqlCommand objCmd = new SqlCommand(sSQL, conn);

                SqlDataAdapter dadapt = new SqlDataAdapter(objCmd);

                DataSet daset = new DataSet();

                dadapt.Fill(daset, "record");
                dataGridView1.DataSource = daset.Tables["record"];
                dataGridView1.Refresh();
               
            }

            catch (Exception ex)
            {
                label3.Text = label3.Text + "\r\n" + ex.ToString();
            }

Now run the program..
Step1..Click on connect database button
Step2: then click on show record button..

Outputwindow:






Now add one button named as search record and double click on it and write the following code:

try
            {

                string sSQL = "select * from record where username= @user";


                SqlCommand objCmd = new SqlCommand(sSQL, conn);

                objCmd.Parameters.Add("@user", SqlDbType.VarChar,50);
                objCmd.Parameters["@user"].Value = textBox1.Text;



                SqlDataAdapter dadapt = new SqlDataAdapter(objCmd);
                DataSet daset = new DataSet();
                dadapt.Fill(daset, "record");

                if (daset.Tables[0].Rows.Count > 0)
                {
                    dataGridView1.DataSource = daset.Tables["record"];
                    dataGridView1.Refresh();
                    MessageBox.Show("Record Found");
               

                }
                else
                {
                    MessageBox.Show("Record Not Found");
                }


            }

            catch (Exception ex)
            {
                label3.Text = label3.Text + "\r\n" + ex.ToString();
            }

 And then add one button named as update record and double click on it and write the following code:

try
            {

                string sSQL = "update record set password=@pass where username=@user";

                SqlCommand objCmd = new SqlCommand(sSQL, conn);
               
                objCmd.Parameters.Add("@user", SqlDbType.VarChar, 50);
               
                objCmd.Parameters.Add("@pass", SqlDbType.VarChar, 50);
               

                objCmd.Parameters["@user"].Value = textBox1.Text;
                objCmd.Parameters["@pass"].Value = textBox2.Text;
              

                objCmd.ExecuteNonQuery();

                MessageBox.Show("Record Updated");
               
            }
            catch (Exception ex)
            {
                label3.Text = label3.Text + "\r\n" + ex.ToString();
            }

And then add one button named as delete record and and double click on it and write the following code:

try
            {

                string sSQL = "delete from record where username=@user";

                SqlCommand objCmd = new SqlCommand(sSQL, conn);
                objCmd.Parameters.Add("@user", SqlDbType.VarChar, 50);

                objCmd.Parameters["@user"].Value = textBox1.Text;


                objCmd.ExecuteNonQuery();

                MessageBox.Show("Record Deleted");


            }
            catch (Exception ex)
            {
                label3.Text = label3.Text + "\r\n" + ex.ToString();
            }

Final Output:-