4 Algorithms and flowcharts (3)
Resources |
Revision Questions |
Information Technology IT
Login to see all questions
Click on a question to view the answer
1.
You are given the following flowchart (see below). Describe, in plain English, what the flowchart represents. Identify any potential problems or inefficiencies in the process depicted. Suggest at least two improvements to the flowchart to make it more efficient or robust.
Flowchart Description:
The flowchart represents a process for a user logging into a system. The user enters a username and password. The system checks if the username and password match the stored credentials. If they match, the user is granted access. If not, an error message is displayed, and the user is prompted to try again. The process repeats until the user successfully logs in or gives up.
Potential Problems/Inefficiencies:
- Infinite Loop: The flowchart doesn't explicitly show a mechanism for the user to give up or exit the login process. This could lead to an infinite loop if the user repeatedly enters incorrect credentials.
- Security Risk: The flowchart doesn't show any security measures to prevent brute-force attacks (e.g., account lockout after multiple failed attempts).
- Lack of Error Handling: The flowchart only handles incorrect credentials. It doesn't address other potential errors, such as a database connection failure.
Suggested Improvements:
- Add an 'Exit' point: Include a decision point to allow the user to explicitly exit the login process. This would prevent an infinite loop.
- Implement Account Lockout: Add a process to lock the account after a certain number of failed login attempts. This would mitigate brute-force attacks. This could be represented by a process that sets a flag and a decision to check the flag.
2.
A shop is offering a discount on items. If a customer spends over £50, they receive a 10% discount. If a customer spends between £20 and £50 (inclusive), they receive a 5% discount. If a customer spends less than £20, they receive no discount. Write an algorithm to calculate the final price a customer pays, given their original spending amount.
Algorithm:
- Start
- Get the customer's spending amount (let's call it
amount
). - If
amount
> 50 then:- Calculate the discount amount:
discount = amount * 0.10
- Calculate the final price:
final_price = amount - discount
- Else If
amount
>= 20 and amount
then:- Calculate the discount amount:
discount = amount * 0.05
- Calculate the final price:
final_price = amount - discount
- Else:
- End (Output:
final_price
)
Pseudocode:
START
INPUT amount
IF amount > 50 THEN
discount = amount * 0.10
final_price = amount - discount
ELSE IF amount >= 20 AND amount
3.
A company is designing a system for processing customer orders. Outline a flowchart, using standard flowchart symbols, to illustrate the process of a customer placing an order, the system validating the order details, and the system fulfilling the order. Your flowchart should clearly show decision points and potential error handling. Assume the system requires a valid credit card number and sufficient stock.
Flowchart Outline:
- Start (Oval)
- Customer places order (Rectangle)
- System validates order details (e.g., address, items) (Process)
- Is order details valid? (Diamond)
- Yes -> Check stock levels (Process)
- No -> Display error message & Return to Customer (Process) -> End (Oval)
- Are stock levels sufficient? (Diamond)
- Yes -> Process Payment (Process)
- No -> Display 'Out of Stock' message & Return to Customer (Process) -> End (Oval)
- Payment successful? (Diamond)
- Yes -> Allocate stock (Process) -> Generate Order Confirmation (Process) -> End (Oval)
- No -> Display 'Payment Failed' message & Return to Customer (Process) -> End (Oval)
Flowchart Symbols Used:
- Oval: Start/End
- Rectangle: Process
- Diamond: Decision