0% found this document useful (0 votes)
9 views10 pages

CS132 Software Engineering Midterm Exam

The document is a midterm exam for a Software Engineering course, consisting of five problem sets totaling 80 points, with each problem addressing different programming and design challenges. Students are instructed to write legibly, state assumptions if problems are ambiguous, and sign a pledge against cheating. The problems cover topics such as class diagrams, C programming, UPPAAL templates for modeling an arcade game machine, and verifying system requirements.

Uploaded by

aoli2wei
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

CS132 Software Engineering Midterm Exam

The document is a midterm exam for a Software Engineering course, consisting of five problem sets totaling 80 points, with each problem addressing different programming and design challenges. Students are instructed to write legibly, state assumptions if problems are ambiguous, and sign a pledge against cheating. The problems cover topics such as class diagrams, C programming, UPPAAL templates for modeling an arcade game machine, and verifying system requirements.

Uploaded by

aoli2wei
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CS132: Software Engineering

Midterm Exam

13:00-14:40, June 10th, 2020

There are 5 problem sets and the total points are 80 points. Your score will be divided by 4 to reflect
the 20% constitution for the midterm. Each problem set includes a few questions. For each question, the
maximum possible points are stated.
Please write your answers legibly on the answer booklet so that we can read and understand your
answers. If a problem seems ambiguous, please feel free to state your assumption explicitly and solve the
problem. Obviously, your assumption should be reasonable and should not trivialize the problem.

Pledge. Copy the following pledge and sign your name in your answer booklet:

I neither cheated myself nor helped anyone cheat on this exam.

1
Problem 1. (20 pts)

Companies employ employees (who can only work for one company), and consist of one or more de-
partments. Each company has a single president, who is an employee. Departments have employees as
members and run projects (one or more.) Employees can work in 1 to 3 projects, while a project can have
2 to 50 assigned employees. You may assume that companies have a name and address, while employees
have an ID and a salary.
A partial class diagram is given to you below. Please complete the class diagram. Make sure to show
attributes, multiplicities and aggregation associations, where appropriate. No need to show any opera-
tions.

Solution:

2
Problem 2. (20 pts)

Consider the following C program snippet. All variables are integers. Recall that the integer division in
C causes roundings, e.g., 7/3=2, and 8/3=2.

1. What is the minimum number of test cases for branch coverage testing? (2pts)

2. Please specify a test suite that achieves branch coverage with the minimum number of test cases.
(8pts)

3. What is the minimum number of test cases for condition coverage testing? (2pts)

4. Please specify a test suite that achieves condition coverage with the minimum number of test
cases. (8pts)

(a) Two test cases are needed. One can use a=3; b=1; x=6 to make both branches true, and then use
a=3; b=4; x=0 to make both branches false. (b) Two test cases are needed. One can use a=3; b=1; x=6
to make all four conditions true, and then use a=3; b=4; x=0 to make all four conditions false.

3
Problem 3. (20 pts)

Read the description below carefully and complete the UPPAAL templates, which can be assembled into
a model of arcade game machine.
An arcade machine consists two components: the game host machine and a coin acceptor module. Assume
you are given the following code in global declaration section:
int coins = 0; // Denote the current number of coins inserted to the machine.
bool power = false; // Denote whether the machine is powered. ”insert” will be fired even if the machine
has no power because its a physical signal!

There are some broadcast channels already defined for you. Assume they are all physical signals and
automatically fire in condition.
broadcast chan insert; // It automatically fires when a coin is physically inserted.
broadcast chan boot; // It automatically fires when the machine is connected to power.
broadcast chan shut; // It automatically fires when the machine shuts down;
broadcast chan start; // It automatically fires when start button on the machine is pressed.
broadcast chan refund; // It automatically fires when refund lever is pulled.
Please label the type of statement you are making on the transitions. For example, if you want to add
a guard to the transition, you need to write down ”(guard) t < 3”. Use ”sel” and ”upd” to represent
selections and updates, and ”inv” to denote invariants.

4
1) Complete the UPPAAL template of the game host machine base on the following information: (6pts)

1. The game requires 5 coins to start. i.e. each game start will consume 5 coins.

2. The game will start if therere 5 or more coins inside when the start button is pressed.

3. The game will run 10 minutes once start unless a forced shutdown happens.

4. A timer, t, is defined in this template. The unit is minute.

Note:

ˆ You are allowed to add urgent/committed locations, but not regular locations.

ˆ You are allowed to add edges or add statements on existing edges.

5
2) Complete the UPPAAL template of the coin acceptor. (10pts)
A typical arcade coin acceptor looks like this:
This module is designed to monitor and manipulate the status of coin acceptor with the following con-
straints:

1. Only one coin can be inserted at a time.

2. The module is capable of refund actions. It will refund on following conditions:

(a) If the refund lever is pulled, one coin inside will be refunded. Nothing will happen if the
acceptor holds no coin.
(b) If the acceptor holds 100 coins, it directly refunds the coins inserted afterwards.
(c) If the machine is not powered, it does not accept coins.
(d) If the machine is turned off, the coin count resets without refunding.

Note:

ˆ When the machine is off, it physically rejects coins, but when the machine is on, you must take the
committed state refund to return coins. An action of reducing coin count without passing refund
in this situation will be considered wrong.

6
ˆ You are allowed to add locations in this part of the question. Please make your graph neat if you
decide to do so.

ˆ You are allowed to add edges or add statements on existing edges.

3) Write UPPAAL queries that can verify these requirements: (4pts)


1. The variable coins never exceeds 100, and never goes down to negative.
2. A game never lasts more than 10 minutes. (Assume that your first model is named host)

7
Problem 4. (8 pts)

There are 4 UPPAAL models below with t as a clock:


Please judge whether there exists deadlock in each model and explain why. Answer:
1) Yes. The model can stay in location A such that t is larger than 4, and location B cannot be entered.
2) No. 3) Yes. Location B cannot be entered when t is larger than 4. 4) Yes. Location A cannot be
exited when t is equal to 4.

8
Problem 5. (12 pts)

We built two apps (app1 and app2) in Matlab as shown below:

We would like to achieve the following functionalities:

ˆ Launching app1 ([Link]) will launch app2 ([Link]) automatically.

ˆ Clicking the button on app1 ([Link]) will set the Value of slider on app2 ([Link]) to the
Value of edit field on app1 ([Link]).

Please complete the code of app1 below so that the functionalities above can be achieved.
Answer:

9
10

Common questions

Powered by AI

Challenges in completing a class diagram for such a system include defining clear relationships and multiplicities between entities, such as correctly modeling the president as both an employee and a unique role. These challenges can be addressed by adhering to correct UML notation practices, ensuring accurate aggregation versus composition representation, and verifying that the diagram satisfies all requirements like unique roles and allowable number of projects or employees per project .

Broadcast channels in UPPAAL models allow seamless communication between concurrent components of a system by automatically firing signals such as 'insert' or 'boot'. The advantage is that they simplify coordination between modules without direct coupling. However, they may lack precision in large systems where signal collisions can occur, potentially leading to uncontrollable states due to the simultaneous triggering of similar events .

The constraints for designing a coin acceptor module include: allowing only one coin to be inserted at once, carrying out a refund when specific events occur, not accepting coins when the machine is unpowered, and rejecting coins without refund when the machine turns off. These constraints ensure proper functionality by maintaining accurate coin counts and enabling appropriate responses to user actions and power states, which are essential for a consistent user experience and system integrity .

Maintaining a pledge of honesty during exams is crucial as it upholds the value of fair assessment, ensuring that grades reflect a student's true understanding and skills. This integrity is vital as it impacts academic credibility and fosters trust, which are essential in professional environments where engineers handle sensitive data and critical systems, reinforcing a culture of ethical responsibility .

Branch coverage testing ensures that each possible branch from a decision point is executed at least once, which typically requires fewer test cases as it focuses on the truth value of decisions. In contrast, condition coverage testing focuses on evaluating each boolean sub-expression independently, often requiring more test cases to ensure each condition within a decision is true and false at least once. This implies that although condition coverage is more comprehensive, it can be less efficient in terms of the number of test cases required .

A MATLAB GUI application uses event-driven programming to ensure consistency and data integrity across components. This involves setting up listeners for user inputs, which trigger callbacks to validate and update related data throughout the application. Ensuring data integrity often includes checks before updating states, such as verifying user input types or ranges, and cascading updates to interconnected elements, like updating sliders based on text inputs or vice versa .

UPPAAL queries can be crafted to ensure that variables like 'coins' remain within defined limits and that the game duration does not exceed a set maximum. For example, a query can check that the coin count never exceeds 100 or goes negative, and another can confirm games do not last longer than 10 minutes. These verifications benefit system reliability as they prevent errors like buffer overflows or unexpected crashes, maintaining consistent operation .

Assumptions in addressing ambiguous questions must be reasonable and not trivialize the problem. They should align with the typical complexities and circumstances expected in real-world scenarios to maintain the integrity and challenge of the exam question. An inappropriate assumption may lead to oversimplification, which can result in an incorrect or incomplete solution .

To ensure seamless interaction between two Matlab applications, mechanisms such as event listeners and callbacks are used. For example, launching app1 automatically launches app2 by directly including app2's initialization in app1's startup routine. Additionally, app1 can manipulate app2's elements, such as synchronizing a slider’s value based on an edit field in app1, through inter-app communication protocols implemented via callbacks that trigger updates or actions within app2's context .

Deadlocks in UPPAAL models occur when a model reaches a situation where no transitions can occur. Such conditions can be diagnosed by examining if time constraints prevent transitions, or if lack of a necessary condition halts further moves. For example, if location B must be entered before time t exceeds 4, failing to meet this condition would result in a deadlock .

You might also like