Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1

2 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

3 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.

4 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?

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

6 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; }

7 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)

8 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 email message addressed to “zubairi@cs.fredonia.edu”

9 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)

10 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

11 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)

12 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

13 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


Download ppt "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."

Similar presentations


Ads by Google