Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Examination Revision Stewart Blakeway FML 213

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

JAVA Coursework (the same for 2A and 2B). Fundamental Information The coursework is 30 marks in your O’Level = 15% of the exam Must be word processed.
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
PSEUDOCODE & FLOW CHART
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 5: Steps in Problem Solving Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Variables and Trace Tables Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 8: Java: Selection and Repetition Stewart Blakeway.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 3 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 7: Java basics Stewart Blakeway
Faculty of Sciences and Social Sciences HOPE PHP Flow Control Website Development Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 12: Data Structures 1 Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Data Structures 3 Stewart Blakeway FML
Faculty of Sciences and Social Sciences HOPE Data Structures 2 Stewart Blakeway
Faculty of Sciences and Social Sciences HOPE Java: Loops within loops Stewart Blakeway FML 213
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving An Introduction Stewart Blakeway
Program Design and Development
Computer Science 1620 Programming & Problem Solving.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
Object Oriented Software Development
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
CIS Computer Programming Logic
Faculty of Sciences and Social Sciences HOPE JavaScript Validation Regular Expression Stewart Blakeway FML
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
chap8 Chapter 8 Arrays (Hanly) chap8 2 Data Structure Simple data types use a simple memory to store a variable. Data Structure: a.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Introduction. 2COMPSCI Computer Science Fundamentals.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
Array Processing.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter
By the end of this session you should be able to...
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
CPS120: Introduction to Computer Science Decision Making in Programs.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
The Software Development Process
1 Pre-Exam Lecture 4 Final Examination is scheduled on Monday December 18th at 1:30PM in class 4 There are 8 questions with or without sub- parts and.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
D75P 34 – HNC Computer Architecture
1 Chapter 6 Methods. 2 Motivation Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Intermediate 2 Computing Unit 2 - Software Development.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Algorithms and Pseudocode
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Algorithms and Flowcharts
Arrays Chapter 7.
Algorithm and Ambiguity
Algorithm and Ambiguity
Data and Flowcharts Session
Problem Solving Designing Algorithms.
Data and Flowcharts Session
Class 4: Repetition Pretest Posttest Counting Flowchart these!
Data and Flowcharts Session
WJEC GCSE Computer Science
Presentation transcript:

Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Examination Revision Stewart Blakeway FML

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

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

Faculty of Sciences and Social Sciences HOPE What we have done Data Structures – FIFO (queues) – LIFO (stacks) – Arrays – Multidimensional Arrays – Tables 4

Faculty of Sciences and Social Sciences HOPE Object Oriented Programming Methods (messages) – Simple – Complex 5

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

Faculty of Sciences and Social Sciences HOPE Conditional Statements We have 4 types of conditional statements – while – for – if – if else

Faculty of Sciences and Social Sciences HOPE while

Faculty of Sciences and Social Sciences HOPE for

Faculty of Sciences and Social Sciences HOPE if

Faculty of Sciences and Social Sciences HOPE if else

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

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

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

Faculty of Sciences and Social Sciences HOPE Stepaza is not z a is not True False Stepaza is not z a is not True 4False 68 3True 4False 67 3True 4False 66 3True 4False 65 3

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

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

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

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

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)

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

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

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)

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

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

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

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? for (y=5 ; y >= 1 ; y--) { System.out.println(scores[y]); }

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 int oldScore; oldScore = score[3]; score[3] = 347; score[5] = score[4]; score[4] = oldScore;

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

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 2Blakeway Whitfield Presland Farrimond START2

Faculty of Sciences and Social Sciences HOPE Answer START Blakeway9.28 Presland9.52 Farrimond10.01 Whitfield10.120

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 – delete Blakeway who boarded at PassengerTimeNext 1 2Blakeway Whitfield Presland Farrimond START2

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 – delete Blakeway who boarded at PassengerTimeNext 1Sultan Whitfield Presland Farrimond START5

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.

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)

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

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

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”)

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

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

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(); }

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

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

Faculty of Sciences and Social Sciences HOPE Questions