-->

Wednesday, October 29, 2014

Design an algorithm to compare two numbers

Input : Two numbers that are to be compared
Output : Messages of comparison

COMPARE (N1, N2)
[N1 and N2 are the numbers]
If(N1==N2) Then :
Write : 'Both the numbers are equal'
Else:
If (N1<N2) Then:
Write : 'First number is smaller then second number'
Else:
Write : 'First number is bigger number than second number'
[End of If]
[End of If]
Exit


Design an algorithm to find the sum, difference and product of two numbers

Input : From the problem definition the input to the algorithm will be two numbers.
NOTE : The identification of the data type of the input is not necessary like int or float.
Output : The result sum, difference and product are to be displayed.

ARTH_OPNS(N1,N2)
[N1 AND N2 are the numbers]
RES <-- N1+N2
Write: "The Sum is'. RES
RES <-- N1-N2
Write: ' The Difference is', RES
RES <-- N1* N2
Write: 'The Product is', RES
Exit

Design an algorithm to search a number using linear search technique

Input : A list (array) of number, number of elements in the list and key to search.
Output : Returns 1 if the key is found otherwise returns 0.

LSEARCH(LIST, N, KEY)
[LIST is an array of numbers, N is the size of the array and KEY is the number to search]
Repeat For I=0,1,2,3.....N-1   [Assuming that array index start from 0]
If (KEY == LIST[I] ) Then:
Return 1
[End of If]
Return 0
Exit.

How to Implement User Defined Function in SQL

Similar to the stored procedures, you can also create functions to store a set of T-SQL statements permanently. These functions are also referred to as user-defined functions (UDFs). A UDF is a database object that contains a set of T-SQL statements, accepts parameters, performs an action, and returns the result of that action as a value. The return value can either be a single scalar value or a result set.

UDFs have a limited scope as compared to stored procedures. You can create functions in situations when you need to implement a programming logic that does not involve any permanent changes to the database objects outside the function. For example, you cannot modify a database table from a function.

UDFs are of different types: scalar functions and table-valued function. As a database developer, it is important for you to learn to create and manage different types of UDFs.

Creating UDFs

A UDF contains the following components:

  • Function name with optional schema/owner name
  • Input parameter name and data type
  • Options applicable to the input parameter
  • Return parameter data type and optional name
  • Options applicable to the return parameter
  • One or more T-SQL statements

To create a function, you can use th CREATE FUNCTION statement. The syntax of the CREATE FUNCTION statement is:

CREATE FUNCTION [ schema_name. ] function_name
( [ { @parameter_name [AS ] [ type_schema_name. ]
Parameter_data_type] }
[ = default ] }
[, …n ]
]
)
RETURNS return_data_type
[WITH <function_option> [ , . . .n ] ]
[ AS ]
BEGIN
Function_body
RETURN expression
END
[;]
Where,

  • Schema_name is the name of the schema to which the UDF belongs.
  • Function_name is the name of the UDF. Function names must comply with the rules for identifiers and must be unique within the database and to its schema.
  • @parameter_name is a parameter in the UDF. One or more parameters can be declared.
  • [type_schema_name.] parameter_data_type is the data type of the parameter, and optionally the schema to which it belongs.
  • [=default ] is a default value for the parameter.
  • Return_data_type is the return value of a scalar user-defined function.


Tuesday, October 14, 2014

Calling a Procedure from another Procedure: SQL

At times, you might need to use the values returned by a procedure in another procedure. For this, you can execute or call one procedure from within another procedure.

A procedure that calls or executes another procedure is known as the calling procedure, and the procedure that is called or executed by the calling procedure is termed as the called procedure. You can also execute a procedure from another procedure if you need to use the functionality provide by one into another.

Consider the previous example where the prcGetEmployeeDetail procedure returns the employee details for a given employee ID. You can create the prcDisplayEmployeeStatus procedure, which accepts the employee ID of an employee as input and displays the department name and shift ID where the employee is working along with the manager ID and the title employee. To perform this task, you need to call the prcGetEmployeeDetail procedure from the prcDisplayEmployeeStatus procedure, as shown in the following statement:

CREATE PROCEDURE prcDisplayEmployeeStatus @EmpId int
AS
BEGIN
DECLARE @DepName char (50)
DECLARE @ShiftId int
DECLARE @ReturnValue int
EXEC @ReturnValue = prcGetEmployeeDetail @EmpId,
@ DepName OUTPUT,
@ ShiftId OUTPUT
IF (@ReturnValue = 0)
BEGIN
PRINT ‘The details of an employee with ID: ‘ + convert (char (10), @EmpId)
PRINT ‘shift ID: ‘ + convert ( char (1), @shiftId)
SELECT ManagerID, Title FROM HumanResources.Employee
WHERE EmployeeID = @EmpID
END
ELSE
PRINT ‘No records found for the given employee’
END

To execute the preceding code, you need to execute the following statement:
EXEC prcDisplayEmployeeStatus 2

SQL Server provides a function, @@ROWCOUNT, which return the number of rows affected by the last statement. You can use this statement in the IF construct to check the result of the last statement that executed.

Monday, October 13, 2014

How to Return values from Stored Procedure: SQL

Similar to providing input values to the procedures at run time, you can also return values as output from the procedures. The values can be returned to the calling application through output parameters. To specify a parameter as the output parameter, you can use the OUTPUT keyword.

The OUTPUT keyword has to be specified in both the CREATE PROCEDURE and the EXECUTE statement. If the OUTPUT keyword is omitted, the procedure will be executed but will not return any value.

The syntax of the declaring an output parameter using the OUTPUT keyword is:

CREATE PROCEDURE procedure_name
[
{ @parameter data_type} [OUTPUT]
]
AS
Sql_statement […n]


  • @parameter data_type [OUTPUT] allows the stored procedure to pass a data value to the calling procedure. If the OUTPUT keyword is not used, then the parameter is treated as an input parameter.

You can also return values from the stored procedure by using the RETURN statement. The RETURN statement allows the stored procedure to return only an integer value to the calling application. The syntax of the RETURN statement is:

RETURN value
Where,

  • Value is any integer. If a value is not specified, then the stored procedure returns a default value of 0 to specify failure and 1 to specify success.

Consider an example. You need to display the details of an employee whose employee ID has been provided as an input. For this, you need to create a procedure prcGetEmployeeDetail thet will accept employee ID as input and will return the department name and ID of the shift in which the employee works. You can create the procedure, as shown in the following statement:

CREATE PROCEDURE prcGetEmployeeDetail @EmpID int, @DepName char (50) OUTPUT, @ShiftID int OUTPUT
AS
BEGIN
IF EXISTS (SELECT * FROM HumanResources.Employee WHERE EmployeeID = @EmpID)
BEGIN
SELECT @DepName = d. Name, @Shiftid = h.ShiftID
FROM HumanResourcess.Department d JOIN
HumanResources.EmployeeDepartmentHistory h
ON d.DepartID = h.DepartmentID
WHERE EmployeeID = @EmpId AND h.Enddate IS NULL RETURN 0
END
ELSE
RETURN 1
END

The preceding procedure accepts the employee ID as an input parameter and returns the department name and shift ID as output parameters. The procedure first checks the existence of the given employee ID. Id it exists, the procedure returns and integer value 0 along with the required details.

Sunday, October 12, 2014

How to Create Parameterized Stored Procedure: SQL

At times, you need to execute a procedure for different values of a variable that are provided at run time. For this, you can create a parameterized stored procedure. Parameters are used to pass values to the stored procedure during run time. These values can be passed by using standard variables.

The parameter that passes the values is defined as input parameter. A stored procedure has the capability of using a maximum of 2100 parameters. Each parameter has a name, data type, direction, and a default value.

The following example creates a stored procedure displaying the employee ID, the login ID, and title of the employees that have the same title provided as an input during

Execution:

CREATE PROC prcListEmployee @title char (50)
AS
BEGIN
PRINT ‘List of Employees’
SELECT EmployeeID, LoginID, Title
FROM HumanResources.Employee
WHERE Title = @title
END

Execute the stored procedure, prcListEmployee, by using the following statement:

EXECUTE prcListEmployee ‘Tool Designer’

While executing the stored procedures, you can also provide the values for the parameters by explicity specifying the name and value of the parameter. In the previous example, you can also pass the parameter value by using the name of variable, as shown in the following SQL statement:

EXECUTE prcListEmployee @title = ‘Tool Designer’

Friday, October 10, 2014

Guidelines to Create and Execute Stored Procedure: SQL

To create stored procedure database developer have to keep some points in mind. The following points need to be considered before creating a stored procedure:

  • You cannot combine the CREATE PROCEDURE statement with other SQL statements in a single batch.
  • You must have the CREATE PROCEDURE permission to create a procedure in the database and the ALTER permission on the schema, where the procedure is being created.
  • You can create a stored procedure only in the current database.
  • After creating a stored procedure, you can execute the procedure. You can also alter the procedure definition or drop it, if not required.

Executing a Stored Procedure

A procedure can be executed by using the EXEC PROCEDURE statement. The syntax of the EXEC PROCEDURE statement is:

EXEC | EXECUTE PROCEDURE proc_name AS [ { LOGIN|USER} = ‘name’]
Where,

  • Proc_name, is the name of the procedure you need to execute.
  • LOGIN|USER specifies the name of the login of another user on the same database server or another user in the same database that you need to impersonate. While executing a procedure you can impersonate the rights of another user or ligin to execute the procedure. This allows a user who does not have permission to execute a procedure to execute it using the permissions assigned to other users.

Consider an example. Robert has created a stored procedure named DispEmpDetail that displays the details of the employees. Kim needs to execute the procedure but does not have the execution rights. In such a case, Kim can use the rights of Robert to execute. For this, Kim needs to impersonate Robert.

You can execute the stored procedure, prcDept, as shown in the following statement:
EXEC PROCEDURE prcDept

Altering Stored Procedure

A stored procedure can be modified by using the ALTER PROCEDURE statement. The syntax of the ALTER PROCEDURE statement is:

ALTER PROCEDURE proc_name

You can alter the stored procedure, prcDept, as followis:

ALTER PROCEDURE prcDept
AS
BEGIN
SELECT DepartmentID, Name FROM HumanResources.Department
END
In the preceding code, the DepartmentID attribute will be displayed along with the department name.

Dropping a Stored Procedure

You can drop a stored procedure from the database by using the DROP PROCEDURE statement. The syntax of the DROP PROCEDURE statement is:

DROP PROCEDURE proc_name

You cannot retrieve a procedure once it is dropped. You can drop the prcDept stored procedure by using the following statement:

DROP PROCEDURE prcDept

Characteristics of Programming : C Language

Now, let us see “What is programming? What are the characteristics of good programming?”

Definition: The art of writing or designing the programs to provide a solution to the well-defined problem is called programming. As the saying goes ‘practice makes a man perfect’, developing such an art requires thorough practice. The following 10 characteristics if followed in a proper way will improve the quality of programming :

Characteristics of good Programming:
  1. Accurate
  2. Efficient
  3. Maintainable
  4. Portable
  5. Readable
  6. Reliable
  7. Robust
  8. Usable
  9. Documentation
  10. Indentation

Now, let us see, “the characteristics of programming” in detail.

Accurate: The programming of a program is based on a certain problem. The problem must be pie-defined clearly with specification of requirements. It is expected from the programmer to design a program that strictly follows these requirements. So, the designed program must be accurate to perform the specified task. Such characteristic of programming is referred ‘accurate’.

Efficient: Every program designed by programming utilizes the resources of the computer system. It is expected from the programming that the designed program utilizes these resources in an efficient manner. It means the program must not spend much time or over use the processor in executing its coded instructions. Such characteristic of the programming is referred ‘efficient’.

Maintainable: When proper structuring method is used in programming, the designed program can be made maintainable. Here maintainable means the ability to change as per the new needs. With very little modification a program should work for the new needs. Such characteristic of programming is referred ‘maintainable”.

Portable: It is expected from the designed program that it can be carried to any platform to solve the task. If the programming is done keeping many systems rather than one system in mind the designed programs are portable. Once the program is portable, it can be easily transferred from one machine to an other. Such characteristic of programming is referred ‘portable’.

Readable: The program designed by the programmer must be self readable as he is the first reader. Generally the designed program is also read by co-programmers or others. So, the designed program must contain proper comments to explain the coded instructions. This commenting will help in understanding and reading the program. Such characteristic of programming is referred ‘readable’.

Reliable: The designed program must perform as per the need all the time. It should also produce the intended results for any sort of inputs. In case of improper inputs, it should stop only after displaying proper error messages. These will indicate the cause of termination of the program. Such programs are created with the ‘reliable’ characteristic of the programming.

Robust: The designed program is expected to continue with its functionality even at the unexpected errors. It is the art of programming that takes care of all the possible errors before com¬pleting the design. Such programs keep on doing their work even at worst situations. Such characteristic of programming is referred ‘robust’.

Usable: The designed program must be easy to use. It must be designed with proper interactive messages so that the user can easily get accustomed to it. Proper thinking in interface design will prove its worthiness. The documentation of the program must be prepared in good format to train the users. Such characteristic of the programming is referred ‘usable’.

Documentation: The usage of comments or remarks to explain the coded instructions and the modules of the program is called documenting the program. Such documented program will also help in providing other characteristic of the programming. The comments will help to find the errors as well as to rectify them. When the program is lengthy one proper documentation will properly connect the components of the program. It improves the readability as well as usability of the program. Such characteristic of programming is referred ‘documentation’.

Indentation: The coded instructions of the designed program must properly match with beginning and ending of the structures or compound statements. Especially in case of C language, the compiler understands the code even if it is not properly indented. The indentation is mainly required for the users or programmers not for the compiler. The indentation improves the clarity of the program as well as its understanding. It will also help in debugging that is to remove the errors. Such characteristic of the programming is referred 'indentation'.

Wednesday, October 8, 2014

Life Cycle of applet

In the previous article, we have already learned about basics of applet.

Life Cycle of applet

1. init() : init method is used to initialize the applet. Before doing anything, must to initialized, so same thing with the applet. Like, in the games.
Before play any games, must to initialized all the  drivers in the system, which is necessary for the games. In the applet, init method is invoked only once, also that method invoked after param tag, which is inside in <applet></applet> tag.

2. start() : This is invoked after the initialization completed. It is used to start the applet, also automatic start. When user navigate to the web page, if
web page contain applet code then it start automatically also start when user moves from other web pages.

3. paint () : This method is invoked just after start() method. Actually only this method is responsible to design the applet, also responsible for repaint the browser, if applet is stooped. It has contain graphics argument as a parameter, through Graphics class we can design any graphics in the applet like rectangle, oval etc. Graphics class inherit from java.awt class.
4. stop() : This method is invoked, just after when the user moves to other browser tab from current applet tab.

5. destroy() : This method is invoked only that time when user close the browser. You can say, opened web page contain applet code , on that time applet is running
properly but in case if user close the browser, applet instance is automatically deleted from the page and destroy method is called automatically.

Example of Applet

The following is a simple applet named HelloWorld.java

import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Hello World", 30, 50);
}
}

The first line of code define, imports some packages, which is used for design the applet. Here are two class that is applet and awt. In the second line of code, we have a class "HelloWorld" which is inherited from Applet class. This Applet class inside in java.applet.* package. Through the Graphics class, we can design new object in the applet. This class inherited from java.awt.*. In this example, we have to draw a string with height and width argument(width=30, height=50).
With the help of applet tag, we will show the output in any browser, which support applet. Applet tag is:
  <applet code="HelloWorld.class" width=50 height=60></applet>

This tells the viewer or browser to load the applet whose compiled code is in HelloWorld.class (in the same directory as the current HTML document), and to set the initial size of the applet to 50 pixels wide and 60 pixels high.

Monday, October 6, 2014

Basics of applet

Applet is a small java program that run in browser, but JVM is required for run applet in browser. Basically applet is used where user want to put some dynamic content into html page.
There are some features and advantages of Applet

Features:


  1. It is a java class file, which is inherit from java.applet.Applet class.
  2. A applet class file don't take main() method for entry point.
  3. Applet codes are embedded in HTML page
  4. For run the applet code in browser, must to install JVM in the client machine
  5. During the execution of applet code in browser, code first to download in the client machine.

Advantages:


  1. Very less response time because Applet designed for client machine. If applet is used for server machine then server take more time to execute applet code.
  2. More secure
  3. Platform independent, so it can run on any platform that is windows, Linux, UNIX, etc.
  4. Use for dynamic application


Disadvantages of applet


  1. For run to its code in browser, must to installed JVM plugin

Thursday, October 2, 2014

Forms of JavaBeans

In the previous article, we have already learn about basic concept of java bean, today i am talking about java beans forms.
Java Beans can appear in two forms:
  1. Visual
  2. Non visual.
Visual is more common, as the majority of Java Beans are extensions of Swing or AWT components. Some Beans may be simple GUI elements such as a specialized button or slider. Others may be sophisticated visual software components such as a diagram component offering different ways to present the bounded data. They all have in common that they can be customized at design time in a builder tool.

Java Beans can also be non visual yet still be customizable using a builder-tool. They do not have to be derived from a specific class or interface, it is recommended that they implement the Serializable interface. In respect of the source code there is no real difference noticeable between a Java Bean and a “normal” Java class. Basically what differs the source code of a “normal” class from a Java Bean is that the latter adheres to the Java Beans API specification in terms of how it is developed. Only the strict adherence to this specification ensures that builder tools can assist a developer to work with Java Beans. For many solutions you can either develop a conventional Java class where you have to write your own code for setting its properties or you can build a Java Bean which allows you To set the properties through the builder tool. Eventually both methods result in code just that in the latter case the builder tool creates the code automatically in the background according to your selection.

Introduction of JavaBeans

A Java Bean is a software component that has been designed to be reusable in a variety of different environments. There is no restriction on the capability of a Bean. It may perform a simple function, such as checking spelling of a document, or a complex function, such as forecasting the performance of a stock portfolio. A Bean may be visible to an end user. One example of this is a button on a graphical user interface. A Mean may also be invisible to a user. Software to decode a stream of multimedia information in real time is an example of this type of building block. A Bean may be designed to work autonomously on a user’s workstation or to work in cooperation with a set of other distributed components. Software to generate a pie chart from a set of data points is an example of a Bean that can execute locally.

A Bean that provides real-time price information from a stock or commodities exchange would need to work in cooperation with other distributed software to obtain its data.

Java Beans components, or beans, are reusable software components that follow simple naming and design conventions so they present a standard interface to other beans, programs, and tools. In the next video tutorial i will learn about forms of java beans.

Wednesday, October 1, 2014

File types, Text and Binary in C

As discussed earlier the C language provides flexibility for the programmers to write file handling programs to store and process data. Such data files contain the data effectively in two formats. So, on the basis of the format structure of the files are of two types, Text File and Binary File.

Text File

In a text file a stream of characters are stored sequentially without any formatting. So, it is very simple to handle but direct access is not possible because any value or character is not stored after fixed number of bytes. Even though the numbers are stored in the form of characters only and the record length is not fixed if the records are stored. Again the records are also stored in the character format of the individual fields.

Similarly, since text files only process characters, generally they can only read or write data one character at a time. But the flexible C Language provides file handling functions to read and write formatted data and lines of text in a text file. But these functions again basically process data one character at a time. The normal functions used to handle the text file are getc(),fgetc(),fgets(), fputs(), putc(),fputc(),fscanf() and fprintf(). These functions transfer the character/s to and from the text file.

Depending on the requirements of the OS (Operating System), newline character may be converted to or from carriage-return/linefeed combination depending on the data is being written to, or read from, the file. Other character conversions may also occur to satisfy the storage requirements of the OS. These translations occur transparently and they occur while processing a text file.

Binary File

A binary file is not much different to a text file. It is also a collection of bytes. But the transfer of data is purely in the form of bytes as stored in main memory. Any number of bytes can be transferred at a time, in binary file. But the length of the bytes transferred is fixed. So, the binary files contain the data in fixed length record format. That is the reason they are more effective than text files. One important advantage of fixed length is that of accessing the record directly. The direct access is possible only in case of the binary files. It is basically because when a record is written to a binary file form the memory, the complete memory block is written. The number of bytes transferred is fixed. In the same manner when the data is read from the binary file the number of bytes is transferred to the memory at the provided address. The file handling functions provided to handle the binary files are fread() and fwrite(). This fixed length transfer is advantageous for direct access but the size of the file increases. So, in comparison to text files the binary files are advantageous in direct access at the cost of the size. Thus a selection of type of file is decided keeping the accessibility of data in mind.

A binary file is also referred to as a character stream but differ in the following ways:

• No special processing of the data occurs and each byte of data is transferred unprocessed to or from the disk.

• C Language places no constraints on the file, and it may be read from, or written to, in any manner.

Binary files can be either processed sequentially or randomly. The processing of a binary file using random access techniques involves moving the file pointer position to an appropriate place in the file before reading or writing data. This indicates a second characteristic of binary files; the binary files are generally processed using read and write operations simultaneously. For example, for the creation and processing a database file the best choice is a binary file. A record update operation will involve locating the appropriate record, reading the record into memory, modifying it in some way, and finally writing the record back to disk at its appropriate location in the file. These kinds of operations are common to many binary files, but are rarely found in applications that process text files.

The type of the file to be processed is decided at the time of opening a file. At the time of opening a file the mode of operation is mentioned indicating text file or binary file. The function fopen() provides the capability of opening a file. By default the file is opened in text mode. If the binary file is to be processed then it is explicitly defined as “b” along with the other required mode character ‘r’, ‘w’ or ‘a’.

When the file is opened the mode of operation is specified. It indicates the types of files “text” and "binary". The text file is advantageous in terms of size and the binary file in terms of random or direct access.

Online Movie ticket booking System project in ASP.NET

Introduction 

Through this software, You can reserve your movie hall ticket online. Basically this system categories in two parts, the first part related to visitor who want to book ticket and second part is related to admin who handle all the privileges like user account, payment account etc. When visitors visit the home page of this site then they will see the first interface of the project that is movie name with full description and book now button. When visitors click on book now button then they will go to the next page that is login page. If the visitors are authenticated person then no need to register again, simply login into the account. After login they will see the seat no , visitor can reserve multiple seat at a time.

Module of the project

  • Viewer module
  • Admin module

Software requirement to run this software

Visual Studio 2013 and windows 8

How to run this project

1. First to open the project in visual studio 2013 
2. Click to green color of triangle button, also you can use ctrl+f5.

Project Module

1. Visitor, who want to reserve seat
2. Admin

Snap Shot of the project

Ticket Booking snap

Ticket Booking snap

Ticket Cancel Snap

Ticket Cancel Snap


How to Download the project

Mail me : narenkumar851@gmail.com
© Copyright 2013 Computer Programming | All Right Reserved