Download presentation
Presentation is loading. Please wait.
1
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Examination Revision Stewart Blakeway FML 213 blakews@hope.ac.uk 0151 291 3113
2
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Aims of the Presentation Brief overview of what we have done Structure of the Examinations Example Questions Example Model Answers The final lap! 2
3
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What we have Algorithms – Declaration – Assignment – Flow Charts – Structured English Programming – Java – For Loops – If Statements – While Loops 3
4
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE What we have done Data Structures – FIFO (queues) – LIFO (stacks) – Arrays – Multidimensional Arrays – Tables 4
5
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Object Oriented Programming Methods (messages) – Simple – Complex 5
6
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Flow Charts Start and Finish – Always Process (Instruction) – Any statement that does not evaluate a condition Conditional Statement – Any condition that is evaluated
7
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Conditional Statements We have 4 types of conditional statements – while – for – if – if else
8
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE while
9
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE for
10
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE if
11
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE if else
12
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge a := 1 z := 10 while (a <= z) begin a := a + 1 z := z – 1 end Start a:=1 z:=10 a<= z a:=a+1 z:=z-1 Finish TF Draw the corresponding flowchart
13
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Trace Tables You need a column for step number All variables need a column All conditional statements need a column a := 1 z := 10 while (a is not z) begin if (a is less than z) then begin a := a + 1 end Shout out the columns required
14
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test Your knowledge a := 1(step 1) z := 10(step 2) while (a is not z)(step 3) begin if (a is not 5) then(step 4) begin a := a + 1(step 5) end else begin z := z – 1(step 6) end display a display z
15
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Stepaza is not z a is not 5 11 210 3True 4 52 3 4 53 3 4 54 3 4 55 3 4False Stepaza is not z a is not 5 69 3True 4False 68 3True 4False 67 3True 4False 66 3True 4False 65 3
16
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Structured English Structured English allows you to represent your solution – the English is Structured – Conventions should be followed – Indentation is important
17
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Conventions instructions while (something operator something) begin instructions end instructions if (something operator something) then begin instructions end else begin instructions end instructions Operators not equal equal equal or less than equal or more than less than more than
18
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge keep filling the tank with fuel until it is full while (tank not full) begin pour fuel end
19
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge HardDiskCost between 100gig and 149gig£50 between 150gig and 199gig£60 more than 200gig£70 if (HardDisk between 100gig and 149gig) then begin Cost := 50 end if (HardDisk between 150gig and 199gig) then begin Cost := 60 end if (HardDisk more than 200gig) then begin Cost := 70 end
20
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Structured English and Functions One of the questions will be in the form of a scenario – description (sometimes ambiguous) – functions (must use exactly) – variables (must use exactly) – reports (that are generated and sent, usually for each occurrence) – Output (usually at end)
21
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge A baked beans company requires an automated system to check the beans in the can before the cans are sealed. Each can joins a conveyor belt and is dealt with in order. The conveyor belt runs until 11pm when it is shut down for maintenance. The system generates and sends reports based on the quality of the beans, depending on the quality of the beans three kinds of reports are generated. – Report_G for good quality – Report_M for medium quality – Report_P for poor quality At the end of each day the system outputs the number of tins processed in each category, Good, Medium and Poor. Remember to initialise any variables you use
22
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Write an algorithm in Structured English (Pseudocode) to describe the operation of the system. Remember to initialise any variables used. The following functions are to be used: getTin()gets the tin from the conveyor and inspects TinOnBelt() returns True or False dependent on if there are tins on the conveyor to be inspected Quality() returns Good, Medium or Poor according to the quality of the beans Generate(Report_Type) creates a report of the specified type, for example Generate(Report_M) will create a report type Medium. Send (Report_Type) sends a report of the specified type. Output (G,M,P) will output the values of each variable G, M and P G, M and P are variables which can store integer (whole number) values Test your Knowledge
23
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Solution G:=0 M:=0 P:=0 while (TinOnBelt()) begin getTin() if (Quality() = “Good”) then begin G:=G+1 Generate(Report_G) Send(Report_G) end. if (Quality() = “Medium”) then begin M:=M+1 Generate(Report_M) Send(Report_M) end if (Quality() = “Poor”) then begin P:=P+1 Generate(Report_P) Send(Report_P) end output (G,M,P)
24
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Data Structures You will be expected to recommend data structures for given scenarios – FIFO (queues) – LIFO (stacks) – Arrays – Multidimensional Arrays – Tables
25
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge The darts league contains 20 teams. What would be the most appropriate data structure to hold the names of each team? Your answer should also include the attributes required to form the data structure Array[1..20] of names
26
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge A university has decided to record the time an employee arrives at work. The system should store the name of the employee and the time the employee arrives for work. Identify a data structure to store this information. Your answer should also include the attributes required to form the data structure. Sequence of records with two fields: employee and time of arrival
27
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge Below is an array called scores, it is storing the top five scores from the darts team. What is displayed when the following code is executed? 12345 360350322 301 for (y=5 ; y >= 1 ; y--) { System.out.println(scores[y]); } 301 322 350 360
28
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge Below is an array called scores, it is storing the top five scores from the darts team. Redraw the array if the following code has been executed 12345 360350322 301 int oldScore; oldScore = score[3]; score[3] = 347; score[5] = score[4]; score[4] = oldScore; 12345 360350347322
29
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge An exchange sort will compare each adjacent array and swap if the array element to the right is less than the array element to the left. For example, 1 is compared with 2, 2 with 3, 3 with 4 and 4 with 5. The process is repeated until the array is sorted in order. Redraw the following array after the first pass of this algorithm. Do not draw the array in its final state. 12345 445612111 12345 441211156
30
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge The data structure below implements a sequence of records of the names and times that passengers have checked in at an airport. Show the records in pointer form. PassengerTimeNext 1 2Blakeway9.285 3Whitfield10.120 4 5Presland9.529 6 7 8 9Farrimond10.013 10 START2
31
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Answer START Blakeway9.28 Presland9.52 Farrimond10.01 Whitfield10.120
32
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge Show the following data structure below after both the following actions have been carried out. – insert Sultan who checked in at 10.10 – delete Blakeway who boarded at 10.22 PassengerTimeNext 1 2Blakeway9.285 3Whitfield10.120 4 5Presland9.529 6 7 8 9Farrimond10.013 10 START2
33
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Answer Show the following data structure below after both the following actions have been carried out. – insert Sultan who checked in at 10.10 – delete Blakeway who boarded at 10.22 PassengerTimeNext 1Sultan10.103 2 3Whitfield10.120 4 5Presland9.529 6 7 8 9Farrimond10.011 10 START5
34
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Object Orient Principles The final section of the exam focuses on object oriented programming. – The first part looks at the principles and design, – The second part looks at the programming.
35
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge A Java software developer has been commissioned by a chain of estate agents in which their offices need to be modelled. He will need to be able to store for each estate agent office the town it is located in, the number of new properties it has for sale and the number of properties it has for rent. Amongst others, he will want to send messages to the estate office object to make it carry out the following actions – set the town of the estate agents to a given value – add a given number of new properties for sale – remove a given number of properties for sale (sold or withdrawn) Suggest a suitable set of attributes and protocols Attributes: town, numPropForSale, numPropForRent Protocol: void setTown(String name) void addNewPropSale(int number) void removePropSale(int number)
36
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge A Java software developer has been commissioned by a chain of estate agents in which their offices need to be modelled. He will need to be able to store for each estate agent office the town it is located in, the number of new properties it has for sale and the number of properties it has for rent. Amongst others, he will want to send messages to the estate office object to make it carry out the following actions – set the town of the estate agents to a given value – add a given number of new properties for sale – remove a given number of properties for sale (sold or withdrawn) Suppose a estate agent object called ABC is created for the town Wolverhampton. The estate agent has 23 properties for sale and 4 properties for rent. Draw a object diagram that shows the initial state of ABC
37
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Answer Class of Object: Estate Agent town numPropForSale numPropForRent “Wolverhampton” 23 4 void setTown(String name) void addNewPropSale(int number) void removePropSale(int number) ABC
38
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge Using the scenario described in the last few slides, write Java statements that will: – add 8 new properties – sell 2 properties – rename the estate agent to “Liverpool” The java statements should send suitable messages using the ABC object. ABC.addNewPropSale(8) ABC.removePropSale(2) ABC.setTown(“Liverpool”)
39
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Test your knowledge Redraw the diagram omitting the protocol to show the resulting state of ABC. Class of Object: Estate Agent town numPropForSale numPropForRent “Liverpool” 29 4 ABC
40
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE public class PieBoss { private PieEater paul; public void start() { paul = new PieEater (“paul”, “red”); this.steps(5); this.turns(0,8); } public void steps(int n) { int i; for (i=1 ; i < n ; i++) { paul.walk(); } Nearly there To the right is some code. The code is missing the method for turns(0,8). Create this method, the first parameter is the direction of the turn, 0 should turn paul to the left. Any other value should turn paul to the right The second parameter is how many times paul should turn (i.e. 8 times) You are allowed to use the following messages paul.turnLeft() and paul.turnRight() Write the code for the turns(int dir, int n) message
41
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Answer public void turns(int dir, int n) { int i; for (int i=0; i<n;i++) { if (dir == 0) { paul.turnleft(); } else { paul.turnright(); }
42
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Finally Describe the process of installing software from removable storage and then running the program. You must attempt the correct terminology and you should produce a diagram that represents the stages
43
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Answer Program is copied from CD onto the secondary storage by sending patterns of electrical signals along the connecting bus Before the program can run it must be transferred from secondary storage into main memory. Once program is loaded into RAM the CPU can start fetching the instructions from RAM and executing them
44
www.hope.ac.uk Faculty of Sciences and Social Sciences HOPE Questions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.