8.2. Arrays
A subsection of Computer Science, 0478, through 8. Programming
Listing 5 of 5 questions
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: Index Wood type Price per square metre ($) Laminate 29.99 Pine 39.99 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.
0478_w23_qp_22
THEORY
2023
Paper 2, Variant 2
The one-dimensional (1D) array TeamName contains the names of teams in a sports league. The two-dimensional (2D) array TeamPoints contains the points awarded for each match. The position of each team’s data in the two arrays is the same. For example, the team stored at index 10 in TeamName and TeamPoints is the same. The variable LeagueSize contains the number of teams in the league. The variable MatchNo contains the number of matches played. All teams have played the same number of matches. The arrays and variables have already been set up and the data stored. Each match can be played at home or away. Points are recorded for the match results of each team with the following values: • 3 – away win • 2 – home win • 1 – drawn match • 0 – lost match. Write a program that meets the following requirements: • calculates the total points for all matches played for each team • counts the total number of away wins, home wins, drawn matches and lost matches for each team • outputs for each team: – name – total points – total number of away wins, home wins, drawn matches and lost matches • finds and outputs the name of the team with the highest total points • finds and outputs the name of the team with the lowest total points. You must use pseudocode or program code and add comments to explain how your code works. You do not need to declare any arrays, variables or constants; you may assume that this has already been done. All inputs and outputs must contain suitable messages. You do not need to initialise the data in the arrays TeamName and TeamPoints or the variables LeagueSize and MatchNo
0478_m23_qp_22
THEORY
2023
Paper 2, Variant 2
Questions Discovered
5