亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
1) Imagine you are creating an application that has a 25 step tutorial. These tutorial steps can be completed in any order. Furthermore the steps are grouped into 5 groups: 4 j& n' G# j2 t( E4 W
Group 1: Steps 1--5 Group 2: Steps 6--10 Group 3: Steps 11--15 Group 4: Steps 16--20 Group 5: Steps 21--25 % v5 I, G. [5 E9 c( @7 c
A group is considered finished if all of the steps in that group are finished.
" Q# X# i A! Y5 X" B/ {- _Create a Tutorial class that implements the following (the function definitions are written here in a c-based style, but you can implement in any language of your choosing):
6 n; P& L( R7 a1 R. m* _0 J" V5 oboolean isStepComplete(uint stepNum); //Checks whether a single step number is complete. boolean isGroupComplete(uint groupNum); //Checks whether a group is complete. void setStepComplete(uint stepNum); //Sets the given step to complete. boolean isTutorialComplete(); //Checks whether all steps are complete.
7 V* N% Y u1 e% Q: ]9 SThe goal is to make this class as efficient as possible both in memory use and runtime.
! O# A" y3 _) j) P3 u/ s: ^+ J2) Imagine we want to design a program to run the inventory for a shop that sells bagels and coffee. For simplicity, the only requirement is that there is a public API to purchase items which takes a list of items you want to buy (i.e. 2 coffees and a bagel), updates the inventory of our store, and returns the price for all of the items. However, our store is a little bit shady and they change the prices based on certain factors:
+ L( ]0 ^$ F9 y& g7 Q* HCoffee: $2 base price +$1 between 6am and 10am local time Unlimited supply (never needs to be restocked) : x( V3 X1 n: t1 R: l! O1 P0 Q- _
Bagel: $2 base price +$1 if we have less than 10 in stock For simplicity, every run of the application we start with a supply of 15 bagels. Once we run out there are no more until the application is completely restarted. 6 T0 z- \5 J$ B: S
Think of this as a base design that we will expand upon in the future so the goal here is to design the code to be easily extensible. You are free to use any language you’d like and design the code in any way you see fit so that the above conditions are met.
7 Z, x+ B, q3 `9 D" e$ \ z: a) E, O, D$ ]* E
& C1 c1 I/ P6 {1 Z5 Z |