Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following informal problem description: Many people need to know if food being served to them contains any particular ingredients that they cannot eat.

Consider the following informal problem description:

Many people need to know if food being served to them contains any particular ingredients that they cannot eat. Implement a function that applications can call to check whether all the dishes on a given menu are free from a specified ingredient.

What type of problem is this? Justify your answer.

Write your answer here.

(b)

Define a function that takes a menu comprising three dishes, and a specified ingredient, and outputs true if all the dishes on the menu are free from the specified ingredient. If any of the dishes on the menu contain the specified ingredient, the function outputs false.

A menu is represented as a list of three dishes.

A dish is represented as a non-empty list of non-empty strings, the first string being the name of the dish and the remaining strings being the ingredients of the dish.

A dish can have a name but no listed ingredients. Ingredients can be duplicated. If the name of the dish matches the specified ingredient, the function should output false.

For example, the menu:

Dish Ingredients
soup onion, potato, leek, celery
pizza bread, tomato, cheese, cheese
banana

would be represented in Python as:

menu = [ ['soup','onion','potato','leek','celery'], ['pizza','bread','tomato','cheese','cheese'], ['banana'] ]

This example menu is not free from banana.

Function:\free_from( Inputs:\Dish,a string Preconditions:\ Output:\ containsIngredient ,a boolean **Postconditions:if

(c) (10 marks)

Add three different test cases to the following test table for the free from ingredient function, where water is the specified ingredient.

We have started with a case where all three dishes have no ingredients. State, giving a reason, whether this is an edge case.

case menu ingredient output
all three dishes have no ingredients (('potato'), ('cheese'), ('apple')) 'water' True

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

understand the meaning of the terms discipline and grievance

Answered: 1 week ago