1 Lab Session-7 CSIT-121 Fall 2004 4 Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.

Slides:



Advertisements
Similar presentations
Repetition Control Structures
Advertisements

Control Structures Corresponds with Chapters 3 and 4.
1 Session-16 CSIT 121 Spring 2006 Demo for switch-case due now Demo for switch-case due now String comparison String comparison Slide 23; sample case.
1 CIS Jan Overview Selection Statements –If Statement –Else –Nested If-Else –Switch Repetition Statements –While statement –For Statement.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
1 Session-I & II CSIT-121 Spring 2006 Session Targets Introducing the VC++.NET Solving problems on computer Programming in C++ Writing and Running Programs.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 Session-7 CSIT 121 Spring 2006 Lab Demo of NiMo Lesson 3-2 Exercises 1,2,3,4,5,6 (Arithmetic Operators with Program ‘Convert.cpp’) Q&A about operators.
1 Session-15 CSIT 121 Spring 2006 Selection with Switch~Case Selection with Switch~Case Need an integer or character to test for Need an integer or character.
1 Session-11 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-4 due Now Chapter 4 topics –Using get and ignore to control input data (3-19) –Prompting.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 Lab Session-VII CSIT-121 Fall Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While.
1 Lab Session-V CSIT-120 Fall 2000 Menu Driven Software Lab Exercise While and do-while statements Lab-V Continues: The if statement Logical Operators.
1 Lab Session-3 CSIT 121 Spring’05 Division rules Operator precedence rules Lab Exercise.
1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise.
1 Lab Session-VI CS121 Fall 2000 l HW#2 Assigned l Multiple Choice Selectors l The While Loop l Switch-Case-Break Exercise l The Counter Controlled Loops.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
Testing Strategies COMP1 – Section 4.2. Testing. Aims At the end of this lesson you will be able to:  Explain different testing strategies  Design and.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
PN: TM rev:3 Administration Training. PN: TM rev:3 Course Overview Logging On Menu Screens »Edit Functions Options Configuration Users »View.
SuccessMaker. Where are they? Math: Intranet On a server at Vanhoose Reading Web-based.
ProCal Calibration Software Performing a Calibration On a Motech MIC39 Multimeter.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
More While Loop Examples CS303E: Elements of Computers and Programming.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Previously Repetition Structures While, Do-While, For.
Copyright ©2005  Department of Computer & Information Science JavaScript Modularity.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
CREATING MENUS IN JAVA Mimi Opkins CECS 174. Menus Menus work well for console applications. The menu can be contained within a do-while loop and the.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
Review while loops Control variables Example Infinite loop
1 CS161 Introduction to Computer Science Topic #8.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: The while Statement cin within a while Loop The for.
A FIRST BOOK OF C++ CHAPTER 5 REPETITION. OBJECTIVES In this chapter, you will learn about: The while Statement Interactive while Loops The for Statement.
A First Book of C++ Chapter 5 Repetition.
LAB SESSION ONE DIMENSIONAL ARRAY.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
COMP Loop Statements Yi Hong May 21, 2015.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
COMP 2710 Software Construction Flow of Control – switch and loops Programming Exercises Dr. Xiao Qin Auburn University
Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased.
Chapter Topics 11.1 Introduction to Menu-Driven Programs
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Chapter 4: Making Decisions.
How to Create a KPI Dashboard Report
Looping III (do … while statement)
CHAPTER 4 Iterative Structure.
EECE.2160 ECE Application Programming
Learning Intention I will learn about the standard algorithm for input validation.
Presentation transcript:

1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises

2 Introducing Structured Choice 4 Structured choice can be implemented with switch~case construct. 4 switch(variable) { 4 case x: {………} break; 4 case y: {………} break; 4 case z: {……….} break; 4 default: {……..} break; 4}4} 4 When should we prefer switch-case over if-else? 4 Why is a default case added at the end? 4 Is it ok to use floating point values in switch-case statements?

3 Using a do-while loop 4 You should use a do~while loop if you wish to run the loop body at least once before testing the condition 4 For example, a menu driven program should display all the choices and then accept user input. Next, the user input can be tested for validity. If invalid, run the loop body again

4 Do~While Loop 4 do { 4:4: 4:4: 4:4: 4:4: 4:4: 4 } while (condition);

5 Do-While + Switch-Case Demo 4 Write a program that displays menu choices for computing a shopping invoice. The choices include entering total number of items, entering prices of all the items, viewing the invoice with prices and sales tax followed by Grand Total, printing the invoice, saving the invoice to a file and exiting the program

6 Lab Exercise (Demo Required on Oct 19) 4 Develop a program that accepts several integers from the keyboard (range:1 to 25) and prints their values followed by their bar charts and finally their average. Program must ask the user the number of values in advance and it must check for valid numbers. Invalid numbers are rejected but the user is given a chance to enter all the numbers.

7 Test Data and Expected Output 4 Input number of values=9 4 Values entered: {2,-3,4,9,22,12,25,20,18,23} 4 2: ** 4 4: **** 4 9: ********* 4 22: ********************** 4 12: ************ 4 25: ************************* 4 20: ******************** 4 18: ****************** 4 23: *********************** 4 Average is 15

8 Practice Exercises 4 Design a program that: 4 prompts the user to input the salary for tax computation 4 Checks the user input to see if it is within the given salary range ( ) 4 If not, it gives a warning beep and re- displays the prompt on a clean screen. 4 Use do-while{} loop and see how the screen can be cleared between menu displays

9 More Exercises for Practice 4 Programming Problem 2 page 301 (old edition see page 306) 4 Exam Preparation Exercise 10 page 298 (old edition see page 303) 4 Exam Preparation Exercise 12 page 299 (old edition see page 304)