1 Lab Session-VII CSIT-121 Fall 2000 4 Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While.

Slides:



Advertisements
Similar presentations
Control Structures Corresponds with Chapters 3 and 4.
Advertisements

Computer Science 1620 Loops.
COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
1 Lab Session-II CSIT 121 Fall 2000 Visual Studio Introduction Lab-1 Explanation and Demos Debugging Tips How to add new files to your projects How many.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Loop variations do-while and for loops. Do-while loops Slight variation of while loops Instead of testing condition, then performing loop body, the loop.
1 Lab Session-2 CSIT 121 Spring 2005 Debugging Tips NiMo’s Varying Rates Lab-2 Exercise.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
Computer Science 1620 Programming & Problem Solving.
Summary of Loops Programming. COMP102 Prog Fundamentals I: Summary of Loops /Slide 2 Which Loop to Use? l for loop n for calculations that are repeated.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
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.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
1 Lab Session-9 CSIT-121 Fall 2003 w Random Number Generation w Designing a Game.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
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.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
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.
High-Level Programming Languages: C++
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Chapter 4: Looping. Resource: Starting Out with C++, Third Edition, Tony Gaddis 5.1 The Increment and Decrement Operators ++ and -- are operators that.
Chapter 4 Selection Structures: Making Decisions.
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
Incremental operators Used as a short-hand i++ or ++i  ==  i = i + 1 i-- or --i  ==  i = i – 1 i += a  ==  i = i + a i -= a  ==  i = i - a i *=
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Chapter 5 Repetition and Loop Statements Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville,
Previously Repetition Structures While, Do-While, For.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
1 Programming Environment and Tools VS.Net 2012 First project MSDN Library.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Iteration Hussein Suleman UCT Dept of Computer Science CS115 ~ 2004.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 CS161 Introduction to Computer Science Topic #8.
Loops and Files. 5.1 The Increment and Decrement Operators.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
COMP Loop Statements Yi Hong May 21, 2015.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
1 ICS103 Programming in C Lecture 7: Repetition Structures.
C++ Programming: CS102 LOOP. Not everything that can be counted counts, and not every thing that counts can be counted. −Albert Einstein Who can control.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Lab 4: Loops and Iteration Graham Northup
Introduction to Computer Programming
Chapter 4: Making Decisions.
Looping III (do … while statement)
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Chapter 4 Repetition Structures
Presentation transcript:

1 Lab Session-VII CSIT-121 Fall Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While Loop variations 4 Lab Exercises

2 Revising Structured Choice 4 Structured choice can be implemented with switch~case construct. 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 The counter-controlled loop 4 The for loop is best for implementing a counter controlled loop. 4 For example, we can convert a given while loop into for loop to show how it works

4 The for loop 4 int count=0; 4 while (count<20) { 4 cout >thisID; count++;} 4 Changed to: 4 int count=0; 4 for (count=0; count<20; count++) 4 {cout >thisID; }

5 Lab Exercises Review 4 Library catalogue menu selection with beeps on wrong input 4 Beeps can be generated by printing “\a” 4 List of upper and lower case letters 4 The for loop has multiple increment expressions 4 The for loop can also have null expressions 4 e.g. for (; ;){cout<<“Will it end?\n”;}

6 Visual Studio Debugger 4 Debugging is quite flexible in Visual Studio 4 You can start debugging by first deciding about the breakpoints in your program 4 Once breakpoints are inserted, you can choose Build==>start debug==>go or step-into 4 This causes a new menu option Debug to appear in your main menu 4 Once the program is halted at a breakpoint, you can choose several options

7 Visual Studio Debugger 4 From a break point: 4 You can step-into functions(i.e. execute even the standard C++ library functions) 4 You can step-over functions(i.e. skip the standard functions and just go to your code) 4 You can step-out of a function 4 Instead of single stepping, it is advised to set breakpoints and use go option

8 While Loop Design 4 Design While loop with care else the program will be stuck in INFINITE LOOP. 4 Check for these three conditions 4 INITIALIZATION (The loop control variable should be initialized before starting the loop) 4 TESTING While(test) {…..} 4 UPDATE Loop control variable should be updated within the loop

9 While Loop Design 4 Lab Exercise: HiLo Game (Demo needed) 4 What type of loop is needed? 4 Get User input 4 (if user input is not equal to key) 4 { display hints 4 get user input again} 4 A starting example follows:

10 An Example 4 #include 4 using namespace std; 4 #define MAX_LIMIT 99 4 void main() { 4 int key; 4 int seed=0; 4 while (seed<254) 4{4{ 4 srand(seed++); 4 key = rand()%MAX_LIMIT; 4 cout<<key<<endl; 4 }}

11 Do-While Loop 4 In the Hi-Lo algorithm, we have some redundant statements. Can you identify? 4 To get rid of the same, we can use the do{}- while loop instead of while{} 4 do-while loop makes sure that the loop is executed at least once. 4 It is recommended where it is necessary to run the loop at least once

12 Lab 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