Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter Topics 11.1 Introduction to Menu-Driven Programs

Similar presentations


Presentation on theme: "Chapter Topics 11.1 Introduction to Menu-Driven Programs"— Presentation transcript:

1

2 Chapter Topics 11.1 Introduction to Menu-Driven Programs
11.2 Modularizing a Menu-Driven Program 11.3 Using a Loop to Repeat the Menu 11.4 Multiple-Level Menus

3 11.1 Introduction to Menu-Driven Programs
A menu is a list of operations that are displayed by a program, in which a user can select which operations to perform Figure A menu

4 11.1 Introduction to Menu-Driven Programs
A decision structure can be used to perform menu selections This can be accomplished through a case structure, series of nested if-then-else statements A case structure is easier to follow the flow A case structure will provide a case for each option in the menu, in addition to a default case

5 11.1 Introduction to Menu-Driven Programs
Figure Flowchart for Program 11-1

6 11.1 Introduction to Menu-Driven Programs
Validating the menu selection can be done before the case is processed, allowing for no need for a default Display “Enter your selection” Input menuSelection //validation While menuSelection < 1 OR menuSelection >3 Display “That is an invalid selection. Enter 1, 2 or 3” End While

7 11.2 Modularizing a Menu-Driven Program
Since a menu-driven program is capable of performing many tasks, it should be put into modules A module should be written for each case that could be processed The options would simply call modules Allows for a clear flow of the program

8 11.2 Modularizing a Menu-Driven Program
Figure Flowchart for the main module in Program 11-3

9 11.3 Using a Loop to Repeat the Menu
Most menu-driven programs use a loop to repeatedly display the menu after a task is performed This allows the user of the program to run another option without restarting the program The menu can also contain on option for ending the program Display “1. Convert inches to centimeters.” Display “2. Convert feet to meters.” Display “3. Convert miles to kilometers.” Display “4. End the program.”

10 11.3 Using a Loop to Repeat the Menu
Figure 11-7 Flowchart for the main module in Program 11-5

11 11.4 Multiple-Level Menus A multiple-level menu has a main menu and one or more submenus Some complex programs require more than one menu A programmer should consider breaking up long menus into multiple menus This is essentially nested case structures

12 11.4 Multiple-Level Menus Instead of this type of long menu
Process a sale Process a return Add a record to the inventory file Search for a record in the inventory file Modify a record in the inventory file Delete a record in the inventory file Print an inventory list report Print a list of inventory items by cost Print a list of inventory items by age Print a list of inventory items by retail value

13 11.4 Multiple-Level Menus Convert to multiple menus such as Main Menu
Process a Sale or a Return Update the Inventory File Print an Inventory Report Exit the Program Sales and Returns Menu Process a Sale Process a Return Go Back to the Main Menu

14 11.4 Multiple-Level Menus More menus Update Inventory File Menu
Add a Record Search for a Record Modify a Record Delete a Record Go Back to the Main Menu

15 11.4 Multiple-Level Menus More menus Inventory Report Menu
Print an inventory list report Print a list of inventory items by cost Print a list of inventory items by age Print a list of inventory items by retail value Go Back to the Main Menu


Download ppt "Chapter Topics 11.1 Introduction to Menu-Driven Programs"

Similar presentations


Ads by Google