Programming with Visual C++: Concepts and Projects Chapter 4B: Selection (Tutorial)

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Visual C++ Programming: Concepts and Projects
Visual C++ Programming: Concepts and Projects
CST JavaScript Validating Form Data with JavaScript.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Visual Basic Chapter 1 Mr. Wangler.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
Chapter 4: Making Decisions. Understanding Logic-Planning Tools and Decision Making Pseudocode – A tool that helps programmers plan a program’s logic.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Programming with Visual C++: Concepts and Projects Chapter 3B: Integral Data (Tutorial)
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
Visual Basic Programming
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
Visual C++ Programming: Concepts and Projects Chapter 11B: Pointers (Tutorial)
Chapter 5: More on the Selection Structure
Programming with Microsoft Visual Basic th Edition
Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
JavaScript, Fourth Edition
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3B Integral Data (Tutorial)
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Unit 6 Repetition Processing Instructor: Brent Presley.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
Visual C++ Programming: Concepts and Projects Chapter 10B: Recursion (Tutorial)
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Course ILT Using complex selection structures Unit objectives Include radio buttons and check boxes in an interface, create and call a user- defined Sub.
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
Visual C++ Programming: Concepts and Projects
JavaScript, Sixth Edition
Chapter 5 Validating Form Data with JavaScript
Tutorial 14 – Shipping Time Application Using DateTimes and Timers
Using Procedures and Exception Handling
More Selections BIS1523 – Lecture 9.
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Microsoft Visual Basic 2005: Reloaded Second Edition
Department Array in Visual Basic
CIS 16 Application Development Programming with Visual Basic
Fonts, TabControl, ListBox
Programming Logic and Design Fifth Edition, Comprehensive
Presentation transcript:

Programming with Visual C++: Concepts and Projects Chapter 4B: Selection (Tutorial)

Tutorial: Vacation Planner Problem Analysis Design – Interface sketch – Control and Data Tables – Algorithms Development – Create the interface – Code event handlers Testing Programming with Visual C++: Concepts and Projects2

Problem Analysis Construct a program that allows the user to select a destination and indicate the number of nights and the number of rooms required The program will calculate cost and apply multiple room discounts, if appropriate Programming with Visual C++: Concepts and Projects3

Problem Analysis (continued) Programming with Visual C++: Concepts and Projects4

Problem Analysis (continued) Programming with Visual C++: Concepts and Projects5

Design Interface Sketch – MonthCalendar controls for date of arrival and departure – GroupBox control used to contain RadioButtons – RadioButtons indicate choice of destination When one is selected the others in the group will automatically become deselected – Some control settings will be initialized upon loading the form in memory Programming with Visual C++: Concepts and Projects6

Design (continued) Programming with Visual C++: Concepts and Projects7

Design (continued) Programming with Visual C++: Concepts and Projects8

Design (continued) Programming with Visual C++: Concepts and Projects9

Design (continued) Algorithm for Form1_Load() event Programming with Visual C++: Concepts and Projects10

Design (continued) Algorithm for btnCalc_Click() event – Step 1: Declare variables – Step 2: Read the input data Read rooms Read arrival date Read departure date Assign room cost based on destination (radio buttons) – Step 3: Process data Programming with Visual C++: Concepts and Projects11

Design (continued) Programming with Visual C++: Concepts and Projects12

Design (continued) Programming with Visual C++: Concepts and Projects13 A look ahead at Visual C++ code (a multiple alternative if statement) to implement Step 2.4 (determining the cost of the room)

Design (continued) Algorithm for btnCalc_Click() event – Step 3 – If rooms < 1 then error message – Calculate nights – If nights < 1 then error message – If no errors Select room discount Calculate total cost Display total cost Programming with Visual C++: Concepts and Projects14

Design (continued) Programming with Visual C++: Concepts and Projects15

Design (continued) Programming with Visual C++: Concepts and Projects16 A look ahead at Visual C++ code (a single alternative if statement) to implement Step 3.1

Design (continued) Programming with Visual C++: Concepts and Projects17

Design (continued) Programming with Visual C++: Concepts and Projects18 A look ahead at Visual C++ code (a multiple alternative switch statement) to implement Step 3.4.1

Design (continued) Programming with Visual C++: Concepts and Projects19 Final Algorithm for btnCalc_Click()

Design (continued) Programming with Visual C++: Concepts and Projects20

Design (continued) Test strategy – Identify valid data ranges – Identify invalid data ranges Programming with Visual C++: Concepts and Projects21

Design (continued) Test strategy – Create test scenarios that involve valid and invalid data Programming with Visual C++: Concepts and Projects22

Design (continued) Use a structured walkthrough (trace table) to verify that the algorithm is correct under each scenario List algorithm steps down the left side and variables across the top Programming with Visual C++: Concepts and Projects23

Design (continued) Programming with Visual C++: Concepts and Projects24 The first scenario fails because in Step 3.4 because ok does not contain a value. It was never assigned in Step 1 (we should make a note of this and revise the algorithm accordingly

Design (continued) Programming with Visual C++: Concepts and Projects25 With the revision made, the algorithm now traces correctly to its finish

Design (continued) Programming with Visual C++: Concepts and Projects26 Each test scenario should be verified this way

Design (continued) If the algorithm passes all tests then you are ready to move on to the Development stage If the algorithm fails any test then it must be revised until it passes Programming with Visual C++: Concepts and Projects27

Development Create the interface – Use a GroupBox control to contain the RadioButtons – GroupBoxes must be laid down before RadioButtons are placed in them Code the event handlers – Form1_Load() – btnCalc_Click() Programming with Visual C++: Concepts and Projects28

Development (continued) Programming with Visual C++: Concepts and Projects29

Development (continued) Programming with Visual C++: Concepts and Projects 30

Development (continued) Programming with Visual C++: Concepts and Projects31

Development (continued) The ComboBox control – Use the Items property to enter the collection of items you wish to appear in the ComboBox list – Each item has its own index value – The first (empty) item has a value of -1 Programming with Visual C++: Concepts and Projects32

Development (continued) Programming with Visual C++: Concepts and Projects33

Development (continued) Programming with Visual C++: Concepts and Projects34

Development (continued) Programming with Visual C++: Concepts and Projects35 You can set a default selection for the ComboBox by assigning a SelectedIndex value

Development (continued) Code the event handlers – Form1_Load() – btnCalc_Click() Programming with Visual C++: Concepts and Projects36

Development (continued) Programming with Visual C++: Concepts and Projects37 Form1_Load() – Assigns default ComboBox value – Initializes destination names on RadioButtons – Sets default destination RadioButton

Development (continued) Programming with Visual C++: Concepts and Projects38 Variables depart and arrive are DateTime objects read from the monthlyCalendars Subtraction is defined for DateTime objects for – Months – Days – Years

On Your Own Test scenarios – Verify that your program works as expected for each of the test scenarios Rewrite the switch statement – Use a multiple alternative if statement instead Extreme nesting – Remove the ok variable from your program – Use nested if…else statements to filter out error conditions Programming with Visual C++: Concepts and Projects39