cp-as-10-08.pdf
TRANSCRIPT
-
8/14/2019 CP-AS-10-08.pdf
1/9
CP-AS-10-08Mark scheme
COMP1
Marks 25Answer all questions
Page 1 of 9
-
8/14/2019 CP-AS-10-08.pdf
2/9
CP-AS-10-08Mark scheme
Put your answers ont o the document "CP- AS- 10- 08 Answers"
Thi s program when f i ni shed wi l l enabl e a user t o car r y out some usef ul
everyday conver si ons. Al ong wi t h t he answer document you wi l l f i nd t heskel et on code f or t hi s pr ogr am on t he school websi t e
Exmouth Col l ege > Subj ect s > I CT & Comput i ng > I CT Year 12 : .
usi ng Syst em;usi ng System. Col l ect i ons. Gener i c;usi ng Syst em. Li nq;usi ng Syst em. Text ;
namespace CShar pExamPr act i ce1{
cl ass Pr ogr am { stat i c i nt sel ect i on;
st at i c i nt MenuOpt i on( ) { i nt choi ce = 0; bool val i dNumber = f al se;
Consol e. Wr i t eLi ne( ) ; Consol e. Wr i t eLi ne( "Ent er a number t o choose an opt i on: " ) ; Consol e. Wr i t eLi ne( " 1 Conver t Fahr enhei t t o Cel si us 3Conver t Mi l es t o Ki l omet er s" ) ; Consol e. Wr i t eLi ne( " 2 Conver t t o Fahr enhei t 4
Conver t Ki l omet er s t o Mi l es" ) ; Consol e. Wr i t eLi ne( " 5 Exi t ") ; Consol e. Wr i t eLi ne( ) ; Consol e. Wr i t e( "Your choi ce: ") ;
choi ce = Conver t . ToI nt 32( Consol e. ReadLi ne( ) ) ;
r et ur n choi ce;
}
st at i c bool Val i dat eDat a( st r i ng s) { st r i ng st r = s; t r y / / we haven' t cover ed val i dat i on yet but you wi l l f i ndt he detai l s on pages 95 - 98 { doubl e d = Conver t . ToDoubl e( s) ; r et ur n t r ue; } cat ch { Consol e. Wr i t eLi ne( "Thi s was not a number " ) ; Consol e. Wr i t eLi ne( "Pl ease t r y agai n") ; r et ur n f al se; }
Page 2 of 9
-
8/14/2019 CP-AS-10-08.pdf
3/9
CP-AS-10-08Mark scheme
}
st at i c voi d Conver t ToCel si us( ) { St r i ng Degr eesFahr enhei t St r ; doubl e Degr eesFahr enhei t ; doubl e Degr eesCel si us; Consol e. Wr i t e( "Ent er f ahr enhei t val ue : ") ; Degr eesFahr enhei t St r = Consol e. ReadLi ne( ) ; Degr eesFahr enhei t = Conver t . ToDoubl e(Degr eesFahr enhei t St r ) ; Degr eesCel si us = ( Degr eesFahr enhei t - 32) *( 5/ 9) ; Consol e. Wr i t e( "Thi s i s ") ; Consol e. Wr i t eLi ne( Degr eesCel si us) ;
}
st at i c voi d Conver t ToFahr enhei t ( ) { Consol e. Wr i t eLi ne( "You wi l l need t o wr i t e t he code f or t he
pr ocedur e Conver t ToFahr enhei t your sel f " ) ; }
st at i c voi d Conver t ToKi l omet er s( ) { Consol e. Wr i t eLi ne( "You wi l l need t o wr i t e t he code f or t hepr ocedur e Conver t ToKi l omet er s your sel f " ) ; }
st at i c voi d Conver t ToMi l es( ) { Consol e. Wr i t eLi ne( "You wi l l need t o wr i t e t he code f or t hepr ocedur e Conver t ToMi l es your sel f " ) ; }
st at i c voi d Mai n( st r i ng[ ] ar gs) { Consol e. Wr i t eLi ne( "Usef ul Conver t er ") ; sel ect i on = MenuOpt i on( ) ; whi l e ( sel ect i on ! = 5) { swi t ch ( sel ecti on) { case 1: Conver t ToCel si us( ) ; br eak; / / t he br eak st at ement t r ansf er s cont r olout ot t he case body case 2:
Conver t ToFahr enhei t ( ) ; br eak; / / t he br eak st at ement t r ansf er s cont r olout ot t he case body case 3: Conver t ToKi l omet er s( ) ; br eak; / / t he br eak st at ement t r ansf er s cont r olout ot t he case body case 4: Conver t ToMi l es( ) ; br eak; / / t he br eak st at ement t r ansf er s cont r olout ot t he case body
Page 3 of 9
-
8/14/2019 CP-AS-10-08.pdf
4/9
CP-AS-10-08Mark scheme
} sel ect i on = MenuOpt i on( ) ; }
i f ( sel ecti on < 5) Consol e. ReadLi ne( ) ; } }}
Gi ve an exampl e of gl obal var i abl e.1 a
(1 Mark)
sel ecti on / t here ar e none?
Gi ve an exampl e of a l ocal var i abl e.b
(1 Mark)
choi ce / val i dnumber st r
Gi ve an exampl e of a f unct i on.c
(1 Mark)
val i datedata / MenuOpt i on
Expl ai n how a f unct i on di f f er s f r oma pr ocedur e.d
(1 Mark)
A f unct i on r eturns a val ue / a f unct i on can be part of an expr essi on
whereas
a pr ocedure does not r etur n a val ue / i s cal l ed as a statement
Page 4 of 9
-
8/14/2019 CP-AS-10-08.pdf
5/9
CP-AS-10-08Mark scheme
Wr i t e a pr ocedur e Conver t ToKm t o conver t mi l es t o ki l omet er s.The conver si on f or mul a i s:
1 mi l e = 1. 6 km
1 e
(5 Marks)
decl ar e var i abl es Mi l esSt r st r i ng Ki l omet er s & Mi l es doubl e = al l t hr ee 1 mar kcor r ect t ype 1 mark
Good pr ompt and i nput st r i ng = 1 mark
Conver t st r i ng t o doubl e = 1 mark
corr ect assi gnment t o cal cl ate = 1 mark
corr ect out put 1 mark
MAX 5
An exampl e of boundary dat a mi ght be t he empt y st r i ng.
Thi s shoul d not cause an er r or but gi ve t he empt y st r i ng as aresul t .
Wr i t e the i nst r uct i ons necessar y t o handl e t hi s boundar y val ue.
Copy t he ent i r e code f or your Conver t ToKm pr ocedur e i nt o youranswer .
f
(4 Marks)
Thi s quest i on r ef er s t o t est i ng t he procedure Conver t ToKm.
To t est a r out i ne adequat el y, normal , boundar y and er r oneousdat a need to be used.
Look at your ver si on of t he f unct i on Conver t ToKm.
Gi ve t wo sui t abl e val ues of normal t est data.
g
(2 Marks)
t r y / cat ch 1 mark
I f l engt h = 0 1 mark
out put "" 1 mark
Page 5 of 9
-
8/14/2019 CP-AS-10-08.pdf
6/9
CP-AS-10-08Mark scheme
Thi s quest i on r ef er s t o t he mai n MenuOpt i on sub- program.
The sub program shoul d show t he menu r epeat edl y t o t he userunt i l t he user ent er s a val i d number ( 1, 2, 3, 4 or 5) .
Wr i t e t he code t o r epeat t he i nput t o t he var i abl e choi ce unt i la cor r ect val ue i s ent er ed.
1 h
(4 Marks)
I f ( Choi ce 5) 1 markf or Appror i at e er r or message 1 mark
I f ( choi ce >1) AND ( choi ce
-
8/14/2019 CP-AS-10-08.pdf
7/9
CP-AS-10-08Mark scheme
COMP2
Marks 8Answer all questions
Look at t he t r ut h tabl e bel ow.
+- - - - - - - +- - - - - - - +- - - - - - - +| I nput | I nput | Out put || A | B | Q |+- - - - - - - +- - - - - - - +- - - - - - - +| 0 | 0 | 1 |+- - - - - - - +- - - - - - - +- - - - - - - +| 0 | 1 | 0 |+- - - - - - - +- - - - - - - +- - - - - - - +
| 1 | 0 | 0 |+- - - - - - - +- - - - - - - +- - - - - - - +| 1 | 1 | 0 |+- - - - - - - +- - - - - - - +- - - - - - - +
What l ogi c gat e does t hi s r epr esent ?
2 a
(1 Mark)
NOR Gat e
Page 7 of 9
-
8/14/2019 CP-AS-10-08.pdf
8/9
CP-AS-10-08Mark scheme
An i nt er i or l i ght i n a t wo- door car i s cont r ol l ed by twoswi t ched t hat t he dr i ve can t ur n on or of f and t wo sensor s, oneper door .
The swi t ches ar e named A and B.The door sensor s ar e named C and D.The i nt er i or l i ght i s named L.I f a door i s open t he out put of i t s sensor i s on.I f a door i s cl osed t he out put of i t s sensor i d of f .
Of bot h swi t ches A and B ar e of f t hen t he l i ght L i s al ways of f .I f swi t ch A i s on t he l i ght L i s al ways on.I f swi t ch B i s on and swi t ch A i s of f t hen:
t he l i ght L t ur ns on i f one or mor e of t he car door s i s opened.The l i ght L t urns of f i f bot h of t he doors ar e cl osed.
The f ol l owi ng symbol s ar e used t o r epresent l ogi c gat es:
- - - - - O- - -
AND OR NOTUsi ng onl y AND, OR and NOT gates dr aw a ci cui t f or t hi s syst emi n the box bel ow. You may not need to use al l t hr ee t ypes aofgate.
+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | | | | A- O | | | | | | | | | | | B- O | | | | | | O- L | | | | C- O | | |
| | | | | | | | D- O | | | | | | | +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2 b
Page 8 of 9
-
8/14/2019 CP-AS-10-08.pdf
9/9
CP-AS-10-08Mark scheme
(3 Marks)
Wr i t e a Bool ean expr essi on t o repr esent t he l ogi c of t hei nter i or l i ght sys tem
c
(1 Mark)
A + B . ( C + D)
A + B . C + B . D _A + A . B . ( C + D)
_ _A + A . B . C + A . B . D
Si mpl i f y t he Bool ean expr essi on bel ow showi ng your worki ng.
_____- - -A + B + B . A
d
(3 Marks)
- - -= A + B + B . A
_= A . B + B . A
= B . (A + A)
= B . 1
= B
OR Use t r uth t abl e.
8
Computing Summer 2009 COMP2 Q 4
Page 9 of 9