Entity-Relationship Diagrams and User-Interface Design

UNIT 2 • MODULE 2 • LESSON 06

The library’s data has to live somewhere. In Lesson 04 the DFD showed data stores called Members, Books and Loans, and the data dictionary listed their fields. Before anyone builds a database or writes C structures, the designer must decide exactly which things the system stores data about and how those things are related. The tool for that is the entity-relationship diagram (ERD), a semantic data model. The second half of this lesson turns to the part of the design that people actually see: screens and reports.

What you will learn

  • Entities, attributes, primary keys and foreign keys.
  • Relationships and their cardinality: one-to-one, one-to-many and many-to-many.
  • How to read and draw an ERD in crow’s foot notation.
  • How to resolve a many-to-many relationship with a link entity.
  • How an entity becomes a C struct.
  • Guidelines for good screens, reports and user interfaces, and how to critique a poor design.

Part 1: Entities, attributes and keys

TermMeaningLibrary example
EntityA thing (person, object, event or idea) about which the system stores data. Written as a singular noun, often in capitals.MEMBER, BOOK, LOAN
AttributeA property of an entity; one data item.Name, Phone, Title, DueDay
Primary key (PK)An attribute (or set of attributes) whose value is unique for every occurrence of the entity.MemberID, BookID, LoanID
Foreign key (FK)An attribute in one entity that is the primary key of another entity, used to link them.MemberID inside LOAN

Primary keys are usually shown underlined. Names are poor primary keys because two members can share a name; that is why systems invent ID numbers. A foreign key is how a relationship is actually stored: each LOAN record holds the MemberID of the member who made it.

Part 2: Relationships and cardinality

A relationship is a link between entities, described with a verb (a member makes a loan). Its cardinality (or degree) says how many occurrences of one entity can be linked to one occurrence of the other.

CardinalityMeaningExample
One-to-one (1:1)Each A is linked to at most one B, and each B to at most one A.Each school has one principal; each principal leads one school.
One-to-many (1:M)Each A can be linked to many B, but each B to only one A.One member makes many loans; each loan is made by one member.
Many-to-many (M:N)Each A can be linked to many B, and each B to many A.A member borrows many books over time; a book is borrowed by many members.

Crow’s foot notation

In crow’s foot notation, the relationship is a line between entity boxes. A short bar (or two bars) at an end means “one”; a three-pronged crow’s foot means “many”. Read each end separately: stand at one entity, look along the line, and read the symbol at the far end.

MEMBERMemberIDNamePhoneLOANLoanIDMemberID (FK)BookID (FK)LoanDayDueDayBOOKBookIDTitleAuthormakesis in
ER diagram for the library, in crow’s foot notation. Two bars mean exactly one; the crow’s foot means many.

Reading the ERD: from MEMBER, look towards LOAN and you see a crow’s foot, so one member makes many loans. From LOAN, look back towards MEMBER and you see bars, so each loan is made by exactly one member. The same pattern links BOOK and LOAN. Some textbooks use a different notation (Chen notation with diamonds and 1 and M labels). Either is acceptable if used consistently and clearly.

Resolving a many-to-many relationship

MEMBERBOOKborrows (many-to-many)
Before resolving: a member borrows many books, and a book is borrowed by many members over time.

Many-to-many relationships cannot be stored directly in a simple table or array, because there is nowhere to put “many” foreign keys on either side. The fix is to introduce a link entity (also called an associative or junction entity) between them. Here, MEMBER borrows BOOK (M:N) becomes MEMBER 1:M LOAN M:1 BOOK, which is the first ERD above. LOAN also turns out to be a natural place for the attributes that belong to the borrowing itself, such as LoanDay and DueDay.

Try it 1Name the cardinality

Choose the cardinality for each relationship.

Worked example: an ERD from a scenario

Scenario. An inter-island ferry company runs several vessels. Each vessel makes many sailings, and each sailing uses one vessel. Passengers make bookings; a passenger may make many bookings, and each booking is for one passenger on one sailing. A sailing can carry many bookings. The company records each vessel’s name and capacity, each sailing’s date and departure time, each passenger’s name and phone number, and each booking’s seat class.

StepWorking
1. Entities (nouns that need data stored)VESSEL, SAILING, PASSENGER, BOOKING. “Company” is the owner of the system, not an entity here.
2. AttributesVESSEL: name, capacity. SAILING: date, departure time. PASSENGER: name, phone. BOOKING: seat class.
3. Primary keysInvent unique IDs: VesselID, SailingID, PassengerID, BookingID.
4. Relationships (verbs)VESSEL makes SAILING; PASSENGER makes BOOKING; SAILING carries BOOKING.
5. CardinalityVESSEL 1 to M SAILING; PASSENGER 1 to M BOOKING; SAILING 1 to M BOOKING.
6. Foreign keysSAILING holds VesselID; BOOKING holds PassengerID and SailingID.
7. Check for M:NPASSENGER and SAILING are many-to-many (a passenger takes many sailings; a sailing carries many passengers), but BOOKING already resolves it as a link entity.

The finished ERD has four boxes in a row or a T-shape, three labelled relationship lines with bars at the “one” end and crow’s feet at the “many” end, primary keys underlined, and foreign keys marked. Notice that BOOKING plays the same role as LOAN in the library: it is the event that links two other entities and carries its own attributes.

Part 3: From ERD to C

The ERD is a design for the data, and in C each entity becomes a struct type, each attribute a field, and each foreign key an ordinary field holding another entity’s key. A collection of entity occurrences becomes an array of structs.

Worked example: the LOAN entity in C

#include <stdio.h>

/* One LOAN entity becomes one struct. */
struct Loan {
    int loanId;    /* primary key */
    int memberId;  /* foreign key */
    int bookId;    /* foreign key */
    int loanDay;
    int dueDay;
};

int main(void)
{
    struct Loan loans[3] = {
        {1, 1001, 52001, 10, 24},
        {2, 1002, 52007, 11, 25},
        {3, 1001, 52003, 15, 29}
    };
    int m = 1001;  /* member to look up */

    printf("Loans for member %d:\n", m);
    for (int i = 0; i < 3; i++) {
        struct Loan L = loans[i];
        if (L.memberId == m)
            printf("  loan %d: book %d, "
                   "due %d\n", L.loanId,
                   L.bookId, L.dueDay);
    }
    return 0;
}

Output:

Loans for member 1001:
  loan 1: book 52001, due 24
  loan 3: book 52003, due 29

Notice how the one-to-many relationship appears in code: to find all loans for one member, the program searches the loans array for records whose foreign key memberId matches. Loan 2 belongs to a different member, so it is skipped. In Lesson 07 this same struct is used in the full library program.

Part 4: Designing screens, reports and user interfaces

Interface design (Lesson 05) includes the user interface: the screens people use to enter and view data, and the reports the system prints or displays. A technically correct system with a confusing interface will cause errors and frustration, so usability (Lesson 01) depends heavily on this part of the design.

Guidelines for screens and forms

GuidelineWhat it means
Clear labelsEvery field has a short, plain-language label next to it. Avoid codes and abbreviations users may not know.
Readable textUse a clear font at a comfortable size; avoid all capitals for long text.
Colour and contrastUse strong contrast between text and background; never use colour alone to carry meaning; use few colours.
Layout and spacingGroup related fields; align fields; leave white space; order fields in the order users think (name, then contact, then address).
ConsistencySame button names, positions and colours on every screen; same date format everywhere.
Suitable field sizes and formatsSize boxes to fit the data; show the expected format (DD/MM/YYYY); offer drop-down lists or calendars where possible to reduce typing.
Prevent and handle errorsValidate input; keep dangerous actions (delete) away from common ones and ask for confirmation.
Helpful messagesError messages say what went wrong and how to fix it, in plain words.
FeedbackConfirm actions (“Member saved”) and show progress for slow tasks.

Guidelines for reports

  • A clear title, plus the date and time the report was produced.
  • Column headings, with units where needed.
  • Data sorted in a useful order (for example by surname or by days overdue).
  • Numbers right-aligned, with totals or counts where useful.
  • Page numbers (“Page 2 of 5”) on printed reports.
  • Only the data the reader needs; summary first, detail after.

Critiquing a poor design

MEMBER REG FORM V2 FINAL1nm2Ph#3D.O.B (YYYYDDMM)4AddressGO!!Del5ERROR 0x3F: INVALID INPUT6All fields required. Press GO!! to save or Del to delete everything.
A deliberately poor screen design. Each numbered flaw breaks a guideline from Part 4.

Try it 2Which guideline is broken?

Match each numbered flaw on the poor screen to the guideline it breaks most clearly.

A redesigned screen would have a calm, high-contrast colour scheme; a title such as “Register a new member”; labelled fields for First name, Surname, Phone (7 digits) and Date of birth (DD/MM/YYYY, with a calendar); a clear “Save member” button; a separate “Cancel” button; no delete button on a registration form; and error messages next to the field they refer to.

Try it 3ERD and interface drill

“ERD” checks data modelling. “Interface” checks screen and report guidelines.

Common mistakes

  • Drawing an attribute (such as Phone) as an entity.
  • Choosing a name as a primary key. Names are not unique.
  • Reading crow’s foot notation from the wrong end. Stand at one entity and read the symbol at the other end.
  • Leaving a many-to-many relationship unresolved when the question asks for a design that could be implemented.
  • Critiquing a screen with vague comments such as "it looks bad". Name the guideline and the specific flaw.
  • Reusing a textbook or specimen scenario word for word. Practise on your own scenarios so that you understand the method.

Summary

IdeaKey point
Entity, attributeA thing stored about; one of its properties.
KeysPrimary key unique; foreign key links to another entity’s primary key.
Cardinality1:1, 1:M, M:N; crow’s foot means many.
M:NResolve with a link entity holding both foreign keys.
CEntity becomes a struct; occurrences become an array of structs.
ScreensLabels, readability, contrast, layout, consistency, formats, error prevention, helpful messages, feedback.
ReportsTitle, date, headings, sorted, aligned, totals, page numbers.

Review questions

1. Define entity, attribute and primary key.

Show answer

An entity is a thing about which data is stored. An attribute is a property of an entity. A primary key is an attribute whose value uniquely identifies each occurrence of the entity.

2. What is a foreign key? Give an example from the library ERD.

Show answer

An attribute in one entity that is the primary key of another, used to link them. MemberID in LOAN is a foreign key referring to MEMBER.

3. Explain the three types of relationship cardinality with an example of each.

Show answer

One-to-one: each country has one capital city. One-to-many: one customer places many orders. Many-to-many: students and clubs.

4. A sports academy has COACHes and ATHLETEs. Each athlete has one coach; a coach trains many athletes. Describe the ERD.

Show answer

Two entities, COACH (CoachID PK, Name) and ATHLETE (AthleteID PK, Name, CoachID FK), joined by a one-to-many relationship "trains", with bars at COACH and a crow’s foot at ATHLETE.

5. Why must a many-to-many relationship be resolved, and how?

Show answer

It cannot be stored directly because neither side can hold many foreign keys. Add a link entity whose primary key includes both foreign keys, giving two one-to-many relationships.

6. State FOUR guidelines for designing a data entry screen.

Show answer

Any four: clear labels; readable font; good colour contrast; logical grouping and spacing; consistency; field sizes and formats that match the data; validation and confirmation for dangerous actions; helpful error messages; feedback.

7. State THREE features of a well-designed printed report.

Show answer

Any three: title; date and time; column headings; sorted data; right-aligned numbers; totals; page numbers.

Homework

  1. A music school has TEACHERs, STUDENTs and INSTRUMENTs. A teacher teaches many students; a student studies one or more instruments; an instrument is studied by many students. Draw the ERD, resolving any many-to-many relationship, and list a primary key for each entity.
  2. Write a C struct for one of your entities and a short program that prints all records matching a foreign key.
  3. Find a real form (paper or online) and critique it against at least five guidelines from Part 4.
  4. Design a printed "Overdue loans" report for the library, showing headings and two sample rows.

Mastery quiz: ER diagrams and interface design

This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.

Mastery quiz: Entity-Relationship Diagrams and User-Interface Design

Your course badges: loading saved progress…

View badges

    No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.

    Saved in this browser on this device. Clearing browser data may remove your badges.

    Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.

    1. In an ERD, a thing about which data is stored is a
    2. Which is the best primary key for STUDENT?
    3. A field in one table that refers to the primary key of another is a
    4. One customer, many orders, each order one customer. Cardinality?
    5. In crow’s foot notation, the three-pronged symbol means
    6. A many-to-many relationship is resolved by
    7. In C, an entity is most naturally represented as
    8. Which is a helpful error message?
    9. Putting a Delete button right beside Save breaks which guideline?
    10. Which feature belongs on a printed report?

    Exam tips

    Specimen Unit 2 Paper 01 (2021), Item 16. You are shown an ER diagram and asked to read a relationship from it. Read each end of the line separately, as in Part 2, and say the sentence aloud: "one A has many B".

    Specimen Unit 2 Paper 02 (2021), Question 4(b). You must produce an ER model from a written scenario. Method: underline nouns that need data stored (entities); note their properties (attributes); pick a unique key for each; underline verbs that link entities (relationships); decide the cardinality of each from the scenario wording; resolve any many-to-many with a link entity if the question asks for an implementable model. Label every relationship and show keys. Practise with your own scenarios, such as the music school in the homework.

    Previous: Unit 2 • Module 2 • Lesson 05 – Software Design: Architecture, Structure Charts and Design Strategies. Next: Unit 2 • Module 2 • Lesson 07 – From Design to Code: The Implementation Phase in C.

    Syllabus link: CAPE Computer Science (CXC A19/U2/21), Software Engineering (Unit 2, Module 2). Specific Objective 5 (second part): semantic data models (entity-relationship diagrams); guidelines for the design of screens, reports and user interfaces.

    Video search terms

    Search YouTube for: "entity relationship diagram crow’s foot tutorial", "resolve many to many relationship link entity", "primary key foreign key explained", "user interface design principles for beginners".

    Try it 4Quick quiz

    Tap an answer. All eight questions are self-checks on this lesson.

    Updates

    2026/12/01

    - First version of the lesson.

    © 2026 islandclass.org

    Leave a Reply