You are on page 1of 25

The Computer

Central Processing Unit (CPU)


Input Primary Memory Output
Arithmetic & Logic Unit (ALU)

Secondary
Memory/Storage
IFM100 – Lecture 01 [ 2 ]
Software

• Operating Systems
• Disk Operating System (DOS)
• Unix
• Windows
• Linux
• Compilers
• Application Software

• Application Development Programming Environment (ADPE)

IFM100 – Lecture 01 [ 3 ]
Programming Languages

• COBOL
• Turbo Pascal
• C++
• Object-oriented programming languages:
• Java
• Visual Basic
• C#

IFM100 – Lecture 01 [ 4 ]
The Problem Solving Cycle • Stepwise refinement
• Pseudo language / Design language
• Problem:
Understanding & • Simplify into number of steps
Analyse problem • Executed in the correct order

Develop
Debug program algorithm
(Pseudo Code)

Code program

Execute and test


program

IFM100 – Lecture 01 [ 5 ]
Algorithms

• Algorithm – a number of simple steps that describe how a problem should be


solved
• Building blocks of an algorithm:

IFM100 – Lecture 01 [ 6 ]
What is a variables?

“a data item that may take on more than one value during the
runtime of a program”. [1]

[1] https://www.lexico.com/en/definition/variable

IFM100 – Lecture 01 [ 7 ]
Variables

• Named placeholders to temporarily contain values


• Examples: Variable Name Value stored in variable
A 100
Count 2
First_Name "John"
• There are very specific rules when it comes to naming variables:
1. The name MUST start with a letter
2. Letters and digits are permitted in naming variables
3. Variable names may not NOT contain ANY spaces
4. Variable names must not be reserved keywords
5. The length of the variable name is not important
• Examples: Valid Variable Names Invalid Variable Names
Variable1 1stVariable
My_Variable My Variable

IFM100 – Lecture 01 [ 8 ]
VeryVeryLongVariableName Private
Variable types

Data type Example of data


Integer 1 ; 2 ; - 500 ; 600 ; 800 Whole numbers
String “Jack” ; “123” ; “12asd” Words, characters
Decimal -5.12345 ; 56.45561; Decimal numeral system
Double -5.12345 ; 56.45561; Decimal numeral system

IFM100 – Lecture 01 [ 9 ]
Variable Assignment

• To assign values to a particular variable, we use:


• = in Visual Basic
• ← in pseudo code / design
• In the context,  and = both mean “gets the value of”
• Examples:
• To assign the integer value 30 to the variable Number:
Visual Basic Code Pseudo Code
Number = 30 Number  30
• To increment the variable Counter by 1:
Visual Basic Code Pseudo Code
Counter = Counter + 1 Counter  Counter + 1

IFM100 – Lecture 01 [ 10 ]
The If-Statement

• Provides selection (choice) of action(s) to take based on a given condition


How to...define an If-statement
If (condition) Then
Sequence of steps to be executed because condition is True
[ Else ]
Sequence of steps to be executed because condition is False
End If
• Examples:
Example 1 Example 2
If GrossIncome < 10 000 Then If Service = "Good" Then
Tax amount is 15% Write good review
Else Else
Tax amount is 25 % Complain to management
End If End If

IFM100 – Lecture 01 [ 11 ]
Event-Driven Programming

Reaction by VB
Event

• Example: Click of a mouse

Public Class Form1


Private Sub Button1_Click(…) Handles
Button1.Click
'Action to follow when
button clicked
End Sub
End Class

IFM100 – Lecture 01 [ 12 ]
Design Process

• What must go into the program


Input

• Actions & Events that must take place in the program


Processing

• Results of input being processed by the program


Output

• Design User Interface


• Input & Output

IFM100 – Lecture 01 [ 13 ]
8 Parts of the Design

Before working in Visual Studio (placing controls on the form and writing the
code), we need to come up with a design that identifies:

1. Inputs – what information must go into the program?


2. Outputs – what information must come out from the program?
3. Events – which events will trigger the actions?
4. Actions – what actions must take place?
5. Variables – what variables are required to transform the information
input into the desired output?
6. Interface – what should the program look like?
7. Algorithms – what steps must be taken to achieve each action?
8. Test Data – How to check the program is working correctly.

IFM1A10 – Lecture 01 [ 2 ]
Designing the Solution to your First Problem

The VAT Problem


Write a program to calculate the VAT on a product if the price is given (VAT is 15%)

• Begin with the design of the solution program:


• Input: Price of product
• Output: VAT on the product
Event Action
User clicks on the command Calculate the VAT of the
button – btnVat product and display

• Variables:
• Price – Integer
• VAT – Double

IFM100 – Lecture 01 [ 15 ]
• Interface:
• Be sure to refer to Inputs, Outputs, Actions & Events to design the
interface

Calculating VAT frmVAT

Price: Calculate btnVAT

VAT: txtPrice

txtVAT

• Pseudo Code:
• For btnVAT() sub:
• Get from the textbox txtPrice and Store in variable Price
• VAT  Price * 15/100
• Display the value of the variable VAT in the textbox txtVAT

IFM100 – Lecture 01 [ 16 ]
• Test data:

Test # Input Output


1 Price = 100 VAT = 15
2 Price = 150 VAT = 22.5
3 Price = 200 VAT = 30
4 Price = 250 VAT = 37.5

IFM100 – Lecture 01 [14]


The Integrated Development Environment (IDE)

• The Integrated Development Environment (IDE) used to develop Visual Basic


applications (projects) is called Visual Studio
• The current version of Visual Studio in use is Visual Studio 2017 Community
Edition

• Visual Basic projects can be combinations of:


• Forms which contain
• Controls (such as textboxes, labels and buttons)
• Code

• A certain convention is applied to the naming of forms and controls to make it


easier for programmers to identify the various components of a Visual Basic
project

IFM100 – Lecture 01 [ 18 ]
Forms

Text
Property:
My Program...

Name
Property:
frmGame

• Important form properties:


• Name
• Prefix with frm
• e.g. frmGame
• Text
• The "label" of the form, representing the form's title

IFM100 – Lecture 01 [ 19 ]
Textboxes

Name
Property:
txtName

• A box that can be used to enable a user to enter text or to display text
• Important textbox properties:
• Name
• Prefix with txt
• e.g. txtName
• Text
• The value in the textbox itself (format of the value is always a String)
• Normally left blank

IFM100 – Lecture 01 [ 20 ]
Labels

Name
Property:
lblName
Text
Property:
Student Name:

• Provides text on the form


• Important label properties:
• Name
• Prefix with lbl
• e.g. lblName
• Text
• The value that is displayed

IFM100 – Lecture 01 [ 21 ]
Command Buttons

Name
Text Property:
Property: btnAdd
Add

• Provides the means to trigger execution of code


• Important command button properties:
• Name
• Prefix with btn
• e.g. btnAdd
• Text
• The caption on the command button

IFM100 – Lecture 01 [ 22 ]
Exercise 1:

Write a program to calculate a net salary where 30% tax is subtracted from the
gross salary.

IFM100 – Lecture 01 [ 23 ]
Solution to Exercise 1
• Input: Gross salary • Variables:
• Outputs: Net salary, Tax • Gross – Integer
• NetSal – Decimal (Double)
Events Actions
• Tax – Decimal (Double)
User clicks the • Calculate the Tax
command button – • Calculate the Net
btnCalc salary • Pseudo Code (for btnCalc() sub):
• Display both Net • Input the entered value into
salary and Tax variable Gross
• Tax ← Gross * 30/100
• Interface: frmSalary • NetSal ← Gross - Tax
• Display the value of the
Salary Calculator
variable Tax in the textbox
txtTax
Gross Salary: Calculate
• Display the value of the
Tax: txtGross variable NetSal in the textbox
txtTax btnCalc txtNet
Net Salary:
txtNet
IFM100 – Lecture 01 [ 24 ]
Solution to Exercise 1 Continued…

Test data:

Test # Input Output


1 Gross = 1000 Tax = 300
Nett = 700
2 Gross = 1500 Tax =450
Nett = 1150
3 Gross = 2000 Tax = 600
Nett = 1400
4 Gross = 5000 Tax = 1500
Nett = 3500

IFM100 – Lecture 01 [ 22 ]

You might also like