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.

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

Arrays and Other Data Structures 4 Introduction to Arrays 4 Bounds and Subscripts 4 Character Arrays 4 Integer Arrays 4 Floating Point Number Arrays 4.
1 Lab Session-VI CSIT-120 Fall 2000 Let us look at C++ syntax rules in brief Next, we complete the lab session-V Lab session-VI deals with functions (OPTIONAL)
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
Announcements The first graded lab will be posted Sunday 2/15 and due Friday 2/27 at midnight It is brand new, so please don’t hand in last semester’s.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
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.
1 Lab Session-VI CSIT-120 Spring 2001 Let us look at C++ syntax rules in brief Exercise VI-A (Demo Required) Lab Assignment#4 Due May 1st, 2001 (No Lab.
Chapter 5: Loops and Files.
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.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS 1 Lesson 5 Loops and Files CS 1 -- John Cole.
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-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.
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.
Today’s Lecture  Boolean Expressions  Building, Evaluating & Precedence Rules  Branching Mechanisms  if-else  switch  Nesting if-else  Loops  While,
Chapter 5: Control Structures II (Repetition)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
WEB PRICING SYSTEM User Manual. Click here to Log In The Defense Commissary Agency Vendor Price Change system is located at
General Programming Introduction to Computing Science and Programming I.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
CONTROLLING PROGRAM FLOW
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
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.
Fundamental Programming: Fundamental Programming Introduction to C++
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Functions.
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.
CPS120: Introduction to Computer Science Lecture 14 Functions.
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
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++ 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.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Chapter 5 Repetition. 2 Objectives You should be able to describe: The while Statement cin within a while Loop The for Statement The do Statement Common.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
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.
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.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
REPETITION CONTROL STRUCTURE
Objectives Identify the built-in data types in C++
Variables A piece of memory set aside to store data
TOPIC 4: REPETITION CONTROL STRUCTURE
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
3.5- The while Statement The while statement has the following syntax:
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Presentation transcript:

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

2 Menu-Driven Software Developing a menu-driven software requires displaying a menu and rejecting illegal values for the choice. A menu can be kept on the screen until the user makes a legal choice On bad choice, user must be given some feedback and the menu should be displayed again.

3 Menu-Driven Software Example Download and run the sample program provided on the course homepage under the link “menus” What input number causes the program to display the menu again? When does it finish executing?

4 Exercise 5-A Let us do an exercise to develop a menu for a flight reservation system once a flight has been selected.

5 Startup Source Code For this exercise, the startup source code is given below. Cut and paste into C++ to get started (Maximum 5 menu options) #include void main() { char tmpbuf[128]; _tzset(); _strtime( tmpbuf ); cout<< "Current time:\t\t\t\t"<< tmpbuf<<endl; _strdate( tmpbuf ); cout<<"Today's date:\t\t\t\t"<< tmpbuf<<endl; cout<<"**************************************************"<<endl; cout<<"Welcome to Flight Information & Reservation System"<<endl; cout<<" NAA (Never-on-Time Airlines)"<<endl; cout<<"**************************************************"<<endl; }

6 While and do-while statements It is good to use do-while{} because it will execute the loop at least once. The plain while{} will first test the condition and then execute the loop Experiment 5.1 Experiment 5.2 (Compile and run then modify and compare)

7 Lab Assignment#4 Due 11/9 Post Lab Problems on Page 75 of Lab manual –Exercise#1: Problem 5.2 –Exercise#2: Problem 5.6 Send the source code in plain text form in an message addressed to

8 Lab V cont’d: The if Statement The ‘if’ statement is very useful in selecting one of the options Lab Exercise 5-B Develop a program for registration of courses that accepts a student status (F,H) and displays proper warnings about a section that is full (Rules: If the course has some space and the student is a freshman, the student is given a standby registration else the student is given final registration. If the course is full and the student is an Honors student, the student is admitted into the course else rejected)

9 The if Statement The ‘if’ statement can be used to protect against errors. Lab-Exercise 5-C Modify the previous program to check for a wrong status entry by a student. (Example: If a student entered the status as ‘G’, the program should reject it immediately) Put the program in a while loop to continue until it gets the right status

10 The for Statement “for” is a loop statement that is controlled through a loop control variable for (lcv=1; lcv<=100; lcv++) The above loop will start with lcv=1 and it will run until lcv equals 100. The step size is 1 (lcv++) Compare it to the above for (lcv=1; lcv<=100; lcv+=2)

11 The for Statement “for” statement and while statement can produce identical loops “for” is preferred if the number of iterations is known beforehand. “while” is preferred if the total iterations cannot be computed in advance Experiment 5.8

12 Logical Operators Logical AND is represented by && Logical OR is represented by || Logical NOT is represented by ! Comparing if equal is represented by == Example: Write a logical expression to be true if x is restricted between 1 and 100 Write a logical expression to check if x equals y- 50 and x is positive Experiment 5.5