-->

Monday, March 3, 2014

Subtraction assignment operator in c# programming

This is type of binary operator, which means it works with more than one operand. In c#, this can be understood from given code
int a=10,b=5;
a -=b;
Console.WriteLine(a);
In this preceding code, we get 5 as a result. It means subtract operand b from a. This types of expression is equivalent to a=a-b. Lets take an simple example with output

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 20;
            b -= a;
            Console.WriteLine(b);
         
            Console.ReadKey();

        }
    }
}

Code generate the following output

Subtraction assignment operator in c# programming

Date of weeks in C# programming

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Total weeks</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Total Weeks" 
            onclick="Button1_Click" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

// Code behind class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default6 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       //initialize the datetime class instance 
        DateTime currentdate = new DateTime();

        Label1.Text = "current date : " + currentdate.ToLongDateString() +"<br/>";

        Label1.Text += "Week Date ";
        Label1.Text += currentdate.DayOfWeek.ToString()+"<br/>";


        int dayOfWeek = (int)currentdate.DayOfWeek;

        Label1.Text += "Day of week ";
        Label1.Text += dayOfWeek; 
    }
}

Code generate the following output

Date of weeks in C# programming

Sunday, March 2, 2014

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List

The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows:
Polynomial:      3x3-4x2+2x-9
Linked List:

In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable.
Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also be traversed very easily to display the polynomial.







The above two linked lists represent the polynomials,3x3-4x2+2x-9 and 5x3-2x2+6x+3 respectively. If both the polynomials are added then the resulting linked will be:




The linked list pointer ROOT gives the representation for polynomial, 8x3-6x2+8x-6.

C Program to read and display a polynomial using linked list .

Operators in expression, C# programming

There are various types of operators, we use in expression. Where we use multiple arithmetic operator known as expression. Your arithmetic expression is
 d=a+b*c;
In this expression, we used three operator, such as assignment operator, arithmetic positive, and  arithmetic multiplication operator. Also we used four operands, such as a,b,c and d operands. So we use variety of operator for designing expression for user query. Some of operator we use, like
Mathematical operators are
+, -  :  Unary positive, negative
+ : Addition
- : Subtraction
* : Multiplication
/ : Division
% : reminder

If you use more than one operator in any expression, evaluate expression according to operator precedence also evaluate expression left to right according to precedence rule.
Now, just take an simple precedence of mathematical operator are:

Unary + and - (I)

* and /  (II)

+ and - (III)

In above mentioned expression ( d=a+b*c ), first calculate multiplication between operand b and c, after that result of the multiplication will be added with operand a. If you want to override the default precedence, use parentheses around the portion of the expression that is to be evaluated first. In some other expression, where we use string datatype then we use + operator for string concatenation. So we can say that '+' operator is used in addition as well as string concatenation.

Saturday, March 1, 2014

How to Rename or Drop User-Defined Database in SQL Programming

Renaming a User-Defined Database

After creating a user-defined database in SQL server, programmer can rename a database whenever required. Only a system administrator or the database owner can rename a database. The sp_renamedb stored procedure is used to rename a database. The syntax of the sp_renamedb statement is:

Sp_renamedb old_database_name, new_database_name
Where

  • old_database_name is the current name of the database
  • new_database_name is the new name of the database 
For example, the following SQL query renames the Personnel database.
Sp_renamedb Personnel Personnel1

Dropping a User-Defined Database

Programmer can delete a database when it is no longer required. This causes all the database files and data to be deleted. Only the users with sysadmin role and the database owner have the permissions to delete a database. The syntax of the DROP DATABASE statement is:

DROP DATABASE database_name
Where
Database_name is the name of the database.

The following SQL query deletes the Employee database:
DROP DATABASE Employee

Programmer cannot delete a system-defined database. Programmer can rename or delete a database using the Object Explorer window by right-clicking the Databases folder and selecting the Rename or Delete option from the shortcut menu.
Create User-Defined Database 

Merging the ordered Singly Linked Lists in 'C'

The merging is over. The merged list can be traversed with the help of the external pointer ROOT. ROOT points to the node with information 1. Node with information 1 points to the node with information 10. Next node is the node with information 20. Similarly the nodes with information 23 and 25 are the next node. The node with information 25 is the last node of the merged list.

Algorithm to merge two ordered linked lists:

MERGEOLLS(ROOT1,ROOT2)
IfROOT-->INFO<ROOT2-->INFO Then:
  ROOT<--ROOT1;  ROOT1<--ROOT1-->LINK
Else:
  ROOT<--ROOT2;  ROOT2<--ROOT2-->LINK
[End of If]
PTR<--ROOT
Repeat While ROOT1< >NULL AND ROOT2< >NULL
  If ROOT1-->INFO<ROOT2-->INFO Then:
      PTR-->LINK<--ROOT1
      PTR<--PTR-->LINK
 Else:
      PTR-->LINK<--ROOT2
      PTR<--PTR-->LINK
      ROOT2<--ROOT2-->LINK
  [End of If]
[End of While]
If ROOT1 = NULL Then:
  PTR<--ROOT2
[End of If]
If ROOT2 = NULL Then:
   PTR<--ROOT1
[End of If]
Exit.

Increment operator in c# programming

Those operator, which is used for increment by one in any value known as increment operator. These are two types.

  1. Pre-increment operator
  2. Post-increment operator 
In pre-increment operator appear before its operand, such as ++a. Here "a" is a operand and ++ is the increment operator. In this case, value of the operand(a) will be incremented by one "after" it has been incremented.

In post-increment operator appear after its operand, such as a++. Similarly again, "a" is a operand and ++ is the increment operator.In this case, value of the operand(a) will be incremented by one "before" it has been incremented.

Lets take an simple example of both pre and post increment
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

            double a;
            a = 1.5;
            Console.WriteLine(++a);
            a = 1.5;
            Console.WriteLine(a++);
            Console.WriteLine(a);

            Console.ReadKey();

        }    

    }

}

Code generate the following output

Increment operator in c# programming

In this example, variable a hold 1.5 double number. When compiler compile third line of statement, which is 
Console.WriteLine(++a). Pre-increment the value by one according to above definition. In forth line of statement again variable a replace with 1.5 double number. According to post-increment, first print same value of variable a (according to line-5) that is 1.5 , after that value has been incremented by one (according to line-6) that is 2.5.

Increment operators in expression

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

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

            int a = 7;
            Console.WriteLine(++a * a++ + a++ * ++a);
            Console.ReadKey();

        }      

    }
}

Code generate the following output

Increment operator in c# programming
In this example, compiler first check operator precedence, here multiply sign take high precedence than addition sign. Also expression evaluate left to right, so first variable a is pre-incremented (value of a=8) also multiply with post-increment variable( a=8). So the result of first half is 64. In the next half, the value of variable a is post-incremented ( value of a=9) also multiply with pre-incremented (a=11 according to above definition). So the result of second half is 99. Now add both result, 64+99 is 163.
© Copyright 2013 Computer Programming | All Right Reserved