Homework 3
CAP 407
MODERN PROGRAMMING TOOLS & TECHNIQUES III
SUBMITTED TO-
Sarabjeet Sir
SUBMITTED BY-
SACHIN RAJ
B34
D3901
Q1. Using console application in vb.net create a namespace
withmethods to read details of student like patient_name,
registration_no, con_doctor, costperday, total days. Use member
variables, procedures ,functions to calculate the bill
display the same?
Ans-
Namespace hello
Public Class a
Public name As String
Public regno As Integer
Public a, b, c, per As Integer
Public Sub input()
Console.WriteLine("Name:")
name = Console.ReadLine()
Console.WriteLine("Registration No:")
regno = Console.ReadLine()
Console.WriteLine("Enter The Marks Of First Subject")
a = Console.ReadLine()
Console.WriteLine("Enter The Marks Of Second Subject")
b = Console.ReadLine()
Console.WriteLine("Enter The Marks Of Third Subject")
c = Console.ReadLine()
Console.WriteLine("Total Marks Is::{0}", a + b + c)
End Sub
Public Function calc()
per = (a + b + c) / 3
If per >= 90 Then
Console.WriteLine("GRADE A")
ElseIf per >= 70 And per <= 90 Then
Console.WriteLine("GRADE B")
Else
Console.WriteLine("NOT QUALIFIED")
End If
Return per
End Function
Public Sub disp()
Console.WriteLine("Student Name is:{0}", name)
Console.WriteLine("Registration No is:{0}", regno)
End Sub
End Class
End Namespace
Module Module1
Sub Main()
Dim obj As New hello.a()
Dim c As Double
obj.input()
obj.disp()
c = obj.calc()
Console.WriteLine("Student Percentage is::{0}", c)
Console.ReadKey()
End Sub
End Module
OUTPUT
Q2. Create a widow based application to implement LIFO and FIFO
concepts in vb.net?
Ans-
Imports System.Collections.Stack
Public Class Form1
Dim stk As New Stack()
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
stk.Push(TextBox1.Text)
MessageBox.Show("Item Inserted")
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
TextBox2.Text = stk.Pop()
Console.WriteLine("Top Element Deleted")
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
MessageBox.Show("First Element Is=" & stk.Peek())
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button4.Click
Dim a As Object
a = InputBox("Enter the Item To Find in Stack")
If stk.Contains(a) Then
MessageBox.Show("Found")
Else
MessageBox.Show("Not Found")
End If
End Sub
End Class
Queue In Windows Form
Imports System.Collections.Queue
Public Class Form1
Dim que As New Queue()
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
que.Enqueue(TextBox1.Text)
MessageBox.Show("Item Inserted")
TextBox1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim a As Object
a = InputBox("Which Operation Do u Like To perform--POP OR
CLEAR")
If a = "pop" Then
MessageBox.Show("Top Element Deleted::" & que.Dequeue)
ElseIf a = "clear" Then
que.Clear()
MessageBox.Show("All Element Cleared")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
Dim a As Object
a = InputBox("Enter elements which U want To Search")
If que.Contains(a) Then
MessageBox.Show("Found")
Else
MessageBox.Show("Not Found")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button4.Click
MessageBox.Show("First Element is" & que.Peek())
End Sub
End Class
Q3. Create a windows application that calculates salary of an
emplyee. Make use of controls like textbox, listbox, combobox ,
date/time picker. Make use of
procedures and functions where ever possible?
PART- B
Q4. Using a rich text box create an application in vb.net to
implement functionality of file menu?
Ans-
Imports System.IO
Imports System.Windows.Forms.Form
Public Class Form1
Private Sub OpeToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
OpeToolStripMenuItem.Click
Dim sr As StreamReader
Dim fo As New OpenFileDialog()
fo.Filter = "text.files(*.txt) |*.txt| " & " all files| *.*"
If fo.ShowDialog() = DialogResult.OK Then
sr = New StreamReader(fo.OpenFile)
RichTextBox1.Text = sr.ReadToEnd()
sr.Close()
End If
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SaveToolStripMenuItem.Click
Dim sw As StreamWriter
Dim filename As String
Dim fs As New SaveFileDialog()
fs.FileName = filename
fs.Filter = "text.files(*.txt) |*.txt| " & " all files| *.*"
If fs.ShowDialog() = DialogResult.OK Then
filename = fs.FileName
sw = New StreamWriter(filename)
sw.Write(RichTextBox1.Text)
sw.Close()
End If
End Sub
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SaveAsToolStripMenuItem.Click
End
End Sub
End Class
Q5. Create an application in vb.net using rich text box to
implement font, colour and use of system calculator in an
application?
Ans-
Public Class Form1
Private Sub FontToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
FontToolStripMenuItem.Click
Dim fd As New FontDialog()
fd.Font = RichTextBox1.Font
fd.Color = RichTextBox1.ForeColor
If fd.ShowDialog = DialogResult.OK Then
RichTextBox1.Font = fd.Font
End If
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ColorToolStripMenuItem.Click
Dim raj As New ColorDialog()
raj.Color = RichTextBox1.ForeColor
If raj.ShowDialog() = DialogResult.OK Then
RichTextBox1.ForeColor = raj.Color
End If
End Sub
End Class
Q6. Create a window based application in VB.Net with a button.
Display a message box whenever the button is being clicked and
count the number of clicks user have done. Place a exit button
to close the application and display the number times user have
clicked the button?
Ans-
Public Class Form1
Dim sachin As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
sachin += 1
MessageBox.Show("You Have Clicked->" & sachin.ToString() & "
Times.")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
End
End Sub
End Class