A number of devices in and around the home can be operated by control systems.
A home owner wishes to install automatic lights to illuminate a water fountain in her garden. These lights will automatically turn on at sunset and turn off at sunrise.
Describe two hardware components that would be an essential part of this control system.
Explain the concept of feedback, with respect to computer control systems in general.
The home owner has also installed a control system that waters the flowerbeds in the garden. This system aims to maintain the water content of the flowerbeds between a minimum and a maximum value. However, the system is only activated when the light intensity is below a certain level.
Outline the algorithm involved in controlling the watering system described above.
A company has 600 employees whose names are currently stored using a collection called NAMES
. The names are stored as surname, first name. For example: Smith, Jane, Uysal, Rafael, Ahmed, Ishmael, Jonsonn, Sara, …
The names in the collection are kept in a random order. However, it would be more useful if they were kept in alphabetical order.
The company’s staff list is now organized in the arrays in alphabetical order.
A binary search was used to find a specific name in the array.
Construct a pseudocode algorithm that will store the surnames in one array and first names in another.
Construct a pseudocode algorithm that will sort the surnames into alphabetical order using the bubble sort method. The order of the first names must also be changed so that they keep the same index as their corresponding surname.
Describe the process a binary search would follow to find a record in the surname array.
Outline one benefit of using sub-programmes to implement your algorithms from parts (a) and (b).
For an identified application, explain why a binary search would be preferred to a linear search.
Describe the steps involved in using the bubble sort algorithm to sort an array.
A school has 100 students. All student names (strings) and student ID numbers (five-digit integers) are held in two separate one-dimensional arrays named SID and SNAMES.
SID | [0] | SNAMES | |
---|---|---|---|
[0] | 10011 | Aron Zucker | |
[1] | 10002 | [1] | Cary Armand |
[2] | 11876 | [2] | Pia Baranger |
[3] | 10122 | [3] | Peter Bow |
[4] | 22103 | [4] | John Buffet |
... | ... | ... | ... |
[99] | 32000 | [99] | Evan Apples |
A binary search algorithm is not used to find a particular name in array SNAMES.
State the reason for not using a binary search.
Construct an algorithm in pseudocode for the method isIn(x, COL).
Construct an algorithm in pseudocode that will output the number of students who have chosen both tennis and football. The method isIn() should be used in your answer.
Construct an algorithm in pseudocode that will output the names of students who have not yet chosen any one of the three sports. An appropriate message should be displayed if every student has chosen a sport.
IB Computer Science SL Paper 1
Construct a logic diagram for the following expression. NOT A OR (A AND B)
An airport uses an object-oriented program to keep track of arrivals and departures of planes. There are many objects in this system and some are listed below.
The code below outlines the Arrival
class used in this program.
public class Flight
{ private String id;
public String getId() {return this.id;}
// ... more variables, accessor and mutator methods
}
**
public class** Arrival
{ private Flight myFlight;
private String sta; // Scheduled Time of Arrival ('hh:mm')
private int runway;
private String gate;
private int delay;
private boolean landed;
public Arrival(Flight myFlight, String sta)
{ **this.**myFlight = myFlight;
**this.**sta = sta;
**this.**runway = 0;
**this.**gate = null;
**this.**delay = 0;
**this.**landed = false;
}
public void addDelay(int newDelay)
{ **this.**delay = newDelay;
}
public String getETA()
{ // calculates the Estimated Time of Arrival (ETA) of the flight
// by adding the delay to the sta and returning the result as a
// String ('hh:mm')
}
public int compareWith(String flightID)
{ if (myFlight.getID().equals(flightID)) { return 0; }
else { return 1; }
}
public int compareWith(Arrival anotherArrival)
{ // missing code
}
// ... plus accessor and mutator methods
}
The code below outlines part of the FlightManagement
class used in this program.
For the purposes of this exam only arriving flights are being considered.
public class FlightManagement
{
private Arrival[] inbound; // array of inbound airplanes
private int last = -1; // index of last used entry
public FlightManagement()
{ inbound = new Arrival[200];
}
public void add(Arrival newArrival)
{ // missing code that adds the newArrival to the array inbound
// sorted by ETA, and updates last
}
private int search (String flightID)
{ // missing code that searches the array inbound and
// returns the index of the Arrival object with flightID
}
public Arrival remove(String flightID)
{ Arrival result;
int index = search(flightID);
result = inbound[index];
while (index < last)
{ inbound[index] = inbound[index + 1];
index++;
}
last--;
return result;
}
// ... many more methods
}
The method search
in the FlightManagement
class searches the array inbound
and returns the index of the Arrival
object with the given flightID
.
Outline the general nature of an object.
Describe two disadvantages of using Object Oriented Programming (OOP).
Outline one advantage of using modularity in program development.
State the relationship between the Flight
object and the Arrival
object.
Construct a UML diagram to represent theArrival
object.
Construct the method search
implementing a linear search. Use the first compareWith()
method in the Arrival
object.
You may assume that an Arrival
object with the given flightID
exists in the array inbound
.
Outline one advantage of using a binary search.
Outline one disadvantage of using a binary search.
A medical centre uses a computer system to manage both patients’ data and appointments. This system, which is used by the doctors, nurses and secretaries, has two unordered files: a patients’ file and an appointments’ file, both of which can only be accessed sequentially.
Every evening the following processing takes place:
Outline the pseudocode that the processing must follow when the system sends out the text reminders.
Describe two different methods that the medical centre could use that would allow data to be restored should it be lost for any reason.
The medical centre is concerned about the privacy of the data it is storing and has to make decisions concerning:
Discuss the issues that should be considered before making these decisions.
NUMBERS
is a collection that holds only positive integers.
A three-digit number has three digits: a hundreds digit, a tens digit and a units digit.
For example, for 406, its hundreds digit is 4, its tens digit is 0 and its units digit is 6.
An algorithm is needed to copy each three-digit number from the collection NUMBERS
, where the hundreds digit is smaller than its tens digit and its tens digit is smaller than its units digit, into a one-dimensinal array named THREE
. If there are no such numbers in the collection then an appropriate message should be displayed.
For example:
IfNUMBERS
={9, 3456, 12, 237, 45679, 368, 296}
then the contents of the array,THREE
, is:
IfNUMBERS
={1234, 56, 90, 324, 876}
then the array THREE
is empty and a message such as “No such numbers”, should be outputted.
Consider the following algorithm.
N = 372
X = N DIV 100
Y = X + 10 * (N MOD 100 DIV 10)
Z = Y + (N MOD 10) * 100
Determine the values of variables X, Y, and Z
after execution of this algorithm. Show your working.
Construct this algorithm. You may assume that the array THREE
is initialized with a sufficient number of elements.
Describe how a selection sort algorithm could be used to sort the array THREE
in ascending order.
Construct a trace table for the following algorithm
A = 2
B = 7
loop while B >= A
A = A + 1
output(B - A)
B = B - 1
end loop