辅导案例-S 321

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
1
Cpt S 321 – Exam 2
Spring 2019
40 points total
Total pages: 12



Name:
WSU ID:

Seat in a way that there is at least one empty seat between you and
your neighbors.

- During the exam, if something is unclear, first ask for clarifications. If it is
still unclear, then write down any assumptions that you are making.

- Please DO NOT detach the sheets.

- Allowed Tools: Pencil/pen, eraser

- Use the last page (p.12) as a draft if needed. Anything you write there will
not be corrected unless you explicitly ask me to do so when you are
answering the questions. In that case annotate which part relates to which
question.

- There are 21 questions. (The last question accounts for 15 points)


2
Multiple Choice (1 point each)
Write
Answers
Here


1. (1 point) Which of the following is true about design patterns?
A. Design patterns represent the best practices used by experienced object-
oriented software developers.
B. Design patterns are solutions to general problems that software
developers faced during software development
C. Design patterns are obtained by trial and error by numerous software
developers over quite a substantial period of time
D. All of the above
E. None of the above
2. (1 point) What pattern helps you to create lots of different kinds of objects?
A. Proxy
B. Command
C. Adapter
D. Strategy
E. Factory
3. (1 point) What is one major difference between a struct and a class in C#?
A. Default access modifier in struct is public, whereas it’s private for a class
B. A struct is a reference type and a class is a value type
C. A class is a reference type and a struct is a value type
D. A struct cannot have member functions, but a class can
E. A class cannot have member functions, but a struct can
F. There is no difference
4. (1 point) A static function in a class:
A. Can be executed without creating an instance of the class
B. Cannot access member variables of the class
C. Cannot call non-static member functions of the class
D. All of the above
A. None of the above




3
5. (1 point) Which of the following is the default access modifier for members?
A. private
B. protected
C. public
D. final
E. internal
F. There is no default access modifier
6. (1 point) If you have a sorted array and do a binary search for a value then the
worst case is:
A. You find the value, time is O(n)
B. You don’t find the value, time is O(n)
C. You find the value, time is O(log n)
D. You don’t find the value, time is O(log n)
E. Doesn’t matter if you find the value or not and the time cannot be
determined without further information about the array contents
7. (1 point) A class is declared in a DLL class library. Which access/protection
modifiers will allow it to be used by external applications that reference the DLL?
(Assume reflection is NOT being used)
A. public, internal, or protected
B. public and internal
C. internal only
D. public only
E. The access modifier is not what controls whether or not external
applications can see and use it
8. (1 point) The event keyword in C# represents something that internally
A. Is an expression tree
B. Is a single integer value
C. Is a single pointer value
D. Is a list of function pointers/references

9. (1 point) What is the output obtained by executing Main?
Code Output
public static void Main() {
string X = "42";
object Y = X.Replace("42", "101");
X = X.Replace("1", "2");
Console.WriteLine(Y);}

4

10. (1 points) What is the output obtained by executing Main?
Code Output
public static void Main() {
string s = “Hello World!”;
F2(ref s);
Console.Write(s);
}
static void F2(ref string s) {
s.Replace(“Hello”, “Goodbye”);
}


11. (1.5 points) Rewrite these equations in a Postfix notation
43 - 12 * 15 / 2


18 / 14 / 2 / 10


(17 - 4) * 16 + 3 * 2



12. (1 point) Draw the Expression Tree for the following equation: 9 + 23 / 5 * ( 4 - 2 )









5
13. (2 points) What is the Shunting Algorithm (give the main characteristics of what it can do;
do not list the steps) and who invented it?






14. (1 point) How can we test non-public methods in C#?





15. (1 point) What is a lambda expression?




16. (3 points) Using delegates and lambda expressions, write code to allow any number to be
transformed into another. Show two examples of use: 1) a number is transformed into its
square number and 2) a number is doubled, i.e. the number is always multiplied by 2?








6
17. (2 points) What is reflection? Give two examples where reflection can be useful.






18. (1.5 points) What is XML? Compare and contrast with alternative solutions (e.g., binaries,
plain text).






19. (1 point) What is the first question that you should ask yourself when thinking about the
designing your application?


20. (1 point) What are the two questions you will ask yourself when wondering whether you
should use an interface or an abstract class?




21. (15 points) Nespresso contacts you to implement an Point-of-Sale application that will help
them sell their coffee and machines as well as help them manage the tasting of their coffee in
the different Nespresso stores. They have two families of coffee machines: Vertuo and Original.
The original one makes short espressos and has a larger variety of capsules – this was their first
type of machine. The Vertuo makes very long espresso (the size of a mug). The capsules for the
two machines are different and are not interchangeable (the original takes only one size of
capsules; the Vertuo takes 3 different sizes and all three make different sizes of espresso). All
7
capsules have the following characteristics: they all have a name; an intensity (from 1 (mild) to
10 (strong) typically but seasonal varieties have even stronger intensity (e.g., 13); they can be
caffeinated, decaffeinated, or half-half; a price; and a description. A couple of examples of
capsules for each machine follow:
Name Intensity Description Price Caffeine Machine
Columbia 6 Winey and
red fruits
$0.72 Caffeinated Original
Ristretto
Decaffeinato
10 Powerful and
contrasting
$0.70 Decaffeinated Original
Melozio 6 Smooth and
balanced
$1.10 Caffeinated Vertuo
Half
Caffeinato
5 Sweet and
velvety
$1.10 Half
Caffeinated
Vertuo

The way the machine works, is that once it is ON and it has a capsule inserted, you can press
the a button and the coffee starts pouring. You can wait for it to finish or you can stop it earlier
to have it shorter and more intense.
The Nespresso Stores sell machines and capsules, but also offer you to try coffee. You can
assume that the store that will use your prototype application has 2 machines: 1 Original and 1
Vertuo. Typically, when a client arrives, an Nespresso agent will ask her/him whether she/he
wants to drink a coffee and if yes what type. The agent will enter this into the system and the
system should automatically run the preparation of the espresso. While the coffee is preparing
the client can buy capsules/machines.
Design and build a console prototype of the application. Your application should provide all
features described above to the Nespresso agent, in other words: sell capsules and machines
and automatically run the preparation of the espresso.
Use page 8 only for explaining your design choices. Feel free to draw class diagrams, sequence
diagrams, or simply enumerate the choices you are making. Use pages 9 to 11 to write the
actual code.

8
Use this page to draw/talk about your design only.


9

10

11

12
DRAFT

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468