Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose Jane gets her groceries from several supermarkets, each with a different number of aisles. Suppose Jane gets items from two aisles per supermarket visit,

Suppose Jane gets her groceries from several supermarkets, each with a different number of aisles. Suppose Jane gets items from two aisles per supermarket visit, and to reduce the amount of carrying she needs to do, she places a basket at the beginning of one aisle. Assume that Jane will not visit the two aisles more than once. Jane wishes to know which aisle she should place her basket so that she can reduce the distance she needs to walk from where she places the basket to the start of the aisle she picks items from, and from the start of the aisle where she picks items from to the basket to place her picked items. Assume the aisles are 1 unit distance from one another. Write and express a program to perform the following tasks: Read the number of aisles in the supermarket that Janet is currently at. Read the two aisles Jane needs to get items from. You can assume that two numbers entered are between 1 and the number of aisles in the supermarket. Compute and display the minimum distance she needs to walk to the basket. You may apply any algorithm to compute the minimum distance. Refer to Figure Q1 for an example algorithm for how the minimum distance can be computed. Suppose there are 5 aisles in a particular supermarket, and Jane needs to pick items from aisle 1 and aisle 4, represented by X. If Jane places her basket in front of aisle 3, represented by B, then the distance she needs to walk is (3-1) x 2 + (4-3) x 2 = 6 units.

Make TWO (2) copies of your answer to Question 1(a) and modify a copy for each of the two parts (i) and (ii). (i) Your program will first prompt for whether Jane needs to visit one aisle. If the first non-whitespace character of the input is y (case insensitive) the program displays the minimum distance as 0. Otherwise, the program prompts for the number of aisles in the supermarket and the two aisles that Jane needs to visit. As in Question 1(a), the program performs the same computation and displays the minimum distance. Example runs Run 1 Do you need to go to just one aisle? (yes/no): ya The minimum distance is 0 units Run 2 Do you need to go to just one aisle? (yes/no): nah Enter number of aisles in supermarket: 10 Enter first aisle: 4 Enter second aisle: 6 The minimum distance is 4 units (ii) Your program will first prompt for the number of aisles Jane needs to visit. If the number of aisles is 1, the minimum distance is 0. If the number of aisles is 2, the program prompts for the number of aisles in the supermarket and the two aisles that Jane needs to visit. As in Question 1(a), the program performs the same computation and displays the minimum distance. If the number of aisles is any other number other than 1 or 2, the program displays the error message: Invalid number of aisles for Jane! Example runs Run 1 Enter the number of aisles to visit: 1 The minimum distance is 0 units Run 2 Enter the number of aisles to visit: 2 Enter number of aisles in supermarket: 10 Enter first aisle: 4 Enter second aisle: 6 The minimum distance is 4 units Run 3 Enter the number of aisles to visit: 5 Invalid number of aisles for Jane! (6 marks) ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 5 of 16 (c) Make TWO (2) copies of your answer to Question 1(a) and modify a copy for each of the two parts (i) and (ii). (i) Your program will first prompt for the number of supermarkets Jane has to visit. For each visit, prompt for the number of aisles the supermarket has and the two aisles Jane has to visit. As in Question 1(a), the program performs the same computation and displays the minimum distance for each supermarket visit. Example run Enter number of supermarkets to visit: 3 Enter number of aisles in supermarket 1: 5 Enter first aisle: 1 Enter second aisle: 4 The minimum distance is 6 units Enter number of aisles in supermarket 2: 10 Enter first aisle: 4 Enter second aisle: 6 The minimum distance is 4 units Enter number of aisles in supermarket 3: 100 Enter first aisle: 1 Enter second aisle: 2 The minimum distance is 2 units (ii) Your program will first prompt for the number of aisles the supermarket has. The program then repeatedly prompts for the aisle numbers that Jane needs to visit. When 0 is entered, the input for aisle numbers is terminated. The program computes the minimum distance based on the best location Jane place her basket and the number of aisles she needs to pick items from. The program then displays the minimum distance. Example runs Run 1 Enter number of aisles in supermarket: 100 Enter the aisle number to visit: 1 Enter the aisle number to visit: 8 Enter the aisle number to visit: 5 Enter the aisle number to visit: 4 Enter the aisle number to visit: 10 Enter the aisle number to visit: 0 The minimum distance is 26 units Run 2 Enter number of aisles in supermarket: 100 Enter the aisle number to visit: 1 Enter the aisle number to visit: 0 The minimum distance is 0 units Run 3 Enter number of aisles in supermarket: 100 Enter the aisle number to visit: 0 Not visiting any aisle

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions