MELJUN CORTES VB.NET Technical faculty module part2 wsd

Preview:

DESCRIPTION

MELJUN CORTES VB.NET Technical faculty module part2 wsd

Citation preview

Introduction to Computer Programming

MELJUN CORTESMELJUN CORTES

Visual Basic .Net Programming Using Visual Studio .Net

Objectives

This module aims:• To introduce the software development process;• To know the different programming constructs of

Visual Basic .NET; and• To enhance the programming skills of the

participants.

Topics

• The software development process

• Different Control Structures in programming

• Visual Basic .NET examples

• Lab Exercise

The Software Development Process

1. Problem Analysis

2. Setting up an algorithm

3. Implementing your algorithm

4. Running, Testing, & Debugging

5. Documentation

Problem!

Mr. De la Cruz needs a program to compute grades of 50 students. Grade computation is:

40% Average of 3 Exams

+ 40% Final Exam

20% Class participation

100%

Once grade of a student is computed the program also displays if student passed or failed. Passing grade is 70%.

1. What are we asked to do?

Compute the final grade, and

determine if student is passing or not

1. Problem analysis

2. What are the given data (inputs) and results that are to be produced (outputs)?

Input: Quiz No. 1 (Q1)

Quiz No. 2 (Q2) Quiz No. 3 (Q3) Final Exam (FE) Class Participation (CP)

Output: Final Grade (FG)

1. Problem analysis

3. How do we accomplish our task?

FG = 40%

+ 30% (FE)

+ 15% (CP)

Q1 + Q2 + Q3

3

1. Problem analysis

Algorithm a list or sequence of steps that solves the

given problemNote: The steps should be as detailed as

possible.

2. Set-up Algorithm

Example:Step 1. Get Q1, Q2, and Q3 gradeStep 2. Get FE gradeStep 3. Get CP gradeStep 4. Calculate the FG using the formulaStep 5. Display the final grade FG

Step 6. Determine if student passed or failedStep 7. If students processed < 50,

go back to step 1 and process next student.

2. Set-up Algorithm

Refining the algorithm

Step 6. Determine if student passed or failed

Step 6. Determine if student passed or failed

Step 6.1. If FG < 70%,

display student failed

otherwise,

display student passed

3. Implementing the algorithm

Basic Questions:1. How do you get input and display output?2. How do you store information?3. How do you write formula?4. How do you make a program perform statements

depending on different situations?5. How do you make a program repeat parts of itself?

Getting input and output

Using consoleImports System

Public Module Hello

Public Sub Main( )

Console.WriteLine("hello, world")

End Sub

End Module

Screen output

Getting input and output

Demo using GUI

How do we store data?

Answer: Use variables

Declaring variables:

Dim variable As datatype

Rules:1. Must begin with a character or underscore2. Cannot have special characters3. Cannot be a reserved word

Basic data types in VB .NET

Numerical:

Integer (whole numbers)

Float (floating point)

Non-numerical:

Boolean (true or false values)

Char (a single character)

String (many characters)

Sample Declaration

Dim finalGrade As Float

Dim quiz1 As Integer

Dim name As String

Programming Tips…

1. Use descriptive variable names2. Don’t use names that differ by only one

characterex. Dim final As Float

Dim finals As Float3. Use names that are not too long and

not too short

Branching constructs

The If statement

Syntax 1: If expression Then

statements

End If

Example

For the problem of Mr. dela Cruz, to determine if a student passed or failed, we use:

If finalGrade >= 70 Then

Console.WriteLine(“Passed”)

End If

If finalGrade < 70 Then

Console.WriteLine(“Failed”)

End If

Branching constructs

The If statement

Syntax 2: If expression Then

statements

Else

statements

End If

Example

For the problem of Mr. dela Cruz, to determine if a student passed or failed, we use:

If finalGrade >= 70 Then

Console.WriteLine(“Passed”)

Else

Console.WriteLine(“Failed”)

End If

Branching constructs

The If statement

Syntax 3: If expression Thenstatements

ElseIf expression Thenstatements

ElseIf expression Thenstatements

Elsestatements

End If

Example

If finalGrade >= 90 Then

Console.WriteLine(“Very Good”)

ElseIf finalGrade >= 80 Then

Console.WriteLine(“Good”)

ElseIf finalGrade >= 70 Then

Console.WriteLine(“Satisfactory”)

Else

Console.WriteLine(“Needs Improvement”)

End If

Looping constructs

• Allow a group of statements to be executed more than once

• Looping statements in VB .NET:– Do– For– For Each

Looping constructs

The Do statement

Body of the loop is executed either:

1. while a condition remains true; or

2. until the condition becomes true

Looping constructs

The Do statement examples

Do While count < 50' statements

Loop

Do Until count > 50' statements

Loop

Do ' statementsLoop While count <= 50

Do ' statementsLoop Until count >= 50

Do ' statementsLoop

Looping constructs

The For statement

• Body of the loop is executed a fixed number of times

• Looping is controlled by a loop control variable

Looping constructs

Syntax of For statement:

For var = expr To expr [ Step expr ]

statements

Next [ variable_list ]

Looping constructs

Example of For statement:

For i = 1 To 10

Next

For i = 1 To 10

For j = 1 To 10

Next i, j

For i = 1 To 10

For j = 1 To 10

Next

Next

Different bugs or errors encountered:

• Syntactical errors are caused by deviating from grammatical rules of the language.

• Logical errors are caused due to faulty algorithm formulation

4. Run, Test, debug

Reasons for doing documentation:1. Ease of understanding different parts of the

code.

2. Reduces efforts during program maintenance and problem reconstruction.

Internal Documentation in VB .NET:‘ This is a comment

5. Documentation

.NET Hands On Exercises

Exercises

• Lab1: Flash Cards

• Lab2: XChange

• Lab3: Student Picker

• Lab4: Mine Sweeper

Flash Cards

• Objectives– Design a graphical user interface.– Modify the properties of the user controls.– Create and call functions.– Perform input and output operations.– Create and evaluate statements and

expressions.– Implement and analyze program branching.

Flash Cards

• Features– Generates random

algebra problems.– Checks user input if

correct or incorrect.– Optional: scoring– Optional: hints

Flash Cards

• Creating the GUI– Drag and drop controls from the toolbox.– Use the properties window to modify the windows

controls.– Change the names of the controls.

Flash Cards

• Declaring Variables

Flash Cards

• Creating Functions

Flash Cards

• Generating the problem

Flash Cards

Flash Cards

Flash Cards

• Checking the answer

Flash Cards

• Giving hints

XChange

• Objectives– Modify the properties of the user controls.– Create and call functions.– Convert data types.– Create and evaluate statements and

expressions.– Handle Windows control events.

XChange

• Features– Converts one value to

another based on a given formula.

– Customizable conversion functions.

XChange

• Synchronize TrackBar and Label

XChange

• Convertion Functions

XChange

• Convert Left Value

XChange

• Convert Right Value

XChange

• Dollar to Peso Conversion

XChange

• Grade Equivalent of 70 pt Exam

XChange

• Other Applications– Celsius to Fahrenheit– Pounds to Kilos– Inches to Centimeters– Etc.

Teaching Assistant

• Objectives– Call functions and pass parameters– Practice looping constructs and conditions– Work with list controls– Use the features of collections– Handle file input and output

Teaching Assistant

• Features– Class attendance

checker– Random student

selection– Load/Save class lists

Teaching Assistant

• Adding new students

Teaching Assistant

• Deleting students

Teaching Assistant

• Checking class attendance

Teaching Assistant

• Checking class attendance

Teaching Assistant

• Checking class attendance

Teaching Assistant

• Create a random function

Teaching Assistant

• Randomly select a present student

Recommended