#include<iostream.h>
#include<conio.h>
int max=7;
int t=0;
class stack
{
int s[7];
public:
void push(int);
void pop();
void top();
void empty();
void show();
};
void stack::push(int y) //Push Operation
{
if(t<max)
{
t=t+1;
s[t]=y;
}
else
cout<<endl<<"stack overflows..."<<endl;
}
void stack::pop() //Pop Operation
{
int item;
if(t>=0)
{
t=t-1;
item=s[t+1];
cout<<endl<<"popped item >>"<<item<<endl;
}
else
cout<<endl<<"stack underflows"<<endl;
}
void stack::top() //To find the top of the stack
{
if(t>=0)
cout<<endl<<"topmost element >> "<<s[t]<<endl;
else
cout<<endl<<"stack underflows..."<<endl;
}
void stack::empty() //To check if the stack is empty
{
if(t<0)
cout<<endl<<"stack is empty..."<<endl;
else
cout<<endl<<"stack is not empty..."<<endl;
}
void main()
{
int a,x;
stack s1;
clrscr();
do
{
cout<<"enter an option..."<<endl<<"1-push"<<endl<<"2-pop"<<endl<<"3-top"<<endl<<"4-empty"<<endl;
cout<<"5-end"<<endl;
cin>>a;
cout<<endl;
switch(a)
{
case 1:
{
cout<<endl<<"enter a value >> "<<endl;
cin>>x;
s1.push(x);
}
break;
case 2:
s1.pop();
break;
case 3:
s1.top();
break;
case 4:
s1.empty();
break;
}
}
while(a!=5);
getch();
}
Monday, 28 January 2013
Tuesday, 22 January 2013
Basic error handling in vb.NET for inserting data into database
Try
conn.Open()
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = "select dname from dept where deptno = " + TextBox1.Text
cmd.CommandType = CommandType.Text
If dr.Read() Then
Label1.Text = dr.Item("dname") ' or use dr.Item(0)
End If
Catch ex As Exception ' catches any error
MessageBox.Show(ex.Message.ToString())
Finally
' In a real application, put cleanup code here.
End Try
Catch ex As OracleException ' catches only Oracle errors
Select Case ex.Number
Case 1
MessageBox.Show("Error attempting to insert duplicate data.")
Case 12545
MessageBox.Show("The database is unavailable.")
Case Else
MessageBox.Show("Database error: " + ex.Message.ToString())
End Select
Catch ex As Exception ' catches any error
MessageBox.Show(ex.Message.ToString())
catch (Exception ex) // catches any error not previously caught
{
MessageBox.Show(ex.Message.ToString());
}
conn.Open()
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = "select dname from dept where deptno = " + TextBox1.Text
cmd.CommandType = CommandType.Text
If dr.Read() Then
Label1.Text = dr.Item("dname") ' or use dr.Item(0)
End If
Catch ex As Exception ' catches any error
MessageBox.Show(ex.Message.ToString())
Finally
' In a real application, put cleanup code here.
End Try
Catch ex As OracleException ' catches only Oracle errors
Select Case ex.Number
Case 1
MessageBox.Show("Error attempting to insert duplicate data.")
Case 12545
MessageBox.Show("The database is unavailable.")
Case Else
MessageBox.Show("Database error: " + ex.Message.ToString())
End Select
Catch ex As Exception ' catches any error
MessageBox.Show(ex.Message.ToString())
catch (Exception ex) // catches any error not previously caught
{
MessageBox.Show(ex.Message.ToString());
}
Thursday, 17 January 2013
Unique Random number generator in vb.net
//hey guys here is my new program in vb.NET which generates unique 20 random Numbers.
Public Class Form1
Dim generator As New Random
Dim arr(20) As Integer
Dim num As Integer = 0
Dim i As Integer = 1
Dim k As Integer = 0
Dim x As Boolean
Public Sub btngenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngenerate.Click
numshow()
End Sub
Private Sub numshow()
If k < 20 Then
num = generator.Next(1, 21)
x = check()
If x = True Then
arr(i) = num
Label1.Text = arr(i).ToString
i = i + 1
k = k + 1
Else
numshow()
num = 0
End If
Else
MessageBox.Show("no more")
End If
End Sub
Private Function check() As Boolean
Dim l = i - 1
For j As Integer = 1 To l
If arr(j) = num Then
Return False
End If
Next
Return True
End Function
End Class
If you liked the code please do the courtesy to give one like and follow my blog or please at least visit our youtube channel at least once and subscribe that too if you like.
Click here to visit youtube channel
Public Class Form1
Dim generator As New Random
Dim arr(20) As Integer
Dim num As Integer = 0
Dim i As Integer = 1
Dim k As Integer = 0
Dim x As Boolean
Public Sub btngenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngenerate.Click
numshow()
End Sub
Private Sub numshow()
If k < 20 Then
num = generator.Next(1, 21)
x = check()
If x = True Then
arr(i) = num
Label1.Text = arr(i).ToString
i = i + 1
k = k + 1
Else
numshow()
num = 0
End If
Else
MessageBox.Show("no more")
End If
End Sub
Private Function check() As Boolean
Dim l = i - 1
For j As Integer = 1 To l
If arr(j) = num Then
Return False
End If
Next
Return True
End Function
End Class
If you liked the code please do the courtesy to give one like and follow my blog or please at least visit our youtube channel at least once and subscribe that too if you like.
Click here to visit youtube channel
Subscribe to:
Posts (Atom)