CSCI3100 Software Engineering
Assignment 3
Due – 11:59:59pm, 31th March, 2024 (Sunday)
Note: Homework needs to be submitted together with Veriguide declaration ("Academic Honesty Declaration Statement"). Otherwise, your assignment will be marked as 0. Late submissions will receive different score deductions as follows:
1. Late for within 24 hours: 30% deduction.
2. Late for within 24~48 hours: 60% deduction.
3. Late for more than 48 hours: 100% deduction.
4. Late Veriguide declaration before score releasing: 10% deduction.
5. Late Veriguide declaration after score releasing: 100% deduction.
Answer the following problems based on lecture Topics 5 notes, from which you can consider for solutions. Special Note: Directly using ChatGPT or GPT4 to answer these questions will not get good marks. In particular for Q4, straight answers from them will get 0 mark.
Q1. Software Design Notation (25 points)
Figure 1. Play TRPG with VR devices (generated by DALL-E-3)
TRPGs (Tabletop Role-Playing Games) are a kind of non-digital game in which players participate by verbally communicating and acting out fictitious characters. TRPG typically takes place around a table where participants sit together. In a TRPG such as Dungeons & Dragons, one of the participants takes on the role of the Game Master (GM) acting as the director of the story while other players act as characters of a certain profession, which could be a brave warrior, a wise mage, or a cunning thief. Each character possesses various attributes like health points, magic points, and experience points. Players describe their characters' actions verbally, interact with other players, and make decisions based on scenarios and situations presented by the GM. Sometimes they use a dice to determine the success of actions. The advent of VR devices has allowed players to have a more immersive experience while playing these types of games and has also enabled them to play together with other players from the comfort of their own homes, just like in-person games. Apple's Version Pro has recently been released, and you immediately realize such a TRPG platform on the Version Pro would be highly welcomed. Therefore, you plan to create a platform. named TalesTable. The whole system should be designed as a TALESTABLE_SYSTEM module, and it needs to provide the following functionalities for players and GMs.
For players:
. Create Character. A Player needs to input the player ID to create a new character within the system, including setting their play name and choosing a profession (such as a brave warrior, a wise mage, a cunning thief, etc.).
. Throw Dice. Players can simulate dice rolls through the system to determine the success of their characters' actions. This function does not require any input and will return the dice value of this throw.
. Buy Item. Players can purchase items (identified by an integer itemID in the system) in the game's store to enhance their character or to complete specific quests.
. Use Item. Players can utilize items that their characters possess, such as potions to restore health or magical items to boost strength. The TALESTABLE_SYSTEM will invoke a function to check
whether the player could use this item as some items maybe only used by some specific profession. Note that this checking function should not be visible from outside TALESTABLE_SYSTEM. If the check is passed, the user will be allowed to use the item.
For GMs:
. Edit Player. Game Masters can edit the status of players' characters. For example, if a player is attacked, the GM will decrease his/her health points. The GMs should input the update type (add, modify, or delete) and the player ID. According to the update type, TALESTABLE_SYSTEM will take different operations on the show.
. Change Scenario. Game Masters can update and alter the background image of the game to fit the progression of the game by entering a new scenario ID. The TALESTABLE_SYSTEM will return the image of the new scenario.
The TALESTABLE_SYSTEM module uses two modules named SHOP_HANDLER and
PLAYER_HANDLER. SHOP_HANDLER is designed for handling each item in the shop system. The implementation details can be omitted. PLAYER_HANDLER is an abstract data type (ADT). It encapsulates the data structure of a player and the operations on it. The first interface is to add a new player, requiring player ID, player name, the profession ID of the player. The second interface is to modify the attribute of a player, requiring the player ID, the name of the attribute you want to modify, and the expected modified value. The third interface is to delete a player using its player ID.
Please answer the following questions:
(1) (5 pt) Using TDN, describe the ADT of PLAYER_HANDLER. Concentrate your design in the module interface. The implementation section could be omitted with comments only. Please explain your design with proper comments in your TDN.
(2) (9 pt) Using TDN, describe the module of the TALESTABLE_SYSTEM module. Concentrate your design in the module interface. The implementation section could be simplified by using comments. Please explain your design with proper comments in your TDN.
(3) (11 pt) Assuming PLAYER and GM are two other modules, whose details are omitted. Please use GDN to depict the whole system, which includes all modules described above.
Grading Criteria:
(1) The grading of TDN is based on the correctness of the modules, data types and functions. The functions should include the input and output. All descriptions in the question should be reflected in the TDN.
(2) The grading of GDN is based on the correctness of the modules and functions. You do not need to list the input and output of the functions.
(3) Each missing or incorrect component will cause a 1-point deduction.
Q2. UML (25 points)
The online Artificial Intelligence (AI)-based chat system is to provide users a chatbot, such as ChatGPT as follows. In this problem, we would like to design such a system
(1) (15 pt) The system has a database of all the users and their chat history with the chatbot. There
are two types of chatbots, 1) TheSmart and 2) TheSmarter, with different prices and types.
For users that have been registered in the system, each user has a username, password, balance, and a unique user ID. Users can change the password for login of the system by a mobile app. In addition, users can top-up their balance in the app.
The mobile app and website can access the Chat Management System, which shows all the chatbots. Chatbots can receive an input question and return an output answer.
Please draw a UML class diagram to describe all the objects of this system and specify the attributes and operations associated with all of them.
(2) (10 pt) The following shows the process of a user chatting with the chatbot from the mobile app.
Please draw a UML sequence diagram to describe this process. The involved entities are: User, Mobile App, ChatBot, and Chat Management System.
a. The user login the Mobile App. The user sends her/his username and password to the App.
b. The Chat Management App checks the validity of username and password.
c. If the username and password is valid, go to (d); otherwise, the App will return “Invalid account ” to the passenger.
d. If the account is valid, the user will choose a ChatBot in Mobile App to chat with, and then the App will send a request to Chat Management System server to call the chat service.
e. The user input a question through App, and App sends the question to Chat Management System.
f. The ChatBot returns an answer to the App through Chat Management System.
g. The App shows the answer message to the user.
Grading Criteria:
The representations of UML are not unique. The grading of UML diagrams is based on the accurate representation of the objects, relationships, and interactions specified in the question. Each missing or incorrect component in the diagram will cause a 2-5 points deduction. However, the number of components does not necessarily match the total points of the question. There will be several points (5 points) left to mark for the presentation clarity of the UML diagram. These points will be graded based on the readability and consistency of the diagram, including the use of proper notation and labelling, the arrangement of elements, and the overall aesthetic appeal of the diagram.
Q3. Stepwise Refinement Revisit (25 points)
Please design a collaborative filtering-based book recommendation system that suggests new books to a user based on the reading history of other users with the most overlaps in the books they have read. The input to the system is a user profile consisting of a list of book titles the user has read. For example, a user profile might be as follows:
{"Crime and Punishment", "1984", "The Great Gatsby"}
The system's output is a list of book recommendations composed of titles read by the most similar user (the user with the most books in common) that the original user has not yet read. For this problem, it is assumed that there is always at least one book that the most similar user has read but the original user has not.
(1) (16 pt) Please develop proper steps of stepwise refinement to solve this problem in a design (at least 3 refinements).
(2) (9 pt) Show your implementation of the last refinement with your preferred programming language (C++, Java, Python, etc.). Your answer should include (I) the source code, (II) your own test cases.
Grading Criteria:
(1) The answer to this problem is not unique. For this question, reasonable abstractions are all acceptable. But you should have at least three steps refinement. Each missing step will cause a 4-point deduction. The grading of each step is based on the relationship with the last step and the correctness of this step.
(2) The grading of this problem is based on the correctness of the codes and whether your answer involves the test case. If you do not encapsulate your code into a function, you will be deducted 3 points.
Q4. Software Design: Recursive and Non-Recursive Modules (25 points)
Given a binary tree, return all root-to-leaf paths. A root-to-leaf path is a path that starts at the root node and ends at a leaf node (a node with no children).
Task:
Implement a function binaryTreePaths(root) that takes the root of a binary tree and returns a list of strings, each representing a path. A path can be represented as a string with node values separated by "->". For example, the path 1 -> 2 -> 5 represents a path from root node 1 through node 2 to leaf node 5.
Recursive Way:
The following C++ function is a recursive solution. Fill out the blanks in the function.
#include
#include
#include
#include struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} };
// Recursive version
void findPaths(TreeNode* node, std::string path, std::vector paths) { if (!node) return; // Append current node's value to the path path += std::to_string(node->val); // Check if it's a leaf node if ( ① ) { paths.push_back(path); // Add path to paths vector } else { findPaths( ② ); findPaths( ③ );); |
} }
std::vector
std::vector findPaths(root, "", paths); return paths; } |
Non-Recursive Way:
The following C++ function is a non-recursive solution using the Standard Template Library (STL) “stack”. Fill out the blanks in the following function
#include
#include
#include
#include
struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} };
std::vector
std::vector if (!root) return paths;
std::stack stack.push({ ① });
while ( ② ) { auto [node, path] = stack.top(); stack.pop(); |
path += std::to_string(node->val); if ( ③ ) { paths.push_back(path); } else { if ( ④ ) stack.push({ ⑤ }); if ( ⑥ ) stack.push({ ⑦ }); } }
return paths; } |
Hint: The C++ STL stack provides the following functions:
• empty(): This function is used to test if the stack is empty. The function returns true if the stack is empty, false otherwise.
• size(): This function returns the number of elements stored in the stack.
• top(): This function is used to access the top element of the stack.
• push(): This function is used to insert a new element at the top of the stack.
• pop(): Remove the element at the top of the stack
Grading Criteria:
There are ten blanks in total, with each one 2.5 points. The answer may not be unique, thus, as long as the semantic is correct, you will get the point.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。