Higher Computing Science. Software Design and Development

Size: px
Start display at page:

Download "Higher Computing Science. Software Design and Development"

Transcription

1 Higher Computing Science Software Design and Development Programming with Visual Studio

2 CONTENTS Topic 1 Topic 2 Topic 3 Topic 4 Topic 5 Topic 6 Topic 7 Topic 8 Topic 9 Getting started Strings and Pre-Defined Functions Selection 1-D Arrays User-defined functions Parameter passing Standard Algorithms Reading from a sequential file Using records Higher Computing Science 2

3 TOPIC 1 GETTING STARTED You will have used a variety of different data types in the Nat 5 programming unit. These are: Integer - stores whole numbers Single String Boolean - stores real numbers (numbers with a decimal point in them) - stores alphanumeric characters (letters / symbols / numbers) - stores one of two values: True or False Task 1: Wages program - Using variables: Real (single) Program specification Wages calculator Design and write a program that asks the user to enter their hourly rate and the number of hours worked. The total pay should be calculated and displayed. FORM DESIGN PROPERTIES HEADING Label: Name is lblheading Text is Real Numbers EXIT Button: Name is cmdexit Text is EXIT CLEAR button: Name is cmdclear Text is CLEAR START button: Name is cmdstart Text is START LISTBOX1: Name is listbox1 DESIGN 1. Take in pay details 2. Calculate wages Refine Step 1: Take in pay details 1.1 Ask for hourly rate. 1.2 Display hourly rate. 1.3 Ask for number of hours worked. 1.4 Display number of hours worked. Refine Step 2: calculate wages 2.1 Total pay = hourly rate * hours worked 2.2 Display total pay Higher Computing Science 3

4 TOPIC 1 GETTING STARTED CODE Public Class Form1 'Task 1: Real Variables program to calculate the total pay from hours worked and work rate 'set the data types of the global variables required in the program Dim hours_per_week, hourly_rate, total_pay As Single Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'main steps to calculate total pay take_in_details() calculate_wage() Private Sub take_in_details() ' Step 1: take in hourly rate and hours worked and convert to a value hourly_rate = Val(InputBox("Please enter your hourly rate.")) ListBox1.Items.Add("The hourly rate is " & hourly_rate) hours_per_week = Val(InputBox("Please enter your hours worked this week.")) ListBox1.Items.Add("The number of hours worked is " & hours_per_week) Private Sub calculate_wage() ' Step 2: calculate and display the total wage total_pay = hourly_rate * hours_per_week ListBox1.Items.Add("") ' display a blank line ListBox1.Items.Add("The total pay for the week is " & total_pay) Private Sub cmdclear_click(sender As Object, e As EventArgs) Handles cmdclear.click 'clear the contents of the list box ListBox1.Items.Clear() Private Sub cmdexit_click(sender As Object, e As EventArgs) Handles cmdexit.click End End Class Load and run the program called Higher Task1 Real. Higher Computing Science 4

5 OUTPUT TOPIC 1 GETTING STARTED Run your program with the test data below. You will notice from the output that the total pay is not displayed properly: The pay has 3 decimal places The pay does not have a pound sign Formatting output In your calculate_wage procedure change the line that displays the wage to this: ListBox1.Items.Add("The total pay for the week is " & Format(total_pay, ".000")) Copy the table below and adapt your program to the different formats shown. Decsribe the output that each format command produces: Format Command Format(average, ".000") Format(average, "000.0") Format(average, "###.0") Format(average, "fixed") Format(average, "currency") Format(average, "percent") Description of this function Higher Computing Science 5

6 TOPIC 1 GETTING STARTED Task 2: Ask a question - Using Variables: Boolean Program specification Ask a question Design and write a program that asks the user to enter the answer to a question. The user will be told whether they are correct or wrong. FORM DESIGN PROPERTIES HEADING Label: Name is lblheading Text is Boolean Variables EXIT Button: Name is cmdexit Text is EXIT CLEAR button: Name is cmdclear Text is CLEAR START button: Name is cmdstart Text is START LISTBOX1: Name is listbox1 DESIGN 1. Ask question() 2. Check answer() 3. Display result() Refine Step 1: Ask Question 1.1 set correct to False 1.2 ask for answer to question what is capital of Norway?. 1.3 Display user s answer Refine Step 2: check answer is correct 2.1 if answer is Oslo 2.2 set correct to True 2.3 end if Refine Step 3: Ask Question 3.1 If correct is True 3.2 display well done message 3.3 Else 3.4 Display wrong message 3.5 End if Higher Computing Science 6

7 TOPIC 1 GETTING STARTED CODE Public Class Form1 'Task 2: program with Boolean value 'Quiz program which asks for the capital of Norway 'set the data types of the global variables required in the program Dim answer As String Dim correct As Boolean Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'main steps to calculate total pay Ask_question() Check_answer() Display_message() Private Sub ask_question() ' ask the user the question and display their answer correct = False answer = InputBox("What is the capital city of Norway?") ListBox1.Items.Add("The answer you gave is " & answer) ListBox1.Items.Add("") Private Sub check_answer() ' check if the users answer is correct If answer = "Oslo" Then correct = True Private Sub display_message() ' display an appropriate message to the user If correct = True Then ListBox1.Items.Add("Your answer is correct - well done!") Else ListBox1.Items.Add("Your answer is not correct") End If Private Sub cmdclear_click(sender As Object, e As EventArgs) Handles cmdclear.click 'clear the contents of the list box ListBox1.Items.Clear() Private Sub cmdexit_click(sender As Object, e As EventArgs) Handles cmdexit.click End End Class Load and run the program called Higher Task 2 Boolean Higher Computing Science 7

8 TOPIC 1 GETTING STARTED OUTPUT Run your program with the test data below: Task 3: Charity Collection Procedures and formatting Problem: Three friends have been collecting money for charity. A local company has offered to add a donation based on the total amount they manage to raise. Write a program that allows the friends to enter their individual amounts. The program should then add the three amounts and store the total. The following decisions on the donation from the company are made: a) any amount raised less than 1000 has a 100 bonus (for example 345 raised = 445 total) b) the company will double the amount raised between (and including) 1000 and 2000 (for example 1282 raised = 2564 total) c) if the amount is over 2000 the initial 2000 is doubled but any amount after that is not (for example 2054 raised = 2* = 4054 total) Create a design for your Form and for your Code. Show this to your teacher before you implement this program. Typical Inputs and Output Higher Computing Science 8

9 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Topic 2 - Working with Strings Visual Studio provides a number of useful pre-defined functions for manipulating strings. Name How it works What it does Example Input(s) Output Len String Integer calculates the number of characters in a string Letters = Len( blob ) will result in Letters = 4 Ucase String String converts lower-case characters into upper-case characters Lcase String String converts upper-case characters into lower-case characters Asc String Integer Returns the ASCII value of a character Chr Integer String takes an ASCII value and returns the corresponding character String_in = Ucase( blob ) will result in String_in = BLOB String_in = Lcase( XX ) will result in String_in = xx Ascii-no = Asc( A ) will result in Ascii_no = 65 Letter = Chr(65) will result in Letter = A Left String Integer String Extracts a sub-string from a string Part = Left( Word, 3) will result in Part = Wor Right String Integer String Extracts a sub-string from a string Part = Right( Word, 2) will result in Part = rd Mid String Integer Integer String extracts a sub-string from a string Part = Mid$( Word, 2, 3) will result in Part = ord NOTE: Every function above has one or more inputs to the functions BUT every function has only ONE OUTPUT!!! Higher Computing Science 9

10 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Task 4: String functions Program specification The program will ask the user to enter a name and will then carry out a series of string operations on the name. FORM DESIGN PROPERTIES HEADING Label: Name is lblheading Text is Pre-Defined String Functions EXIT Button: Name is cmdexit Text is EXIT CLEAR button: Name is cmdclear Text is CLEAR LowerCase button: Name is cmdlower Text is Lower case UpperCase button: Name is cmdupper Text is Upper case Left button: Name is cmd Left Text is Left Right button: Name is cmdright Text is Right Middlebutton: Name is cmdmiddle Text is Middle Capitalise button: Name is cmdcapfirst Text is Capitalise First Convert button: Name is cmdconvert Text is Convert first to ASCII LISTBOX1: Name is listbox1 Higher Computing Science 10

11 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS DESIGN Lowercase 1. Read in originalname 2. Change originalname to lowercase and store in newname 3. Display originalname 4. Display newname Uppercase 1. Read in originalname 2. Change originalname to uppercase and store in newname 3. Display originalname 4. Display newname Left 1. Read in originalname 2. Store the left 2 characters in newname 3. Display originalname 4. Display newname Right 1. Read in originalname 2. Store the right 2 characters in newname 3. Display originalname 4. Display newname Middle 1. Read in originalname 2. Get the length of originalname 3. Store the middle two characters in newname 4. Display length 5. Display originalname 6. Display newname Higher Computing Science 11

12 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Capitalise First 1. Read in originalname 2. Get the length of original name 3. Store the first character in firstletter 4. Store the rest of the characters in restofname 5. Make firstletter a capital and store it in capital 6. Concatenate the capital and the restofname 7. Display length 8. Display original name 9. Display new name Convert to Ascii 1. Read in originalname 2. Store the first character in firstletter 3. Convert firstletter to an Ascii value and store it in letterasascii 4. Display original name 5. Display first letter 6. Display first letter as Ascii CODE Public Class Form1 'Task 3 : program with pre-defined string functions 'set the data types of the global variables required in the program Dim originalname, newname, firstletter, restofname, capital As String Dim letterasascii, length As Integer Private Sub cmdlower_click(sender As Object, e As EventArgs) Handles cmdlower.click ' convert the name to lower case letters originalname = InputBox("Please enter a name") newname = LCase(originalname) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("the new name name is :" & newname) ListBox1.Items.Add("") Private Sub cmdupper_click(sender As Object, e As EventArgs) Handles cmdupper.click ' convert the name to upper case letters originalname = InputBox("Please enter a name") newname = UCase(originalname) ListBox1.Items.Add("the original name is :" & originalname) ListBox1.Items.Add("the new name name is : " & newname) ListBox1.Items.Add("") Higher Computing Science 12

13 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Private Sub cmdleft_click(sender As Object, e As EventArgs) Handles cmdleft.click ' extract the first character on the left originalname = InputBox("Please enter a name") newname = Microsoft.VisualBasic.Left(originalname, 2) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("the first two characters are : " & newname) ListBox1.Items.Add("") Private Sub cmdright_click(sender As Object, e As EventArgs) Handles cmdright.click ' extract the last character from the right originalname = InputBox("Please enter a name") newname = Microsoft.VisualBasic.Right(originalname, 2) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("the last two characters are : " & newname) ListBox1.Items.Add("") Private Sub cmdmiddle_click(sender As Object, e As EventArgs) Handles cmdmiddle.click ' extract the middle two characters of the name originalname = InputBox("Please enter a name") length = Len(originalname) newname = Microsoft.VisualBasic.Mid(originalname, length / 2, 2) ListBox1.Items.Add("The length of the original name is " & length) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("the middle two characters are : " & newname) ListBox1.Items.Add("") Private Sub cmdcapfirst_click(sender As Object, e As EventArgs) Handles cmdcapfirst.click ' extract the first letter of the name and capitalise it originalname = InputBox("Please enter a name") length = Len(originalname) firstletter = Microsoft.VisualBasic.Left(originalname, 1) restofname = Microsoft.VisualBasic.Right(originalname, length - 1) capital = UCase(firstletter) newname = capital + restofname ListBox1.Items.Add("The length of the original name is " & length) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("The new name with a capital letter is : " & newname) ListBox1.Items.Add("") Private Sub cmdconvertascii_click(sender As Object, e As EventArgs) Handles cmdconvertascii.click ' extract the first character of the name and convert to ASCII originalname = InputBox("Please enter a name") firstletter = Microsoft.VisualBasic.Left(originalname, 1) letterasascii = Microsoft.VisualBasic.Asc(firstletter) ListBox1.Items.Add("the original name is : " & originalname) ListBox1.Items.Add("The first letter of name is : " & firstletter) ListBox1.Items.Add("The first letter as ASCII is : " & letterasascii) ListBox1.Items.Add("") End Class Load and run the program called Higher Task 4 String functions. Higher Computing Science 13

14 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS OUTPUT Run your program with the test data below: Lower case, Upper case, Left, Right: Middle, Capitalise First, Convert first to ASCII: Higher Computing Science 14

15 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Task 5: Devising User IDs String functions Problem: A program is required which will automatically generate a password from information provided by the user. The program should generate the password from the first letter of their first name, second letter of their surname, last two letters of their birth month converted to upper case, second and third letters of their favourite colour, first 3 letters of their street name, the second-last character in their name then converted to an ASCII value and finishing with the letters VB. For example, Brenda McSporran, born in NovembER, likes the colour green lives in Market Place, second last letter is a and converted to 97, so her password will be BcERreMar97VB. Create a design for your Form and for your Code. Show this to your teacher before you implement this program. Pre-defined Numeric Functions There are pre-defined functions that work in a mathematical way. These include: name what it does example Rnd generates a random number between 0 and 1 X = Rnd * 10 Int Round returns the whole number part of a real number Rounds a value to a specified number of decimal places Answer = Int(3.24) returns Answer = 3 Answer = Round(3.24, 1) returns Answer = 3.2 Val Is used to convert a string to a numeric value Number=Val(txtInput.text) Higher Computing Science 15

16 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS Task 6: Using Pre-defined Numeric Functions Problem specification Create a program which will generate a random number. The program will use the INT function on a random number and also the ROUND function. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Pre-Defined Numeric Functions EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR Random button: Name: cmdrandom Text: Random Number Int button: Name: cmdint Text: Int Roundbutton: Name: cmdround Text: Round ListBox: Name: listbox1 Higher Computing Science 16

17 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS DESIGN Random Number 1. Generate random number 2. Display random number 3. Display blank line Int 1. Generate random number 2. Apply INT function to remove decimal part of random number and store as result 3. Display random number 4. Display result 5. Display blank line Round 1. Generate random number 2. Apply ROUND function to round random number to one decimal place and store as result 3. Display random number 4. Display result 5. Display blank line Higher Computing Science 17

18 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS CODE Public Class Form1 'Task 4: program with pre-defined maths functions Dim randomnumber, result As Single Private Sub cmdrandom_click(sender As Object, e As EventArgs) Handles cmdrandom.click ' generate a random number between 0 and 1 Randomize() randomnumber = Microsoft.VisualBasic.Rnd() ListBox1.Items.Add("the random number generated was : " & randomnumber) ListBox1.Items.Add("") Private Sub cmdint_click(sender As Object, e As EventArgs) Handles cmdint.click 'remove the decimal part of a number Randomize() randomnumber = Microsoft.VisualBasic.Rnd() * 10 result = Int(randomnumber) ListBox1.Items.Add("the random number multiplied by 10 is : " & randomnumber) ListBox1.Items.Add("INT converts this number to : " & result) ListBox1.Items.Add("") Private Sub cmdround_click(sender As Object, e As EventArgs) Handles cmdround.click 'round a random number to one decimal place Randomize() randomnumber = Microsoft.VisualBasic.Rnd() result = Math.Round(randomnumber, 1) ListBox1.Items.Add("the random number generated was : " & randomnumber) ListBox1.Items.Add("Rounded to one decimal place : " & result) ListBox1.Items.Add("") Private Sub cmdclear_click(sender As Object, e As EventArgs) Handles cmdclear.click ListBox1.Items.Clear() End Class Load and run Higher Task 6 Maths Functions. Higher Computing Science 18

19 TOPIC 2 STRINGS & PRE-DEFINED FUNCTIONS OUTPUT Run your program a few times like the test runs below. Task 7: Painting a fence Procedures, rounding and formatting Problem: The program should calculate the number of tins of paint to paint a rectangular fence and the total cost of buying the tins. The user should enter the dimensions of the fence (the length and height in metres), the cost of one tin of paint and the coverage factor for one tin of paint (how many metres squared can be painted). Both the front and the back of the fence will need to be painted. The program should display the following details: The total area to be painted (to one decimal place) The number of tines required (rounded up to a whole number) The total cost of buying the tins (formatted as currency). Create a design for your Form and for your Code. Show this to your teacher before you implement this program. Higher Computing Science 19

20 TOPIC TOPIC 1 GETTING 3 - SELECTION STARTED Topic 3 - Selection using CASE A Case statement is an alternative to using multiple IF statements. This method has the same outcome but requires less code and is easier to read. Task 8: Assign a grade Case statement Problem specification Design and write a program that asks the user to enter their mark. A grade is assigned as follows:- 80 or over is a grade 1, 60 to 79 is a grade 2, 40 to 59 is a grade 3, 20 to 39 is a grade 4, 10 to 19 is a grade 5, less than 10 is a grade 6. The grade should be displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Case Statement EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 20

21 TOPIC TOPIC 1 GETTING 3 - SELECTION STARTED DESIGN MAIN STEPS 1. Take in mark() 2. Display grade() DESIGN - REFINEMENTS Refine Step 1: Take in Mark () 1.1 Read in the pupils mark 1.2 In the case of mark 1.3 Greater than or equal to Grade is Greater than or equal to Grade is Greater than or equal to Grade is Greater than or equal to Grade is Greater than or equal to Grade is Less than Grade is End Case Statement Refine Step 2: Display Grade () 2.1 Display the mark 2.2 Display the grade 2.3 Display a blank line Higher Computing Science 21

22 TOPIC TOPIC 1 GETTING 3 - SELECTION STARTED CODE Public Class Form1 'task 3.1 Using a case statement to decide on a student grade Dim mark, grade As Integer Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click take_in_mark() display_grade() Private Sub take_in_mark() ' ask user to enter the mark out of 100 mark = Val(InputBox("Please enter pupil's mark out of 100")) 'decide on an appropriate grade Select Case mark Case Is >= 80 grade = 1 Case Is >= 60 grade = 2 Case Is >= 40 grade = 3 Case Is >= 20 grade = 4 Case Is >= 10 grade = 5 Case Is < 10 grade = 6 End Select Private Sub display_grade() ' display the pupil's mark and grade ListBox1.Items.Add("The pupil's mark is " & mark) ListBox1.Items.Add("Their grade is " & grade) ListBox1.Items.Add("") End Class OUTPUT Test your program with sample output similar to below: Load and run Higher Task 8 Assign a grade. Higher Computing Science 22

23 TOPIC TOPIC 1 GETTING 3 - SELECTION STARTED Task 9: Posting a Package Case statement Design, implement and test a program to calculate the cost of posting a package by first class mail, based on the following table: Weight up to and including: Cost 100g 42p 300g 99p 450g g g g g 3.45 each extra 250g add 86p Create a design for your Form and for your Code. Show this to your teacher before you implement this program. Theory Task 1: Error detection Ask your teacher for a printed copy of this task. Higher Computing Science 23

24 Topic 4: Arrays TOPIC 4 - ARRAYS Task 10: Store 10 marks - Fill an array using a For Loop Problem specification Design and write a program that asks the user to enter 10 marks. The marks should then be displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Fill an Array EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 24

25 TOPIC 4 - ARRAYS DESIGN 1. Take in Marks() 2. Display Marks() Refine Step 1 Take in Marks 1.1 repeat 10 times 1.2 read in current mark into correct location in array 1.3 end loop Refine Step 2 Display Marks 2.1 Display heading 2.2 Display blank line 2.3 Repeat 10 times 2.4 Display current mark 2.5 End loop CODE Public Class Form1 ' Topic 4: Filling a array within a fixed loop Dim mark(9) As Integer Dim pupil As Integer Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'main steps of the problem take_in_marks() display_marks() Private Sub take_in_marks() 'ask for 10 marks For pupil = 0 To 9 mark(pupil) = Val(InputBox("Please enter the mark for pupil " & pupil + 1)) Next pupil Private Sub display_marks() 'display the marks in the listbox End Class ListBox1.Items.Add("Here are the marks for the class") ListBox1.Items.Add("") For pupil = 0 To 9 ListBox1.Items.Add("Pupil " & pupil + 1 & "- mark is " & mark(pupil)) Next pupil Higher Computing Science 25

26 TOPIC 4 - ARRAYS Load and run the program called Higher Task 10 Fill an array. OUTPUT Theory Task 2: Error detection Ask your teacher for a printed copy of this task. Task 11: Lottery Winner Using arrays & RND function. Problem Specification Design, implement and test a program to do the following: The program should prompt the user to enter 10 names and 4 different prizes. The program should select a lucky winner at random and assign them a prize also chosen at random. The program should display all ten possible winners and all 4 possible prizes. It should also display the name of the winner and the chosen prize. Create a design for your Form and for your Code. Show this to your teacher before you implement this program Higher Computing Science 26

27 TOPIC TOPIC 1 5 GETTING PARAMETER STARTEDPASSING Topic 5: Parameter Passing This section of the course shows algorithms including data flow as well as programs that use procedures. Data Flow: In/out In is the equivalent of ByRef is the equivalent of ByVal Task 12: Area of a rectangle Parameter passing Problem specification Design and write a program that asks the user to enter a length and a breadth of a rectangle. The area of the rectangle is calculated and then displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Area of a rectangle EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 27

28 TOPIC TOPIC 1 5 GETTING PARAMETER STARTEDPASSING DESIGN MAIN STEPS 1 get values from user() in/out: length, breadth 2 calculate the area() in: length, breadth in/out: area 3 display the area () in: area CODE DESIGN REFINEMENTS refine step 1 get values from user in/out: length, breadth 1.1 Read in the length 1.2 Display the length 1.3 Read in the breadth 1.4 Display the breadth refine step 2 calculate the area in: length, breadth in/out: area 2.1 multiply length by breadth to give area refine step 3 display the area in: area 1.1 display a blank line 1.2 display a message to the use giving the area Higher Computing Science 28

29 TOPIC TOPIC 1 5 GETTING PARAMETER STARTEDPASSING CODE Public Class Form1 ' this program calculates the area of a rectangle using parameter passing Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'the main steps of the problem declare the parameter data types Dim length, breadth, area As Single getvalues(length, breadth) calculatearea(length, breadth, area) displayarea(area) Private Sub getvalues(byref length, ByRef breadth) ' ask the user to enter the dimensions of the rectangle length = Val(InputBox("Please enter the length of the rectangle (in centimetres)")) ListBox1.Items.Add("The length is " & length & "cm") breadth = Val(InputBox("Please enter the breadth of the rectangle (in centimetres)")) ListBox1.Items.Add("The breadth is " & breadth & "cm") Private Sub calculatearea(byval length, ByVal breadth, ByRef area) ' this module will calculate the area area = length * breadth Private Sub displayarea(byval area) ' this module will display the area ListBox1.Items.Add("") ListBox1.Items.Add("The area of the rectangle is " & area & "cm squared") End Class Load and run Higher Task 12 Area of a rectangle. OUTPUT Test your program with sample output similar to below: Higher Computing Science 29

30 TOPIC TOPIC 1 5 GETTING PARAMETER STARTEDPASSING Task 13: Estimate Grades Parameter passing Problem specification Design, implement and test a program to do the following: The program will estimate a pupil s grade for their Nat5 Computing Science exam based on a mark from their prelim and their coursework total. Their prelim mark is out of 90 and their coursework is out of 60. The total is converted to a percentage and the following estimates are applied: >= 85% = Band 1 >= 70% = Band 2 >= 65% = Band 3 >= 60% = Band 4 >= 55% = Band 5 >= 50% = Band 6 >= 45% = Band 7 <45% = Band 8 Your program should display the total mark out of 150, their percentage and their Band estimate. Create a design for your Form and for your Code showing the data flow for the problem. Show this to your teacher before you implement this program. Higher Computing Science 30

31 TOPIC 6 USER-DEFINED FUNCTIONS Topic 6: User-defined Functions Pre-defined functions (like LEN) are already made for us. If we want to create a function we will use again and again, we create a user-defined function. Functions can input several parameters but only ever return one value. Functions are different from procedures that can input several parameters and may also return many parameters. Task 14: Calculate an area Using a function Problem specification Design and write a program that asks the user to enter the radius of a circle. The area is then calculated and displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Area of a circle (user-defined Function) EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 DESIGN MAIN STEPS 1. get radius() in/out: radius 2. calculate and display the area() in: radius CODE DESIGN REFINEMENTS Refine step 1 get radius from user 1.1 Read in the radius 1.2 Display the radius in/out: radius Higher Computing Science 31

32 TOPIC 6 USER-DEFINED FUNCTIONS Refine step 2 calculate and display the area 2.1 calculate area 2.2 display area in: radius Refine Function: get Area display the area in: radius 1. area = radius ^ 2 * return area CODE Public Class Form1 'this program calculates the area of a circle 'this version uses a user-defined function to calculate the area Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'this contains the main steps of the problem 'declare parameter data type Dim radius As Single get_radius(radius) calculate_and_display(radius) Private Sub get_radius(byref radius) ' this module will ask the user to enter the radius radius = Val(InputBox("Please enter the radius of the circle in cm")) ListBox1.Items.Add("The radius of the circle is " & radius & "cm") Private Sub calculate_and_display(byval radius) Dim area As Single area = get_area(radius) ListBox1.Items.Add("The area is " & area & "cm squared") Function get_area(radius) As Single Dim area As Single area = math.round(radius ^ 2 * 3.14,2) Return area End Function End Class Load and run Higher Task 14 Area using function. OUTPUT Test your program with the following test data: Test Type of Test Test data Expected Result 1 Normal Radius = 5 Area = Normal Radius = 6.7 Area = Extreme Radius = Area = Higher Computing Science 32

33 TOPIC 6 USER-DEFINED FUNCTIONS Task 15: Input Validation Function Problem specification Design a program which will ask the user to enter two numbers between 1 and 10. The program will then find the sum of these numbers. Inputs from the user must be validated. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Validation using a Function EXIT Button: Name: cmdexit Text: EXIT CLEAR button: Name: cmdclear Text: CLEAR START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 DESIGN MAIN STEPS 1 get_numbers() in/out: num1, num2 2 calculate and display total() in: num1, num2 DESIGN REFINEMENTS Refine step 1 get numbers 1.1 Validate number 1 using function 1.2 Validate number 2 using function in/out: num1, num2 Higher Computing Science 33

34 TOPIC 6 USER-DEFINED FUNCTIONS Refine step 2 calculate and display total 2.1 calculate sum of number 1 and number calculate and display answer in: radius Refine Function: get valid number in: prompt, low, high out: number 1. ask the user to enter a number between low and high 2. Loop while the number is less than low or greater than high 3. Display an error message to the user 4. Ask the user to re-enter the number 5. End loop 6. return number CODE Public Class Form1 'program using a function to validate inputs from user Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'declare data flow parameters Dim num1, num2 As Integer 'main steps get_values(num1, num2) calculate_and_display_total(num1, num2) Private Sub get_values(byref num1, ByRef num2) 'procudeure to input numbers from user num1 = get_valid_number("please enter a number between, 1, 10) num2 = get_valid_number("please enter a number between, 1, 10) Private Sub calculate_and_display_total(byval num1, ByVal num2) 'procedure to calculate and display values 'declare local variable Dim answer As Integer answer = num1 + num2 ListBox1.Items.Add(num1 & " + " & num2 & " = " & answer) Function get_valid_number(byval prompt, byval low, byval high) As Integer 'function used to validate a number between 2 boundaries Dim number as integer number = Val(InputBox(prompt & low & and & high)) Do While number < low Or number > high MsgBox("That number is invalid. Please try again") number = Val(InputBox(prompt & low & and & high)) Loop Return number End Function End Class Load and run Higher Task 15 Input Validation Higher Computing Science 34

35 TOPIC 6 USER-DEFINED FUNCTIONS OUTPUT Test your program with the following test data: Test Type of Test Test data Expected Result 1 Normal Num1 = 4 num2 = = 11 2 Normal Num1 = 8 num2 = = 13 3 Extreme Num1 = 1 num2 = = 11 4 Extreme Num1 = 2 num2 = Exceptional Num1 = 14 num2 = 7 Error message for num1 6 Exceptional Num1 = 4 num2 = 78 Error message for num2 Task 16: Input Validation User defined functions Problem specification Design, implement and test a program to do the following: The user should enter 3 different values and each should be validated as shown: I. prompt the user to enter either a yes or a no. the program should also accept yes, no, yes, NO, no etc II. III. prompt the user to enter a telephone number. The program should only accept a number starting with the digit 0 and with a total of 11 digits. Assume no spaces are allowed. Prompt the user to enter a password which can include any character except for a space, and must be more than 6 characters long. Create a design for your Form and for your Code. Show this to your teacher before you implement this program. Higher Computing Science 35

36 TOPIC 7 STANDARD ALGORITHMS Topic 7: Standard Algorithms In the design and development of software, there are certain tasks which are needed over and over again. For example, almost every program uses input validation to prevent a user entering data which cannot be acceptable and which might cause the program to fail. Rather than every programmer having to write the code for an input validation routine, this module of code can be taken from a module library to be re-used or adapted. There are many other standard algorithms, including: Finding the maximum value Finding the minimum value Linear Search Counting Occurrences Task 17: Highest Mark find maximum algorithm Task 17: Finding the Maximum Value Problem specification Design and write a program that generates 5 random marks between 1 and 100 and stores them in an array. The marks are displayed then the highest mark is displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Findinf the Maximum EXIT Button: Name: cmdexit Text: EXIT START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 36

37 TOPIC 7 STANDARD ALGORITHMS DESIGN MAIN STEPS 1. initialise variables() in/out: max, marks_array 2. fill array with data () in/out: marks_array 3. display the array in: marks_array 4. find the maximum value in: marks_array in/out: max 5. display max in: max DESIGN REFINEMENTS Refine step 1 initialise variables() 1.1 clear contents of list box 1.2 start loop counter from 0 to set marks_array (loop counter) to End loop 1.5 Set max to 0 Refine step 2 fill array with data () in/out: max, marks_array in/out: marks_array 2.1 start loop counter from 0 to set marks_array (loop counter) to a random value between 1 and End loop Refine step 3 display the array in: marks_array 3.1 display title Here are the marks: 3.2 display a blank line 3.3 start loop counter from 0 to display marks_array (loop counter) 3.5 End loop Refine step 4 find the maximum value in: marks_array in/out: max 3.1 set max to equal the first element in the array 3.2 start loop for the rest of the array 3.3 If marks_array (loop counter) is greater than max then 3.4 set max to equal marks_array (loop counter) 3.5 End If 3.6 End loop Refine step 4 display max in: max 3.1 Display a blank line 3.2 Display The highest mark is and max Higher Computing Science 37

38 TOPIC 7 STANDARD ALGORITHMS CODE Public Class Form1 'Standard Algorithm task - Find the max Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'contains the main steps of the problem 'declare the parameters Dim marks_array (4) As Integer Dim max As Integer Randomize() initialise(max, marks_array) fill_random_marks(marks_array) display_array(marks_array) find_max(max, marks_array) display_maximum(max) Private Sub initialise(byref max, ByRef marks_array) ' this module sets an initial value to the parameters Dim index As Integer ListBox1.Items.Clear() For index = 0 To 4 marks_array(index) = 0 Next max = 0 Private Sub fill_random_marks(byref marks_array) ' this module will populate the array with random marks between 1 and 100 Dim index As Integer For index = 0 To 4 marks_array(index) = Int(Microsoft.VisualBasic.Rnd() * 100) + 1 Next Private Sub display_array(byref marks_array) 'this module will display the random marks Dim index As Integer ListBox1.Items.Add("Here are the marks: ) ListBox1.Items.Add("") For index = 0 To 4 ListBox1.Items.Add(marks_array(index)) Next Higher Computing Science 38

39 TOPIC 7 STANDARD ALGORITHMS Private Sub find_max(byref max, ByRef marks_array) ' this module will find the highest mark in the array Dim index As Integer max = marks_array(0) For index = 1 To 4 If marks_array(index) > max Then max = marks_array(index) End If Next Private Sub display_maximum(byval max) ' this module will display the highest mark ListBox1.Items.Add("") ListBox1.Items.Add("The highest marks is & max) End Class Load and run Higher Task 17 Highest mark. OUTPUT Test your program works by running it a few times. Ensure the following works correctly: The program picks up the correct value each time The program is correct when the max value is the first item in the array Higher Computing Science 39

40 TOPIC 7 STANDARD ALGORITHMS Task 18: Find the Min and Max temperature Problem specification Design, implement and test a program to do the following: The program should ask the user to enter the average temperature that occurred each day for one week. The program will display these temperatures and then display the highest and lowest temperature for the week. Example: Day 1: Day 2: Day 3: Day 4: Day 5: Day 6: Day 7: 12 degrees 10 degrees 17 degrees 6 degrees 18 degrees 9 degrees -6 degrees Highest temperature was 18 degrees Lowest temperature was -6 degrees Create a design for your Form and for your Code showing the data flow for the problem. Show this to your teacher before you implement this program. Task 19: Find the days that had the min and max temperature Problem specification Improve your last program so that it displays output like this:- Sunday: Monday: Tuesday: Wednesday: Thursday : Friday: Sunday: 12 degrees 10 degrees 17 degrees 6 degrees 18 degrees 9 degrees -6 degrees Highest temperature was 18 degrees on Thursday Lowest temperature was -6 degrees on Sunday Create a design for your Form and for your Code showing the data flow for the problem. Show this to your teacher before you implement this program. Higher Computing Science 40

41 TOPIC 7 STANDARD ALGORITHMS Task 20: Mark Counter - Count Occurrences Problem specification Design and write a program that asks the user to enter 10 marks between 0 and 100. The marks should be displayed then the user should be asked to enter a target mark that they want to count the occurrences of. The number of times that the target mark appears in the array should be displayed. FORM DESIGN PROPERTIES HEADING Label: Name: lblheading Text: Findinf the Maximum EXIT Button: Name: cmdexit Text: EXIT START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 41

42 TOPIC 7 STANDARD ALGORITHMS DESIGN MAIN STEPS 1. initialise variables in/out: marks_array, target, counter 2. take in marks in/out: marks_array 3. target = validated number in: prompt, low, high in/out: target 4. count occurrences of target in: target, marks_array, in/out: counter 5. display results in: marks_array, target, counter DESIGN REFINEMENTS Refine step 1 initialise variables() in/out: marks_array, target, counter 1.1 start loop counter from 0 to set marks_array(loop counter) to End loop 1.4 Set counter to Set target to 0 Refine step 2 take in marks in/out: marks_array 2.1 start loop counter from 0 to marks_array(loop counter) = validated number (use get_valid_number function) 2.3 End loop Refine step 3: Function: get valid number in: prompt, low, high out: number 1. ask the user to enter a number between low and high 2. Loop while the number is less than low or greater than high 3. Display an error message to the user 4. Ask the user to re-enter the number 5. End loop 6. return number Refine step 4 count occurrences of target 4.1 start loop counter from 0 to If marks_array(loop counter) = target 4.3 add 1 to counter 4.4 End If statement 4.5 End loop Refine step 5 display results in: target, marks_array, in/out: counter in: marks_array, target, counter 5.1 Display Here are the marks 5.2 Start loop counter from 0 to Display marks_array(loop counter) 5.4 End loop 5.5 Display a blank line 5.6 Display The target being counted is and target 5.7 Display it was found and counter and times Higher Computing Science 42

43 TOPIC 7 STANDARD ALGORITHMS CODE Public Class Form1 ' Standard algorithms task - Count Occurences of a value in a list Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'declare the parameters used Dim marks_array(9) As Integer Dim target, counter As Integer 'main steps of the problem initialise(marks_array, target, counter) take_in_marks(marks_array) target = get_valid_number("what mark do you want to search for? Enter a mark between, 0, 100) count_occurences(marks_array, target, counter) display_results(marks_array, target, counter) Private Sub initialise(byref marks_array, ByRef target, ByRef counter) 'set an initial value to all parameters used in the program Dim index As Integer For index = 0 To 9 marks_array(index) = 0 Next counter = 0 target = 0 Private Sub take_in_marks(byref marks_array) 'populate the array with valid marks from the user Dim index As Integer For index = 0 To 9 marks_array(index) = get_valid_number("please enter the mark for pupil " & index + 1, 1, 100) Next Function get_valid_number(byval prompt, byval low, byval high) As Integer 'function used to validate a number between 2 boundaries Dim number as integer number = Val(InputBox(prompt & low & and & high)) Do While number < low Or number > high MsgBox("That number is invalid. Please try again") number = Val(InputBox(prompt & low & and & high)) Loop Return number End Function Higher Computing Science 43

44 TOPIC 7 STANDARD ALGORITHMS Private Sub count_occurences(byref marks_array, ByVal target, ByRef counter) 'count how many times the target appears in the list Dim index As Integer For index = 0 To 9 If marks_array(index) = target Then counter = counter + 1 End If Next Private Sub display_results(byref marks_array, ByVal target, ByVal counter) 'display the marks entered, the targer being searched for and the number of occurrences Dim pupil As Integer End Class ListBox1.Items.Add("Here are the marks:") For index = 0 To 9 ListBox1.Items.Add(marks_array(index)) Next ListBox1.Items.Add("") ListBox1.Items.Add("The target being counted is :" & target) ListBox1.Items.Add("It was found " & counter & " times") Load and run Higher Task 20 Count Occurrences. OUTPUT Higher Computing Science 44

45 TOPIC 7 STANDARD ALGORITHMS Test your program with the following test data: Test Type of Test 1 Normal 2 Normal 3 Extreme 4 Extreme 5 Exceptional 6 Exceptional Test data 15,45,47,45,89,62,36,34,45,25 TARGET = 45 15,95,47,45,89,62,36,34,55,25 TARGET = 45 45,45,45,45,45,45,45,45,45,45 TARGET = 45 0,0,1,1,99,99,100,100,0,100 TARGET = 45 Enter mark below 0 and over 100 Enter target below 0 and over 100 Expected Result Target of 45 appears 3 times Target of 45 appears 1 times Target of 45 appears 10 times Target of 45 appears 0 times Error message for mark Error message for target Task 21: Count the number of days that were a target temperature Count Occurrences Problem specification Improve your temperature program so that it also asks the user to enter a target temperature and displays output like this:- Sunday: Monday: Tuesday: Wednesday: Thursday : Friday: Sunday: 12 degrees 10 degrees 17 degrees 10 degrees 18 degrees 9 degrees -6 degrees Highest temperature was 18 degrees on Thursday Lowest temperature was -6 degrees on Sunday The number of days that it was 10 degrees was 2. Create a design for your Form and for your Code showing the data flow for the problem. Show this to your teacher before you implement this program. Higher Computing Science 45

46 TOPIC 7 STANDARD ALGORITHMS Task 22: Who got a target mark - Linear search Problem specification Design and write a program that fills an array with 10 marks then asks the user to enter a target mark. The program should then display the number of each pupil who got the target mark. FORM DESIGN PROPERTIES Property Property HEADING Label: Name: lblheading Text: Linear Search EXIT Button: Name: cmdexit Text: EXIT START button: Name: cmdstart Text: START LISTBOX1: Name: listbox1 Higher Computing Science 46

47 DESIGN MAIN STEPS TOPIC 7 STANDARD ALGORITHMS 1. initialise variables() in/out: target 2. display marks () in: marks_array 3. target = validated number in: prompt, low, high out: target 4. linear search in: marks_array, target DESIGN REFINEMENTS Refine step 1 initialise variables() in/out: target 1.1 clear the contents of the listbox 1.2 Set target to 0 Refine step 2 display marks in: marks_array 2.1 Display Here are the marks 2.2 Display a blank line 2.3 start loop counter from 0 to display the pupils mark 2.5 end loop Refine step 3: Function: get valid number in: prompt, low, high out: number 1. ask the user to enter a number between low and high 2. Loop while the number is less than low or greater than high 3. Display an error message to the user 4. Ask the user to re-enter the number 5. End loop 6. return number Refine step 4 linear search in: marks_array, target 4.1 set flag to false 4.2 Display a blank line 4.3 Start loop from 0 to If the value in marks_array(loop counter) = target 4.5 Display the position of this target loop counter 4.6 Set flag to true 4.7 End if statement 4.8 End loop 4.9 If flag is false display Target not found in list Higher Computing Science 47

48 TOPIC 7 STANDARD ALGORITHMS CODE Public Class Form1 ' Standard Algorithms - Linear Search Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click ' declare parameters and initialise array with values Dim marks_array() As Integer = {10, 15, 14, 13, 9, 14, 12, 18, 9, 10} Dim target As Integer initialise(target) display_marks(marks_array) target = get_valid_number("what mark do you want to search for? Enter a number between ", 0, 20)) linear_search(marks_array, target) Private Sub initialise(byref target) 'this module will set an initial value for the target ListBox1.Items.Clear() target = 0 Private Sub display_marks(marks_array) 'this module will display the values stored in the array Dim index As Integer ListBox1.Items.Add("Here are the marks out of 20:") ListBox1.Items.Add("") For index = 0 To 9 ListBox1.Items.Add("Pupil " & index + 1 & ": " & marks_array(index)) Next Private Sub linear_search(byref marks_array, ByVal target) 'this module will search the array for occurences of the target value and report their position Dim index As Integer Dim found As Boolean found = False ListBox1.Items.Add("") For index = 0 To 9 If marks_array(index) = target Then ListBox1.Items.Add("The target of " & target & " was found for pupil " & index + 1) found = True End If Next If found = False Then ListBox1.Items.Add("Target " & target & " not found in the list") Function get_valid_number(byval prompt, byval low, byval high) As Integer 'function used to validate a number between 2 boundaries Dim number as integer number = Val(InputBox(prompt & low & and & high)) Do While number < low Or number > high MsgBox("That number is invalid. Please try again") number = Val(InputBox(prompt & low & and & high)) Loop Return number End Function End Class Higher Computing Science 48

49 TOPIC 7 STANDARD ALGORITHMS Load and run Higher Task 22 Linear search. OUTPUT Your output should look like this: Adapt your program to work with the following test data: Test Type of Test 1 Normal 2 Normal 3 Extreme 4 Extreme 5 Exceptional 6 Exceptional Test data 11, 12, 10, 12, 10, 19, 18, 20, 12, 8 TARGET = 12 11, 12, 10, 12, 10, 19, 18, 20, 12, 8 TARGET = 10 11,11,11,11,11,11,11,11,11,11 TARGET = 20 0,0,1,1,9,9,10,20,10,18 TARGET = 0 0,0,1,1,9,9,10,20,10,18 TARGET = -3 0,0,1,1,9,9,10,20,10,18 TARGET = 21 Expected Result Target appears for pupil 2 Target appears for pupil 4 Target appears for pupil 9 Target appears for pupil 3 Target appears for pupil 5 Target 20 not on the list Target appears for pupil 1 Target appears for pupil 2 Error message for target Error message for target Higher Computing Science 49

50 TOPIC 7 STANDARD ALGORITHMS Task 23: Search for the days that were a target temperature Problem specification Improve your temperature program so that it also displays the days that matched the target temperature. It should display output like this:- Sunday: Monday: Tuesday: Wednesday: Thursday : Friday: Sunday: 12 degrees 10 degrees 17 degrees 10 degrees 18 degrees 9 degrees -6 degrees Highest temperature was 18 degrees on Thursday Lowest temperature was -6 degrees on Sunday The number of days that it was 10 degrees was 2. It was 10 degrees on Monday. It was 10 degrees on Wednesday. Higher Computing Science 50

51 TOPIC 8 READING FROM A SEQUENTIAL FILE Topic 8 Reading from a sequential file Task 24: Read hotel data from a Comma Separated Value file and store it in arrays Problem specification Design and create a program that reads data from a file and stores it in arrays. The output should look like this:- The Comma Separated Value file looks like this:- Higher Computing Science 51

52 TOPIC 8 READING FROM A SEQUENTIAL FILE DESIGN MAIN STEPS 1. initialize in/out: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels 2. read_file_into_records() in/out: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels 3. display_records() in: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels DESIGN REFINEMENTS Refine step 1 initialise in/out: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels 1.1 start loop counter from 1 to set hotelname(loop counter) to 1.3 set hotelrating(loop counter) to set hotelcity(loop counter) to 1.5 set hotelpricepernight(loop counter) to set hotelmealsincluded(loop counter) to 1.7 end loop 1.8 set countofhotels to 0 Refine step 2 read_file_into_arrays() in/out: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels 2.1 Using myreader to Open a file to read from it 2.2 set countofhotels to loop while not at the end of the data 2.4 try 2.5 set currentrow to a line in the file 2.6 add 1 to countofhotels 2.7 set allhotels(countofhotels).hotelname field to string 0 in the current line 2.8 set allhotels(countofhotels). hotelrating field to value 1 in the current line 2.9 set allhotels(countofhotels). hotelcity field to string 2 in the current line 2.10 set allhotels(countofhotels). hotelpricepernight field to value 3 in the current line 2.11 set allhotels(countofhotels). hotelmealsincluded field to string 4 in the current line 2.12 Catch file error 2.13 display error message 2.1 end try 2.1 end loop 2.1 End Using 2 Higher Computing Science 52

53 TOPIC 8 READING FROM A SEQUENTIAL FILE Refine step 3 display_records() in/out: hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels 3.1 start loop counter from 1 to countofhotels 3.2 send allhotels(loop counter).hotelname to display 3.3 send allhotels(loop counter).hotelrating to display 3.4 send allhotels(loop counter).hotelcity to display 3.5 send allhotels(loop counter).hotelpricepernight to display 3.6 send allhotels(loop counter).hotelmealsincluded to display 3.7 end loop Public Class Form1 Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click Dim hotelname(5) As String Dim hotelrating(5) As Integer Dim hotelcity(5) As String Dim hotelpricepernight(5) As Single Dim hotelmealsincluded(5) As String Dim countofhotels As Integer initialise(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) read_file_into_arrays(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) display_arrays(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) Private Sub initialise(byref hotelname, ByRef hotelrating, ByRef hotelcity, ByRef hotelpricepernight, ByRef hotelmealsincluded, ByRef countofhotels) Dim index As Integer For index = 1 To 5 hotelname(index) = "" hotelrating(index) = 0 hotelcity(index) = "" hotelpricepernight(index) = 0 hotelmealsincluded(index) = "" Next countofhotels = Higher Computing Science 53

54 TOPIC 8 READING FROM A SEQUENTIAL FILE Private Sub read_file_into_arrays(byref hotelname, ByRef hotelrating, ByRef hotelcity, ByRef hotelpricepernight, ByRef hotelmealsincluded, ByRef countofhotels) 'reads a comma separated value file into 5 arrays Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("N:\Visual Studio 2012\Hotel Info.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim currentrow As String() ' Dim numberoffields As Integer While Not MyReader.EndOfData Try currentrow = MyReader.ReadFields() 'numberoffields = currentrow.getupperbound(0) ' MsgBox(numberOfFields) countofhotels = countofhotels + 1 hotelname(countofhotels) = currentrow(0).tostring hotelrating(countofhotels) = Val(currentRow(1).ToString) hotelcity(countofhotels) = currentrow(2).tostring hotelpricepernight(countofhotels) = Val(currentRow(3).ToString) hotelmealsincluded(countofhotels) = currentrow(4).tostring Catch ex As Microsoft.VisualBasic. FileIO.MalformedLineException MsgBox("Line " & ex.message & "is not valid and will be skipped.") End Try End While End Using Private Sub display_arrays(byref hotelname, ByRef hotelrating, ByRef hotelcity, ByRef hotelpricepernight, ByRef hotelmealsincluded, ByVal countofhotels) For index = 1 To countofhotels ListBox1.Items.Add(hotelName(index)) ListBox2.Items.Add(hotelRating(index)) ListBox3.Items.Add(hotelCity(index)) ListBox4.Items.Add(hotelPricePerNight(index)) ListBox5.Items.Add(hotelMealsIncluded(index)) Next Private Sub cmdexit_click(sender As Object, e As EventArgs) Handles cmdexit.click End End Class Copy the CSV file called Hotel Info into your Visual Studio 2012 folder. Load and run Higher Task 24 Read a hotel file into arrays. Higher Computing Science 54

55 TOPIC 8 READING FROM A SEQUENTIAL FILE Task 25: Notice the difference here actual and formal parameter can have different names Load and run Higher Task 25 Read a hotel file into arrays using standard modules. Public Class Form1 Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click 'This module contains the main program Dim hotelname(5) As String Dim hotelrating(5) As Integer Dim hotelcity(5) As String Dim hotelpricepernight(5) As Single Dim hotelmealsincluded(5) As String Dim countofhotels As Integer initialise(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) read_file_into_arrays(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) display_arrays(hotelname, hotelrating, hotelcity, hotelpricepernight, hotelmealsincluded, countofhotels) Private Sub initialise(byref hotelname, ByRef hotelrating, ByRef hotelcity, ByRef hotelpricepernight, ByRef hotelmealsincluded, ByRef countofhotels) 'This module will initialise the records so that the string fields are set to "" and the numeric fields, countofhotels and are set to 0 Dim index As Integer For index = 1 To 5 hotelname(index) = "" hotelrating(index) = 0 hotelcity(index) = "" hotelpricepernight(index) = 0 hotelmealsincluded(index) = "" Next countofhotels = Higher Computing Science 55

56 TOPIC 8 READING FROM A SEQUENTIAL FILE Private Sub read_file_into_arrays(byref array1, ByRef array2, ByRef array3, ByRef array4, ByRef array5, ByRef count) 'this module reads a comma separated value file into some arrays Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("N:\Visual Studio 2012\Hotel Info.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim currentrow As String() While Not MyReader.EndOfData Try currentrow = MyReader.ReadFields() 'reads a line of the csv and stores it in the string variable called currentrow count = count + 1 'keeps track of which line of the file was read a value a value puts the values that are separated by the commas into the arrays array1(count) = currentrow(0).tostring array2(count) = Val(currentRow(1).ToString) 'val converts a string to array3(count) = currentrow(2).tostring array4(count) = Val(currentRow(3).ToString) 'val converts a string to array5(count) = currentrow(4).tostring End While End Using Catch ex As Microsoft.VisualBasic. FileIO.MalformedLineException MsgBox("Line " & ex.message & "is not valid and will be skipped.") End Try Private Sub display_arrays(byref array1, ByRef array2, ByRef array3, ByRef array4, ByRef array5, ByVal count) 'this module will display the contents of some arrays Dim index As Integer For index = 1 To count ListBox1.Items.Add(array1(index)) ListBox2.Items.Add(array2(index)) ListBox3.Items.Add(array3(index)) ListBox4.Items.Add(array4(index)) ListBox5.Items.Add(array5(index)) Next Private Sub cmdexit_click(sender As Object, e As EventArgs) Handles cmdexit.click End End Class Higher Computing Science 56

57 TOPIC 8 READING FROM A SEQUENTIAL FILE Task 26: Improve the hotel data program so that it uses the Find max and Linear search procedures Problem specification Improve the hotel data program that reads data from a file and stores it in arrays so that it also displays the highest rating and the hotels that had that rating. To test it you should change your Comma Separated Value file so that the Paisley Palm hotel has a rating of 5. The output should look like this:- Task 27: Read pupil data from a Comma Separated Value file and store it in arrays Problem specification Design and create a program that reads data from a file and stores it in arrays. The data should include Forename, Surname, Register Class, Date of Birth. You will need to create a Comma Separated Value file like this:- John, Smith,5L,18/1/1998 Susan, Brown,5M,20/3/1998 Katie,Jones,5L,12/4/1998 Kara,Green,5M,2/1/1998 Higher Computing Science 57

58 TOPIC 9 USING RECORDS Topic 9 Using records Task 28: Enter hotel data and store it in records Problem specification Design and create a program that allows the user to enter data about hotels and stores it in records. It should display output like this:- The data will be stored in records in an array of records like this:- Array hotelname hotelrating hotelcity hotelpricepernight hotelmealsincluded Index 0 1 Glasgow 5 Glasgow Breakfast Caledonian 2 Aberdeen Arms 3 Aberdeen Breakfast 3 Paisley Palm 4 Paisley None 4 Premier Inn 2 Glasgow None 5 Premier Inn 2 Carlisle All meals Higher Computing Science 58

59 TOPIC 9 USING RECORDS DESIGN MAIN STEPS 1. initialise variables() in/out: allhotels, countofhotels 2. store_data_in_records() in/out: allhotels, countofhotels 3. display_records() in: allhotels, countofhotels DESIGN REFINEMENTS Refine step 2 initialise variables() in/out: allhotels, countofhotels 1.1 set countofhotels to start loop counter from 1 to countofhotels 1.3 set allhotels(loop counter).hotelname to 1.4 set allhotels(loop counter).hotelrating to 1.5 set allhotels(loop counter).hotelcity to 1.6 set allhotels(loop counter).hotelpricepernight to 1.7 set allhotels(loop counter).hotelmealsincluded to 1.8 end loop Refine step 2 store_data_in_records() in/out: allhotels, countofhotels 2.1 start loop counter from to countofhotels 2.2 receive set allhotels(loop counter).hotelname from keyboard 2.3 receive set allhotels(loop counter).hotelrating from keyboard 2.4 receive set allhotels(loop counter).hotelcity from keyboard 2.5 receive set allhotels(loop counter).hotelpricepernight from keyboard 2.6 receive set allhotels(loop counter).hotelmealsincluded from keyboard 2.7 end loop Refine step 3: display_records() in: allhotels, countofhotels 3.1 start loop counter from to countofhotels 3.2 send allhotels(loop counter).hotelname to display 3.3 send allhotels(loop counter).hotelrating to display 3.4 send allhotels(loop counter).hotelcity to display 3.5 send allhotels(loop counter).hotelpricepernight to display 3.6 send allhotels(loop counter).hotelmealsincluded to display 3.7 end loop Higher Computing Science 59

60 TOPIC 9 USING RECORDS Public Class Form1 Structure hotelrecord 'Declare the strucre of a record Dim hotelname As String Dim hotelrating As Integer Dim hotelcity As String Dim hotelpricepernight As Single Dim hotelmealsincluded As String End Structure Private Sub cmdstart_click(sender As Object, e As EventArgs) Handles cmdstart.click ' Main program Dim countofhotels As Integer Dim allhotels(5) As hotelrecord initialise(allhotels, countofhotels) store_data_in_records(allhotels, countofhotels) display_records(allhotels, countofhotels) Private Sub initialise(byref allhotels() As hotelrecord, ByRef countofhotels As Integer) 'This module gives the records and countofhotels initial values Dim index As Integer countofhotels = 5 'Set the number of hotels that are to be stored For index = 1 To countofhotels allhotels(index).hotelname = "" allhotels(index).hotelrating = 0 allhotels(index).hotelcity = "" allhotels(index).hotelpricepernight = 0 allhotels(index).hotelmealsincluded = "" Next Private Sub store_data_in_records(byref allhotels() As hotelrecord, ByVal countofhotels As Integer) 'This module invites the user to enter data that is stored in an array of records Dim index As Integer For index = 1 To countofhotels allhotels(index).hotelname = InputBox("Enter the name of hotel " & index) allhotels(index).hotelrating = InputBox("Enter the rating of hotel " & index) allhotels(index).hotelcity = InputBox("Enter the city of hotel " & index) allhotels(index).hotelpricepernight = InputBox("Enter the price per night of hotel " & index) allhotels(index).hotelmealsincluded = InputBox("Enter the meals included of hotel " & index) Next Higher Computing Science 60

61 TOPIC 9 USING RECORDS Private Sub display_records(byref allhotels() As hotelrecord, ByVal countofhotels As Integer) 'This module displays the data that is stored in an array of records Dim index As Integer For index = 1 To countofhotels ListBox1.Items.Add(allHotels(index).hotelName) ListBox2.Items.Add(allHotels(index).hotelRating) ListBox3.Items.Add(allHotels(index).hotelCity) ListBox4.Items.Add(allHotels(index).hotelPricePerNight) ListBox5.Items.Add(allHotels(index).hotelMealsIncluded) Next Private Sub cmdexit_click(sender As Object, e As EventArgs) Handles cmdexit.click End End Class Load and run the program called Higher Task 28 Enter hotel data into records. Try changing it store a different number of records. Higher Computing Science 61

62 TOPIC 9 USING RECORDS Task 29: Read hotel data from a Comma Separated Value file and store it in records Problem specification Improve the hotel records program so that the data is read from a file instead of the user entering it. The output should still looks like this:- The Comma Separated Value file looks like this:- Higher Computing Science 62

Programming with Visual Studio Higher (v. 2013)

Programming with Visual Studio Higher (v. 2013) Programming with Visual Studio Higher (v. 2013) Contents/Requirements Checklist Multiple selection: using ifs & case While Loops Using arrays Filling arrays Displaying array contents Types of variables:

More information

St. Benedict s High School. Computing Science. Software Design & Development. (Part 1 Computer Programming) National 5

St. Benedict s High School. Computing Science. Software Design & Development. (Part 1 Computer Programming) National 5 Computing Science Software Design & Development (Part 1 Computer Programming) National 5 VARIABLES & DATA TYPES Variables provide temporary storage for information that will be needed while a program is

More information

Objectives/Outcomes. Introduction: If we have a set "collection" of fruits : Banana, Apple and Grapes.

Objectives/Outcomes. Introduction: If we have a set collection of fruits : Banana, Apple and Grapes. 1 September 26 September One: Sets Introduction to Sets Define a set Introduction: If we have a set "collection" of fruits : Banana, Apple Grapes. 4 F={,, } Banana is member "an element" of the set F.

More information

Computing Science Unit 1

Computing Science Unit 1 Computing Science Unit 1 Software Design and Development Programming Practical Tasks Business Information Technology and Enterprise Contents Input Validation Find Min Find Max Linear Search Count Occurrences

More information

Mental Math. Grade 9 Mathematics (10F) General Questions. 2. What is the volume of a pool that measures 7 m by 3 m by 2 m? 42 m 3

Mental Math. Grade 9 Mathematics (10F) General Questions. 2. What is the volume of a pool that measures 7 m by 3 m by 2 m? 42 m 3 E 1 Substrand: -D Objects and 2-D Shapes Specific Learning Outcome: 9.SS.2 1. What value of m satisfies the equation 5 m 1? m 4 4 5 2. What is the volume of a pool that measures 7 m by m by 2 m? 42 m.

More information

Functions and Procedures. Functions. Built In Functions. Built In Functions in VB FIT 100 FIT 100

Functions and Procedures. Functions. Built In Functions. Built In Functions in VB FIT 100 FIT 100 Functions Functions and Procedures Similarities: Little mini-programs that are named and include a series of code statements (instructions) to be executed when called. Differences: Functions have a specific

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

CS 101, Spring 2016 March 22nd Exam 2

CS 101, Spring 2016 March 22nd Exam 2 CS 101, Spring 2016 March 22nd Exam 2 Name: Question 1. [3 points] Which of the following loop statements would most likely cause the loop to execute exactly n times? You may assume that n will be set

More information

Using Variables to Write Pattern Rules

Using Variables to Write Pattern Rules Using Variables to Write Pattern Rules Goal Use numbers and variables to represent mathematical relationships. 1. a) What stays the same and what changes in the pattern below? b) Describe the pattern rule

More information

Seventh Grade Spiraling Review Week 1 of First Six Weeks

Seventh Grade Spiraling Review Week 1 of First Six Weeks Week of First Six Weeks Note: Record all work in your math journal. Day Indicate if each of the given numbers below is equivalent to, less than, or greater than. Justify each response. 0.0, 0 4.7, %,,

More information

MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING. 9691/22 Paper 2 (Written Paper), maximum raw mark 75

MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING. 9691/22 Paper 2 (Written Paper), maximum raw mark 75 UNIVERSITY OF CAMBRIDGE INTERNATIONAL EXAMINATIONS GCE Advanced Subsidiary Level and GCE Advanced Level MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING 9691/22

More information

Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column

Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column SQL Functions Aggregate Functions Some Basic Aggregate Functions OUTPUT COUNT() The number of rows containing non-null values MIN() The minimum attribute value encountered in a given column MAX() The maximum

More information

PAF Chapter Prep Section Mathematics Class 6 Worksheets for Intervention Classes

PAF Chapter Prep Section Mathematics Class 6 Worksheets for Intervention Classes The City School PAF Chapter Prep Section Mathematics Class 6 Worksheets for Intervention Classes Topic: Percentage Q1. Convert it into fractions and its lowest term: a) 25% b) 75% c) 37% Q2. Convert the

More information

Problem Solving. Problem Solving Concept for Computer Science

Problem Solving. Problem Solving Concept for Computer Science Problem Solving Problem Solving Concept for Computer Science by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering azida@ump.edu.my OER Problem Solving by Noor Azida Binti Sahabudin

More information

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark]

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark] Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.

More information

= = 170

= = 170 Section 1 20 marks. In your exam, this section should take 20 minutes to complete. The questions below should take no more than 30 mins. 1. Convert the value 52 into an 8-bit binary number. Show your working.

More information

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true; Programming in C++ If Statements If the sun is shining Choice Statements if (the sun is shining) go to the beach; True Beach False Class go to class; End If 2 1 Boolean Data Type (false, ) i.e. bool bflag;

More information

Chapter 2.4: Common facilities of procedural languages

Chapter 2.4: Common facilities of procedural languages Chapter 2.4: Common facilities of procedural languages 2.4 (a) Understand and use assignment statements. Assignment An assignment is an instruction in a program that places a value into a specified variable.

More information

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester Programming Language Control Structures: Selection (switch) Eng. Anis Nazer First Semester 2018-2019 Multiple selection choose one of two things if/else choose one from many things multiple selection using

More information

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ). LOOPS 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ). 2-Give the result of the following program: #include

More information

6 th Grade Math Cylinder Task. c) Draw a net (pattern) for the manufacturer to use to make the can.

6 th Grade Math Cylinder Task. c) Draw a net (pattern) for the manufacturer to use to make the can. 6 th Grade Math a) Explain what is meant by surface area. What steps would you take to find the surface area of a cylinder? b) One of the major expenses in manufacturing a can is the amount of metal that

More information

Whole Numbers. Integers and Temperature

Whole Numbers. Integers and Temperature Whole Numbers Know the meaning of count and be able to count Know that a whole number is a normal counting number such as 0, 1, 2, 3, 4, Know the meanings of even number and odd number Know that approximating

More information

Grade 8 Common Mathematics Assessment Multiple Choice Answer Sheet Name: Mathematics Teacher: Homeroom: Section A No Calculator Permitted

Grade 8 Common Mathematics Assessment Multiple Choice Answer Sheet Name: Mathematics Teacher: Homeroom: Section A No Calculator Permitted Multiple Choice Answer Sheet Name: Mathematics Teacher: Homeroom: Section A No Calculator Permitted Calculator Permitted. A B C D 2. A B C D. A B C D 4. A B C D 5. A B C D 6. A B C D 7. A B C D 8. A B

More information

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) END-TERM EXAMINATION DECEMBER 2006 Exam. Roll No... Exam Series code: 100274DEC06200274 Paper Code : MCA-207 Subject: Front End Design Tools Time: 3 Hours

More information

LEVEL 6. Level 6. Page (iv)

LEVEL 6. Level 6. Page (iv) LEVEL 6 Number Page N9... Fractions, Decimals and Percentages... 69 N20... Improper Fractions and Mixed Numbers... 70 N2... Prime Numbers, HCF and LCM... 7 Calculating C22... Percentage of an Amount...

More information

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1 Arrays Chapter 8 Spring 2017, CSUS Array Basics Chapter 8.1 1 Array Basics Normally, variables only have one piece of data associated with them An array allows you to store a group of items of the same

More information

SRPSD Math Common Assessment

SRPSD Math Common Assessment Grade 8 SRPSD Math Common Assessment srsd119 Instructions Administering the Assessments 1. This assessment has been developed with the intention of being split up into individual outcomes and given upon

More information

Introduction to Computer Science Unit 4B. Programs: Classes and Objects

Introduction to Computer Science Unit 4B. Programs: Classes and Objects Introduction to Computer Science Unit 4B. Programs: Classes and Objects This section must be updated to work with repl.it 1. Copy the Box class and compile it. But you won t be able to run it because it

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1 Lecture 9 Reminder: Programming Assignment 3 is due Wednesday by 4:30pm. Exam 1 is on Friday. Exactly like Prog. Assign. 2; no collaboration or help from the instructor. Log into Windows/ACENET. Start

More information

Lecture Outline. Rainfall Solution Attempt 1. Motivation for arrays. Introducing the Array. Motivation

Lecture Outline. Rainfall Solution Attempt 1. Motivation for arrays. Introducing the Array. Motivation Lecture Outline IMS1906 Programming in VB.NET Week 7 Lecture 1 & 2 Introduction to Arrays Arrays Part 1 and II Angela Carbone Monash University School of Information Management and Systems Defining Arrays

More information

Higher Computing Science Software Design and Development - Programming Summary Notes

Higher Computing Science Software Design and Development - Programming Summary Notes Higher Computing Science Software Design and Development - Programming Summary Notes Design notations A design notation is the method we use to write down our program design. Pseudocode is written using

More information

Elementary Statistics

Elementary Statistics 1 Elementary Statistics Introduction Statistics is the collection of methods for planning experiments, obtaining data, and then organizing, summarizing, presenting, analyzing, interpreting, and drawing

More information

Look at these number cards. (a) Choose any two of the number cards that add to 2. (b) Choose any three of the number cards that add to 5

Look at these number cards. (a) Choose any two of the number cards that add to 2. (b) Choose any three of the number cards that add to 5 Number cards 1 Look at these number cards. 7 5 3 1 1 3 5 7 (a) Choose any two of the number cards that add to 2 + = 2 (b) Choose any three of the number cards that add to 5 + + = 5 (c) Choose any four

More information

Expressions and Variables

Expressions and Variables Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,

More information

Understanding the problem

Understanding the problem 2.1.1 Problem solving and design An algorithm is a plan, a logical step-by-step process for solving a problem. Algorithms are normally written as a flowchart or in pseudocode. The key to any problem-solving

More information

Strings in Visual Basic. Words, Phrases, and Spaces

Strings in Visual Basic. Words, Phrases, and Spaces Strings in Visual Basic Words, Phrases, and Spaces Strings are a series of characters. Constant strings never change and are indicated by double quotes. Examples: Fleeb Here is a string. Strings are a

More information

Mathematics / Mathématiques

Mathematics / Mathématiques Mathematics / Mathématiques Test Description The Grade 9 Mathematics Achievement Test consists of two parts: Part A contains 20 numerical-response questions and was designed to be completed in 20 minutes.

More information

Maths Programme of Study 3.3

Maths Programme of Study 3.3 1 4/9/17 2 11/9/17 3 18/9/17 4 25/9/17 5 2/10/17 Recognise place value of each digit in 4-digit numbers. Identify, estimate and represent numbers using different representations including measures. Compare

More information

Final Examination Semester 3 / Year 2010

Final Examination Semester 3 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2010 COURSE : PROGRAMMING LOGIC AND DESIGN COURSE CODE : CCIS1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM

More information

VB CONSOLE SUMMER WORK. Introduction into A Level Programming

VB CONSOLE SUMMER WORK. Introduction into A Level Programming VB CONSOLE SUMMER WORK Introduction into A Level Programming DOWNLOAD VISUAL STUDIO You will need to Download Visual Studio Community 2013 to create these programs https://www.visualstudio.com/ en-us/products/visual-studiocommunity-vs.aspx

More information

Woodland Community College: Math practice Test

Woodland Community College: Math practice Test Woodland Community College: Math practice Test Pre algebra Math test The following problems are recommended practice problems for the pre-algebra section of the placement test. Some of the problems may

More information

VB FUNCTIONS AND OPERATORS

VB FUNCTIONS AND OPERATORS VB FUNCTIONS AND OPERATORS In der to compute inputs from users and generate results, we need to use various mathematical operats. In Visual Basic, other than the addition (+) and subtraction (-), the symbols

More information

Module 201 Object Oriented Programming Lecture 10 - Arrays. Len Shand

Module 201 Object Oriented Programming Lecture 10 - Arrays. Len Shand Module 201 Object Oriented Programming Lecture 10 - Arrays Len Shand Methods Arrays One dimensional Multi dimensional The variables you have been working with so far have only been able to hold one value

More information

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck! CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, 2011 Name: EID: Section Number: Friday discussion time (circle one): 9-10 10-11 11-12 12-1 2-3 Friday discussion TA(circle one): Wei Ashley Answer

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

FND Math Orientation MATH TEAM

FND Math Orientation MATH TEAM FND Math Orientation MATH TEAM Key Goals of Foundation Math Build strong Foundation in Mathematics Improve motivation to learn Inculcate good study habits Enhance independent & mobile learning skills Improve

More information

Grade 7 Mensuration - Perimeter, Area, Volume

Grade 7 Mensuration - Perimeter, Area, Volume ID : ae-7-mensuration-perimeter-area-volume [1] Grade 7 Mensuration - Perimeter, Area, Volume For more such worksheets visit www.edugain.com Answer the questions (1) A teacher gave a rectangular colouring

More information

Software Systems Development Unit AS1: Introduction to Object Oriented Development

Software Systems Development Unit AS1: Introduction to Object Oriented Development New Specification Centre Number 71 Candidate Number ADVANCED SUBSIDIARY (AS) General Certificate of Education 2014 Software Systems Development Unit AS1: Introduction to Object Oriented Development [A1S11]

More information

1. Look carefully at the program shown below and answer the questions that follow.

1. Look carefully at the program shown below and answer the questions that follow. 1. Look carefully at the program shown below and answer the questions that follow. a. What is the name of the class of this program? BillClass b. Identify one variable that holds a String. item c. What

More information

Big Apple Academy 2017 Mathematics Department

Big Apple Academy 2017 Mathematics Department Big Apple Academy 201 Mathematics Department Grade Homework Math Package It is important that you keep practicing your mathematical Knowledge over the summer to be ready for 5 th grade. In this Package

More information

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types Managing Data Unit 4 Managing Data Introduction Lesson 4.1 Data types We come across many types of information and data in our daily life. For example, we need to handle data such as name, address, money,

More information

Thursday Friday. Tuesday. Sunday. Mathematics Assessment (CfE) - Early Level. 1. What time is shown here? 9 o clock. o clock

Thursday Friday. Tuesday. Sunday. Mathematics Assessment (CfE) - Early Level. 1. What time is shown here? 9 o clock. o clock Mathematics Assessment (CfE) - Early Level (MNU 0-10a) I am aware of how routines and events in my world link with times and seasons, and have explored ways to record and display these using clocks, calendars

More information

Visual Basic for Applications

Visual Basic for Applications Visual Basic for Applications Programming Damiano SOMENZI School of Economics and Management Advanced Computer Skills damiano.somenzi@unibz.it Week 1 Outline 1 Visual Basic for Applications Programming

More information

NUMBERS AND NUMBER RELATIONSHIPS

NUMBERS AND NUMBER RELATIONSHIPS MODULE MODULE CHAPTERS Numbers and number patterns 2 Money matters KEY SKILLS writing rational numbers as terminating or recurring decimals identifying between which two integers any irrational number

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

Mental Math. Grade 9 Mathematics (10F) General Questions. test, what percentage of students obtained at least 50% on the test?

Mental Math. Grade 9 Mathematics (10F) General Questions. test, what percentage of students obtained at least 50% on the test? F 1 Specific Learning Outcome: 9.SS.4 1. Add: -4 + 3.1-9.3 2. If 19 out of 20 students obtained at least 15 on the last mathematics 30 test, what percentage of students obtained at least 50% on the test?

More information

Chapter 2 THE STRUCTURE OF C LANGUAGE

Chapter 2 THE STRUCTURE OF C LANGUAGE Lecture # 5 Chapter 2 THE STRUCTURE OF C LANGUAGE 1 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING Contents Introduction to

More information

[Page 177 (continued)] a. if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65 << endl";

[Page 177 (continued)] a. if ( age >= 65 ); cout << Age is greater than or equal to 65 << endl; else cout << Age is less than 65 << endl; Page 1 of 10 [Page 177 (continued)] Exercises 4.11 Identify and correct the error(s) in each of the following: a. if ( age >= 65 ); cout

More information

Higher Software Development - Section 1a

Higher Software Development - Section 1a Higher Software Development - Section 1a _ 1. List the stages involved in the development of a program in the correct order? (7) 2. In the software development process, what happens at the analysis stage?

More information

6 th Grade Enriched Math to 7 th Grade Pre-Algebra

6 th Grade Enriched Math to 7 th Grade Pre-Algebra Summer Work 2018 6 th Grade Enriched Math to 7 th Grade Pre-Algebra 6 th Grade Skills that are necessary for success in 7 th grade and beyond: - ability to add subtract, multiply and divide decimals, fractions

More information

MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING. 9691/23 Paper 2 (Written Paper), maximum raw mark 75

MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING. 9691/23 Paper 2 (Written Paper), maximum raw mark 75 UNIVERSITY OF CAMBRIDGE INTERNATIONAL EXAMINATIONS GCE Advanced Subsidiary Level and GCE Advanced Level MARK SCHEME for the May/June 2011 question paper for the guidance of teachers 9691 COMPUTING 9691/23

More information

Assessment - Unit 3 lessons 16-21

Assessment - Unit 3 lessons 16-21 Name(s) Period Date Assessment - Unit 3 lessons 16-21 1. Which of the following statements about strings in JavaScript is FALSE? a. Strings consist of a sequence of concatenated ASCII characters. b. Strings

More information

5th Grade Mathematics Essential Standards

5th Grade Mathematics Essential Standards Standard 1 Number Sense (10-20% of ISTEP/Acuity) Students compute with whole numbers*, decimals, and fractions and understand the relationship among decimals, fractions, and percents. They understand the

More information

Measures of Central Tendency

Measures of Central Tendency Page of 6 Measures of Central Tendency A measure of central tendency is a value used to represent the typical or average value in a data set. The Mean The sum of all data values divided by the number of

More information

Math 7 & 8 FLUENCY STUDY (timed) Name Date Fractions > Decimals Period % Seat # Fraction Dec. Math 7 & Science Fraction Dec.

Math 7 & 8 FLUENCY STUDY (timed) Name Date Fractions > Decimals Period % Seat # Fraction Dec. Math 7 & Science Fraction Dec. Math 7 & 8 FLUENCY STUDY (timed) Name Date Fractions > Decimals Period % Seat # Directions: Convert each fraction to a decimal. 1. Under Math (Mr. Hayo), you may leave terminating decimals alone; however,

More information

Lab 9: Creating a Reusable Class

Lab 9: Creating a Reusable Class Lab 9: Creating a Reusable Class Objective This will introduce the student to creating custom, reusable classes This will introduce the student to using the custom, reusable class This will reinforce programming

More information

Archdiocese of Washington Catholic Schools Academic Standards Mathematics

Archdiocese of Washington Catholic Schools Academic Standards Mathematics 5 th GRADE Archdiocese of Washington Catholic Schools Standard 1 - Number Sense Students compute with whole numbers*, decimals, and fractions and understand the relationship among decimals, fractions,

More information

More on variables and methods

More on variables and methods More on variables and methods Robots Learning to Program with Java Byron Weber Becker chapter 7 Announcements (Oct 12) Reading for Monday Ch 7.4-7.5 Program#5 out Character Data String is a java class

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

YEAH 2: Simple Java! Avery Wang Jared Bitz 7/6/2018

YEAH 2: Simple Java! Avery Wang Jared Bitz 7/6/2018 YEAH 2: Simple Java! Avery Wang Jared Bitz 7/6/2018 What are YEAH Hours? Your Early Assignment Help Only for some assignments Review + Tips for an assignment Lectures are recorded, slides are posted on

More information

Measures of Central Tendency. A measure of central tendency is a value used to represent the typical or average value in a data set.

Measures of Central Tendency. A measure of central tendency is a value used to represent the typical or average value in a data set. Measures of Central Tendency A measure of central tendency is a value used to represent the typical or average value in a data set. The Mean the sum of all data values divided by the number of values in

More information

CS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications

CS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications CS130/230 Lecture 12 Advanced Forms and Visual Basic for Applications Friday, January 23, 2004 We are going to continue using the vending machine example to illustrate some more of Access properties. Advanced

More information

Find the maximum value or minimum value for the function. 11. Solve the equation. 13.

Find the maximum value or minimum value for the function. 11. Solve the equation. 13. ACCELERATED MATH IV SUMMER PACKET DUE THE FIRST DAY OF SCHOOL The problems in this packet are designed to help you review topics from previous mathematics courses that are essential to your success in

More information

MATH 9 - Midterm Practice - Chapters 1-5

MATH 9 - Midterm Practice - Chapters 1-5 Period: Date: MATH 9 - Midterm Practice - Chapters 1-5 Multiple Choice Identify the choice that best completes the statement or answers the question. 1. What type of symmetry is shown by the figure? a.

More information

Reviewing all Topics this term

Reviewing all Topics this term Today in CS161 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for) Functions (pass by value, pass by reference) Arrays (specifically arrays of characters)

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

PROGRAMMING IN C AND C++:

PROGRAMMING IN C AND C++: PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print

More information

Phụ lục 2. Bởi: Khoa CNTT ĐHSP KT Hưng Yên. Returns the absolute value of a number.

Phụ lục 2. Bởi: Khoa CNTT ĐHSP KT Hưng Yên. Returns the absolute value of a number. Phụ lục 2 Bởi: Khoa CNTT ĐHSP KT Hưng Yên Language Element Abs Function Array Function Asc Function Atn Function CBool Function CByte Function CCur Function CDate Function CDbl Function Chr Function CInt

More information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure 2.8 Formulating

More information

NEA sample solution Task 2 Cows and bulls (solution 2) GCSE Computer Science 8520 NEA (8520/CA/CB/CC/CD/CE)

NEA sample solution Task 2 Cows and bulls (solution 2) GCSE Computer Science 8520 NEA (8520/CA/CB/CC/CD/CE) NEA sample solution Task 2 Cows and bulls (solution 2) GCSE Computer Science 8520 NEA (8520/CA/CB/CC/CD/CE) 2 Introduction The attached NEA sample scenario solution is provided to give teachers an indication

More information

Level 3 Computing Year 2 Lecturer: Phil Smith

Level 3 Computing Year 2 Lecturer: Phil Smith Level 3 Computing Year 2 Lecturer: Phil Smith Previously We started to build a GUI program using visual studio 2010 and vb.net. We have a form designed. We have started to write the code to provided the

More information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure

More information

Unit 1: Numeration I Can Statements

Unit 1: Numeration I Can Statements Unit 1: Numeration I can write a number using proper spacing without commas. e.g., 934 567. I can write a number to 1 000 000 in words. I can show my understanding of place value in a given number. I can

More information

Year 10 Term 2 Homework

Year 10 Term 2 Homework Yimin Math Centre Year 10 Term 2 Homework Student Name: Grade: Date: Score: Table of contents 5 Year 10 Term 2 Week 5 Homework 1 5.1 Graphs in the number plane................................ 1 5.1.1 The

More information

Guess Paper Class XII Subject Informatics Practices TIME : 1½ HRS. M.M. : 50

Guess Paper Class XII Subject Informatics Practices TIME : 1½ HRS. M.M. : 50 Guess Paper 2009-10 Class XII Subject Informatics Practices Answer the following questions 1. Explain the following terms: 2x5=10 a) Shareware b) PHP c) UNICODE d) GNU e) FLOSS 2 Explain the following

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions CSE 142 - Computer Programming I 1 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >=

More information

The Big Python Guide

The Big Python Guide The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String

More information

Solve problems involving proportional reasoning. Number Sense and Algebra

Solve problems involving proportional reasoning. Number Sense and Algebra MFM 1P - Grade Nine Applied Mathematics This guide has been organized in alignment with the 2005 Ontario Mathematics Curriculum. Each of the specific curriculum expectations are cross-referenced to the

More information

Object Oriented Programming Using C ++ Page No. : 1. ASSIGNMENT SHEET WITHOUT USING OBJECT AND CLASSES

Object Oriented Programming Using C ++ Page No. : 1. ASSIGNMENT SHEET WITHOUT USING OBJECT AND CLASSES Object Oriented Programming Using C ++ Page No. : 1. ASSIGNMENT SHEET WITHOUT USING OBJECT AND CLASSES 1. Write a program to calculate the sum of two numbers using function. 2. Write a program to calculate

More information

Int 1 Checklist (Unit 1) Int 1 Checklist (Unit 1) Whole Numbers

Int 1 Checklist (Unit 1) Int 1 Checklist (Unit 1) Whole Numbers Whole Numbers Know the meaning of count and be able to count Know that a whole number is a normal counting number such as 0, 1, 2,, 4, Know the meaning of even number and odd number Know that approximating

More information

Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F

Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F PROGRAM 4A Full Names (25 points) Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F This program should ask the user for their full name: first name, a space, middle name, a space,

More information

Math 155. Measures of Central Tendency Section 3.1

Math 155. Measures of Central Tendency Section 3.1 Math 155. Measures of Central Tendency Section 3.1 The word average can be used in a variety of contexts: for example, your average score on assignments or the average house price in Riverside. This is

More information

2nd Paragraph should make a point (could be an advantage or disadvantage) and explain the point fully giving an example where necessary.

2nd Paragraph should make a point (could be an advantage or disadvantage) and explain the point fully giving an example where necessary. STUDENT TEACHER WORKING AT GRADE TERM TARGET CLASS YEAR TARGET The long answer questions in this booklet are designed to stretch and challenge you. It is important that you understand how they should be

More information

Chapter 8. Arrays and More Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

Chapter 8. Arrays and More Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 8 Arrays and More Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved. Introduction Arrays are like groups of variables that allow you to store sets of similar data

More information

Westbourne House School Revision Easter Term Y8 MATHS REVISION CHECKLIST

Westbourne House School Revision Easter Term Y8 MATHS REVISION CHECKLIST The Exam(s) will consist of: Y8 MATHS REVISION CHECKLIST Three papers: o Non- calculator Paper duration 60 minutes o Calculator Paper duration 60 minutes o Maths Aural duration 20 minutes (paper is done

More information

DEPARTMENT OF ACADEMIC UPGRADING

DEPARTMENT OF ACADEMIC UPGRADING DEPARTMENT OF ACADEMIC UPGRADING COURSE OUTLINE WINTER 2014 INTRODUCTION TO MATH 0081 INSTRUCTOR: Joelle Reynolds PHONE: (780) 539-2810 or 2204 OFFICE: Math Lab A210 E-MAIL: jreynolds@gprc.ab.ca OFFICE

More information

What Have You Learned About Programming So Far? Expressions

What Have You Learned About Programming So Far? Expressions What Have You Learned About Programming So Far? Let s review: Variables Expressions Conditionals Procedures Expressions A means of performing the actual computation Many kinds of expressions. They can

More information

Lecture 1. Course Overview, Python Basics

Lecture 1. Course Overview, Python Basics Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures and Labs are at fire-code capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are

More information

IS 320 Spring 96 Page 1 Exam 1. Please use your own paper to answer the following questions. Point values are shown in parentheses.

IS 320 Spring 96 Page 1 Exam 1. Please use your own paper to answer the following questions. Point values are shown in parentheses. IS 320 Spring 96 Page 1 Please use your own paper to answer the following questions. Point values are shown in parentheses. 1. (10) Consider the following segment of code: If txtansicode.text < "0" Or

More information