IGCSE cs 0478 2023 Nov 22 11
IGCSE cs 0478 2023 Nov 22 11
A wood flooring company stores the names of up to 100 customers in a one‑dimensional (1D) array Customers[]
. A two‑dimensional (2D) array Quotations[]
stores details of each customer’s quotation:
• length of room (one decimal place)
• width of room (one decimal place)
• area of wood required (rounded up to next whole number)
• choice of wood index (whole number)
• price of wood required in dollars (two decimal places).
The floor measurements (room length and room width) are taken in metres. All floors are rectangles and room measurements must be between 1.5 and 10.0 inclusive.
The index of any customer’s data is the same in both arrays. For example, a customer named in index 4 of Customers[] corresponds to the data in index 4 of Quotations[]
The wood choices available are:
1
Laminate
29.99
2
Pine
39.99
3
Oak
54.99
The data are stored in two 1D arrays named WoodType[]
and Price[]
. The index of the wood type and price in their arrays share the same index number.
Write a program that meets the following requirements:
input a new customer’s name, room length and room width
check that each measurement is valid
output an error message and require the measurement to be re‑entered until it is valid
calculate the area of the room by multiplying together the length of the room and the width of the room
input the choice of wood and find its price per square metre
calculate the price of the wood needed
store all data in the relevant array
output the customer’s quotation to include: the name of the customer, the choice of wood and the calculated price of the wood required
continue to accept the next customer.
You must use pseudocode or program code and add comments to explain how your code works. You do not need to declare any arrays or variables; you may assume that this has already been done.
You will need to initialise WoodType[]
and Price[]
All inputs and outputs must contain suitable messages.
Python版初始化代码,练习的时候使用如下的代码
import string
import random
#################################################
# Declare
#################################################
customer_size = 100
customers = []
quotations = []
wood_type = ["Laminate", "Pine", "Oak"]
price = [29.99, 39.99, 54.99]
#################################################
# Initialize Data (not include)
#################################################
for customer_index in range(customer_size):
customers.append(''.join(random.choice(string.ascii_letters) for name_letter_index in range(6)))
quation_item = [0.0, 0.0, 0, 0, 0.0]
quotations.append(quation_item)
print(customers)
print(quotations)
#################################################
# For you to write
#################################################
图解

Python版答案
import string
import random
#################################################
# Declare
#################################################
customer_size = 100
customers = []
quotations = []
wood_type = ["Laminate", "Pine", "Oak"]
price = [29.99, 39.99, 54.99]
#################################################
# Initialize Data (not include)
#################################################
for customer_index in range(customer_size):
customers.append(''.join(random.choice(string.ascii_letters) for name_letter_index in range(6)))
quation_item = [0.0, 0.0, 0, 0, 0.0]
quotations.append(quation_item)
print(customers)
print(quotations)
#################################################
# For you to write
#################################################
current_customer = 0
cont = True
while cont:
customer_name = input("Input the customer’s name: ")
customers[current_customer] = customer_name
room_length = float(input("What is the length of your room: "))
while room_length < 1.5 or room_length > 10.0:
print("The measurement must be in the range 1.5 to 10.0 inclusive, please try again ")
room_length = float(input("What is the length of your room: "))
room_width = float(input("What is the width of your room: "))
while room_width < 1.5 or room_width > 10.0:
print("The measurement must be in the range 1.5 to 10.0 inclusive, please try again ")
room_width = float(input("What is the width of your room: "))
room_area = round(room_length, 1) * round(room_width, 1)
room_area = round(room_area + 0.5, 1)
print("the wood choices available are: ")
print("Number Wood Type Price($)")
for i in range(3):
print(i + 1, " ", wood_type[i], " ", price[i])
wood_choice = int(input("Input a number from 1 to 3: "))
while wood_choice < 1 or wood_choice > 3:
print("number valid, 1 to 3: ")
wood_choice = int(input("Input a number from 1 to 3: "))
wood_cost = round(room_area * price[wood_choice - 1], 2)
quotations[current_customer][0] = room_length
quotations[current_customer][1] = room_width
quotations[current_customer][2] = room_area
quotations[current_customer][3] = wood_choice
quotations[current_customer][4] = wood_cost
print("Customer name: ", customers[current_customer])
print("The wood you have chosen is: ", wood_type[wood_choice - 1])
print("Your total price is: ", quotations[current_customer][4])
current_customer = current_customer + 1
if current_customer > 100:
current_customer = 1
print(customers)
print(quotations)
Last updated
Was this helpful?