12.2 Program Design (3)
Resources |
Revision Questions |
Computer Science
Login to see all questions
Click on a question to view the answer
1.
A software development team is tasked with creating a program to manage a library's book collection. The program needs to allow users to add new books, search for books by title or author, and remove books from the collection. Describe, using a structure chart, how you would decompose this problem into sub-tasks. Clearly indicate the parameters passed between the modules/procedures/functions involved in the algorithm design. Your structure chart should be at least three levels deep.
Structure Chart:
The top-level module would be 'Library Management System'. It calls upon sub-modules for specific tasks.
Level 1:
- Library Management System: This is the main module.
- Book Management: Handles adding, searching, and removing books.
- User Interface: Provides the user interaction (e.g., menus, input fields, output display).
Level 2:
- Book Management:
- Add Book: Takes book details (title, author, ISBN, publication year) as input. Parameters: book_details (a structure containing the book information).
- Search Book: Takes a search term (title or author) as input. Parameters: searchterm (a string), booklist (a list of book structures). Returns: found_book (a book structure or null).
- Remove Book: Takes the ISBN of the book to remove as input. Parameters: isbn (a string), booklist (a list of book structures). Returns: updatedbook_list (a list of book structures).
- User Interface:
- Display Menu: No parameters. Returns: None.
- Get User Input: Takes a menu choice as input. Parameters: menuchoice (an integer). Returns: userchoice (an integer).
- Display Book List: Takes a list of book structures as input. Parameters: book_list (a list of book structures). Returns: None.
Relationships:
Library Management System calls Book Management and User Interface. |
Book Management calls Add Book, Search Book, and Remove Book. |
User Interface calls Display Menu and Get User Input. |
2.
Consider a system for calculating the area of different geometric shapes. Describe, using a structure chart, how you would decompose this problem into sub-tasks. Clearly indicate the parameters passed between the modules/procedures/functions involved in the algorithm design. Your structure chart should be at least three levels deep.
Structure Chart:
The top-level module is 'Area Calculator'. It delegates calculations to specific shape modules.
Level 1:
- Area Calculator: The main module.
- Shape Calculation: Handles the area calculation for different shapes.
Level 2:
- Shape Calculation:
- Calculate Circle Area: Takes the radius as input. Parameters: radius (a float). Returns: area (a float).
- Calculate Rectangle Area: Takes the length and width as input. Parameters: length (a float), width (a float). Returns: area (a float).
- Calculate Triangle Area: Takes the base and height as input. Parameters: base (a float), height (a float). Returns: area (a float).
Relationships:
Area Calculator calls Shape Calculation. |
Shape Calculation calls Calculate Circle Area, Calculate Rectangle Area, and Calculate Triangle Area. |
3.
Describe the key components of a state-transition diagram. Include a description of the symbols used to represent states, transitions, and initial/final states. Provide a brief example of how these components would be used to model a simple real-world process.
The key components of a state-transition diagram are:
- States: Represented by circles or ovals. Each state represents a distinct condition or stage in the algorithm.
- Transitions: Represented by arrows connecting states. Each arrow indicates a transition from one state to another, triggered by a specific event or condition.
- Initial State: Indicated by a filled-in circle. This is the state the algorithm starts in.
- Final State(s): Indicated by a double-filled-in circle. This represents the state the algorithm reaches upon completion. An algorithm can have multiple final states, representing different successful outcomes.
- Events/Triggers: Labels on the transitions that specify the event or condition that causes the transition to occur.
Example: Consider modeling a simple traffic light system.
States: Green, Yellow, Red |
Transitions: - Green -> Yellow (Timer Expires)
- Yellow -> Red (Timer Expires)
- Red -> Green (Timer Expires)
|
Initial State: Red (Traffic starts at red) |
Final State: (The diagram implies a cyclical process, so there isn't a single final state in the traditional sense. The cycle continues indefinitely.) |
This diagram clearly shows the sequence of states and the events that trigger the transitions, making the traffic light logic easy to understand.