Chapter four selected exercises with solutions. 4.2.

Slides:



Advertisements
Similar presentations
Modular Programming Splitting your program into functions and procedures.
Advertisements

Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Input Dialog Box An input dialog box can be used to obtain a single item of input from the user Presents a window (dialog box) requesting input Syntax:
Introduction to Computing Dr. Nadeem A Khan. Lecture 27.
Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
1 Pertemuan 07 Procedures Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 5 - Visual Basic Schneider1 Chapter 5 Decisions.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Fundamentals of Programming in Visual Basic
Click 98 bmi 1,75 kg m 98 bmi 1,75 kg m 32 Applet for calculation of body mass index.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
Body Mass Index Calculator CS 633 – Distributed Software Development Prof. Eric Braude Facilitator Bryan Halter Group 2 Adriana CastrillonHaroon Chohan.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
Chapter 7 Code Tables. VB Code Box 7-1 Event Procedure for Compute Button Private Sub hsbExemptions_Change() txtExemptions.Text =Str(hsbExemptions.Value)
ENGR 112 Decision Structures.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Do Loop with Interest Please see speaker notes for additional information!
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
Chapter 8 - Visual Basic Schneider
Arrays. Lesson Objectives  To understand what an array is and it’s function  To know how code and array in VB.
1. 2 Sales tax is calculated by finding the percent of the total purchase.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Repetition Structures
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
User Defined Data Types The Type Statement. Creating Your Own Data Types You can combine variables of several different types to create user-defined types.
Chapter six exercises
Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable.
EVAN’S FAST FOOD VISUAL BASIC 2012 FINAL PROJECT BY: EVAN CHOATE.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Chapter81 For....Next Loops n For i = m To n statement (s) Next i n For statement designates a numeric variable, called control variable. n It is initialized.
情報基礎 A Lecture 9 Takeshi Tokuyama ・ Jinhee Chun Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
General Procedures Chapter 4. Different Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular Design (not.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
Spreadsheet-Based Decision Support Systems
User-Defined Data Types
College Algebra Chapter 4 Exponential and Logarithmic Functions
Chapter 4 - Visual Basic Schneider
Lbound and Ubound Functions
3-SAT as integer program
Chapter 2 Section 2.
Function Procedures.
Exercise Solution First questions What's output What's input
Chapter 8 - Visual Basic Schneider
For...Next Statements.
Presentation transcript:

Chapter four selected exercises with solutions

4.2

6. NE

8. Approximate Annual Wage: $20,000.00

10. If you fail to plan then you plan to fail

14. Hello Ray and Bob and Bob

Private Sub cmdDisplay_Click() Dim first As String, last As String, fInit As String, lInit As String 'Display initials picOutput.Cls Call InputNames(first, last) Call ExtractInitials(first, last, fInit, lInit) Call DisplayInitials(fInit, lInit) End Sub Private Sub InputNames(first As String, last As String) 'Get the persons first and last name first = InputBox("Enter your first name:") last = InputBox("Enter your last name:") End Sub

Private Sub ExtractInitials(first As String, last As String, fInit As String, lInit As String) 'Determine the initials of the first and last names fInit = Left(first, 1) lInit = Left(last, 1) End Sub Private Sub DisplayInitials(fInit As String, lInit As String) 'Display the initials picOutput.Print "Your initials are "; fInit; "."; lInit; "." End Sub

Or without calls to sub procedures Private Sub cmdDisplay_Click() Dim first As String, last As String, fInit As String, lInit As String 'Display initials picOutput.Cls first = InputBox("Enter your first name:") last = InputBox("Enter your last name:") fInit = Left(first, 1) lInit = Left(last, 1) picOutput.Print "Your initials are "; fInit; "."; lInit; "." End Sub

Dim total As Single 'In (Declarations) section of (General) Private Sub cmdProcessItem_Click() Dim item As String, price As Single 'Process item; display part of sales receipt Call InputData(item, price) total = total + price Call ShowData(item, price) txtItem.Text = "" txtPrice.Text = "" txtItem.SetFocus End Sub

Private Sub InputData(item As String, price As Single) 'Input item name and price item = txtItem.Text price = Val(txtPrice.Text) End Sub Private Sub ShowData(strItem As String, numItem As Single) 'Display data on specified line picReceipt.Print strItem; Tab(15); FormatNumber(numItem) End Sub

Private Sub cmdDisplay_Click() Dim tax As Single 'Display sum, tax, and total tax = total * 0.05 tax = Round(tax, 2) picReceipt.Print Tab(15); " " Call ShowData("Sum", total) Call ShowData("Tax", tax) Call ShowData("Total", total + tax) End Sub

4.3

4. 400

6. The day is Wed

Private Sub cmdCalcIdealAge_Click() Dim manAge As Integer 'Calculate ideal age for wife, according to Plato picIdealAge.Cls Call InputManAge(manAge) Call ShowWifeAge(manAge) End Sub Private Sub InputManAge(manAge As Integer) manAge = Val(InputBox("Enter your age: ")) End Sub Private Sub ShowWifeAge(manAge As Integer) picIdealAge.Print "The ideal age of your wife is"; Int(manAge / 2 + 7) End Sub

Private Sub cmdCalculate_Click() picResult.Cls picResult.Print "Your BMI is"; BMI(Val(txtWeight), Val(txtHeight)) End Sub Private Function BMI(w As Single, h As Single) As Single 'Calculute body mass index BMI = Round(703 * w / h ^ 2) End Function