Arrays (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

A programmer is writing a program to calculate the total cost of items in a shopping basket. The price of each item is stored in an array. The program needs to use a loop to iterate through the array and calculate the total cost. The array is defined as follows:

  • prices = [2.50, 1.75, 3.00, 1.25, 4.50]

Write pseudocode to show how a loop can be used to calculate the total cost of all items in the shopping basket.

2.

Consider an array of student marks in a class. The marks are stored in an array called marks. Write a program (in a language of your choice) that uses a for loop to find the highest mark in the array and display it. Assume the array has at least one element.

3.

Describe what an array is and explain why arrays are useful for storing multiple values of the same data type in a computer program. Give an example of a scenario where using an array would be more efficient than using multiple individual variables.