16
SOFTWARE DESIGN & DEVELOPMENT OUTCOME 2 PROGRAMMING TASK NICK SULLIVAN

Outcome 2 Nick Sullivan

Embed Size (px)

Citation preview

Page 1: Outcome 2 Nick Sullivan

SOFTWARE DESIGN &

DEVELOPMENT

OUTCOME 2

PROGRAMMING TASK

NICK SULLIVAN

Page 2: Outcome 2 Nick Sullivan

STEP 1

DESIGN PROGRAM

Design Table

Procedures Input Parameters

Output Parameters

readfile Firstname[],surname[]

Score[]

findtopscore Firstname[], surname[],

score[]

Topfirstname, topsurname ,topscore

getoutputs Topfirstname ,topsurname,

topscore

Page 3: Outcome 2 Nick Sullivan

Stepwise Refinement

open filenames

SET counter to 0RECEIVE firstname(counter) from filenamesSEND firstname(counter) TO displayRECEIVE surname(counter) from filenamesSEND surname(counter) TO displayRECEIVE score(counter) from filenamesSEND score(counter) TO display counter = counter + 1

Loop

Close Filenames

PROCEDURE findOldest

SET topscore TO score[0]

SET topname TO firstname[0]

SET topsurname TO surname[0]

FOR counter = 1 TO age.length-1

IF topscore<score(counter) THEN

SET topname TO firstname[counter]

SET topsurname TO surname[counter]

SET topscore TO score[counter]

End if

End procedure

Page 4: Outcome 2 Nick Sullivan

FIND GETOUTPUTS

SEND TO DISPLAY ( topname, topsurname, topscore) Open file topscore READ ON FILE (1, topname, topsurname,topscore) Close file topscore DISPLAY ("Your file has been written successfully.")

Page 5: Outcome 2 Nick Sullivan

STEP 2

TEST PLAN

Date Expected Results

Actual Results

Pass/Fail

Original SQA file

Lynn Simpson,

188

Lynn Simpson,

188

PASS

Filenames Test

Nick Sullivan,

190

Nick Sullivan,

190

PASS

FilenamesTest 2

Richard Primrose,

199

Richard Primrose,

199

PASS

Page 6: Outcome 2 Nick Sullivan

Screenshots of Results

Page 7: Outcome 2 Nick Sullivan
Page 8: Outcome 2 Nick Sullivan
Page 9: Outcome 2 Nick Sullivan

STEP 3

PROGRAM CODE

Public Class Form1 'setup array Dim firstname(50) As String 'firstname string because its a name Dim surname(50) As String 'surname is string also Dim score(50) As Integer 'score is integer as all the scores are whole numbers Dim topname As String 'topname is string as its a line of text Dim topsurname As String 'topsurname also a line of text Dim topscore As Integer 'topscore is a whole number Dim counter As String = 0

Private Sub BtnRead_Click(sender As Object, e As EventArgs) Handles BtnRead.Click 'call procedures 'the information in brackets is the information being passed between the procedures Call readFile(firstname, surname, score) Call Findtopscore(score, firstname, surname, topname, topsurname, topscore) Call getOutputs(topname, topsurname, topscore)

End Sub Private Sub readFile(ByRef firstname, ByRef surname, ByRef score) 'in brackets are the information being passed 'ByRef because the information is coming into the procedure 'byVal because the information is going out to another procedure 'setup variables Dim tempname As String = "" Dim tempname2 As String = "" Dim tempscore As Integer

'open file FileOpen(1, "C:\Nick VB\filenames.csv", OpenMode.Input)

Do While Not EOF(1) 'assign first name in file to tempname Input(1, tempname) 'assigns tempname to index of array firstname(counter) = tempname TxtNames.AppendText(firstname(counter) & vbCrLf) 'assign first name in file to tempname2 Input(1, tempname2) 'assigns tempname to index of array surname(counter) = tempname2 TxtSurname2.AppendText(surname(counter) & vbCrLf) Input(1, tempscore)

Page 10: Outcome 2 Nick Sullivan

score(counter) = tempscore TxtScores2.AppendText(score(counter) & vbCrLf)

counter = counter + 1

Loop

FileClose(1) End Sub

Private Sub Findtopscore(ByVal score, ByVal firstname, ByVal surname, ByRef topname, ByRef topsurname, ByRef topscore) Dim counter As Integer = 0 'find topscore 'set variables to 0 topscore = score(0) topname = firstname(0) topsurname = surname(0) 'set counter to -1 so that the counter starts counting from the begginning For counter = 1 To score.Length - 1 'find the topscore by going through the counter and stopping at the highest score If topscore < score(counter) Then 'finding the topscore,top firstname and top surname is the score, firstname and surname 'where the counter stops and display the results topscore = score(counter) topname = firstname(counter) topsurname = surname(counter)

End If Next 'opening the file and saving the information FileOpen(2, "C:\Nick VB\topscore.txt", OpenMode.Output) WriteLine(2, "The person with the topscore is " & topname & topsurname & " Their score is " & topscore) 'closing the file FileClose(2)

End Sub

Private Sub getOutputs(ByRef topname, ByRef topsurname, ByRef topscore)

'message box to give outputs to tell the user what they want to know MsgBox("The person with the topscore is " & topname & " " & topsurname & " Their score is " & topscore) 'create a new file called topscore FileOpen(1, "C:\Nick VB\topscore.txt", OpenMode.Output) 'create the text l wish to display PrintLine(1, "The person with the topscore is " & topname & topsurname & " Their score is " & topscore) 'make sure to close the file FileClose(1) MsgBox("Your file has been written successfully.") End SubEnd Class

Page 11: Outcome 2 Nick Sullivan

STEP 4

Changed Results

Page 12: Outcome 2 Nick Sullivan
Page 13: Outcome 2 Nick Sullivan

Changed Results

Page 14: Outcome 2 Nick Sullivan
Page 15: Outcome 2 Nick Sullivan