La Trobe University, Bendigo

Total Page:16

File Type:pdf, Size:1020Kb

La Trobe University, Bendigo

CSE1PE Programming Environment 2008 Practice Exam 1 Solution

Question 1

(a) i * j / 2

5 * 2 / 2 10 / 2 5

(b) x – 0.8 / j + (i * 2)

6.4 – 0.8 / 2 + (5 * 2) 6.4 – 0.8 / 2 + 10 6.4 – 0.4 + 10 6 + 10 16

Question 2

(a) i >= 5 And j <> 2

5 >= 5 And 2 <> 2 True And 2 <> 2 True And False False

(b) x < 0 Or Not x > 10

6.4 < 0 Or Not 6.4 > 10 False Or Not 6.4 > 10 False Or Not False False Or True True

Question 3

Values are – i: 5 x = 6.40 or

Values are - i: 5 x = 6.40

Question 4

(a) What are some major features of UNIX?

 Multi-user  Command driven  Multiple user accounts  One directory tree  Reliability 2008 Practice Exam 1 Solution Programming Environment (CSE1PE)

(b) What is ftp used for? How would you connect to redgum using ftp? What different file transfer modes are available? Name an alternative ftp program available for Windows.

 Transferring files  ftp ironbark.bendigo.latrobe.edu.au or ftp, then open ironbark.bendigo.latrobe.edu.au  ASCII, Binary  One of: ws_ftp, cuteftp etc

(c) What is the alias command used for? Give an example.  aliases can be used to define command shortcuts  aliases should be specified in .bashrc if they are to be generally available  e.g. alias l=”ls –al”

Question 5

(a) pwd (b) ls (c) ls –al or ls –a -l (d) mv test.java test2.java (e) nedit test2.java& (f) javac test2.java (g) java test2 (h) lpr –Pitlab5 test2.java (i) mkdir examples (j) cp test2.java examples/test3.java (k) cd examples (l) rm ../test2.class (m) cd or cd ~ (n) chmod o-w * (o) cat ../klray/a1.java (p) less /usr/staff/tim/q1.java or more

Question 6

(a) What is meant by input validation? Give two examples (code NOT required).

 Checking a value input by a user is correct  Examples: checking a month number of between 1 and 12; Checking a membership of a club is Full, Junior or Life ("F", "J" or "L")

(b) What is a sentinel value? What is it used for?  A special value input by a user to indicate that the end of input.  The sentinel value should not be able to be confused with a normal valid value e.g -1 for a mark  Used to indicate the end of input in a while loop.

Page 2 2008 Practice Exam 1 Solution Programming Environment (CSE1PE)

Question 7

Line Member membership membership total Conditions Input/ Output Number ship Fee Name Type Fees 1, 2 0 3 J membership type ? J 4 "J" <> "X" ? is True 5, 12, 13 "J" = "F" ? is False 16, 17 "J" = "J" ? is True 18 80 19 "Junior" 23 - 25, 6 0 + 80 = 80 7 membership Name = Junior; membership Fee = 80 8 membership type ? X 9, 4 "X" <> "X" ? is False 10 Total Fees = 80 11

Question 8

Option Compare Database Option Explicit

Sub Main() Dim category As String Dim concession As String Dim price As Double Dim reason As String Dim totalTakings As Double

totalTakings = 0 concession = InputBox("Concession (Y=Yes, N=No, X=eXit) ?") While concession <> "X" If concession = "Y" Then reason = InputBox("Reason (C=Child, P=Pensioner) ?") If reason = "C" Then category = "Child" price = 8 Else category = "Pensioner" price = 9 End If Else category = "Full" price = 12 End If totalTakings = totalTakings + price Debug.Print category; ": $"; Format(price, "0.00") concession = InputBox("Concession (Y=Yes, N=No, X=eXit) ?") Wend Page 3 2008 Practice Exam 1 Solution Programming Environment (CSE1PE)

Debug.Print "Total takings = $"; Format(totalTakings, "0.00") End Sub

Page 4 2008 Practice Exam 1 Solution Programming Environment (CSE1PE)

Question 9

(a) Defining Diagram

Inputs Processing Outputs averageBalance Input averageBalance, numberOfTrans fees numberOfTrans Calculate fees interestRate Determine interestRate interest Calculate interest Display fees, interestRate, interest

(b) Pseudo Code

CalcFeesAndInterest() Input averageBalance WHILE averageBalance >= 0 DO Input numberOfTrans IF averageBalance < 1000 THEN fees = 40 + numberOfTrans * 0.50 interestRate = 0 ELSE IF numberOfTrans < 10 THEN fees = 40 ELSE fees = 40 + (numberOfTrans – 10) * 0.50 ENDIF interestRate = 3 ENDIF interest = averageBalance * interestRate / 100 Display fees, interestRate, interest Input averageBalance ENDWHILE STOP

(c) Data Dictionary

Identifier Name Data Type Description averageBalance Double The average balance in the account over the year in $. fees Double The fees payable on the account of the year in $. interest Double The interest earned on the account for the year in $. interestRate Double The interest rate applicable to the account in %. numberOfTrans Integer The number of transactions on the account fore the year.

Page 5

Recommended publications