【MTRX3760】Mechatronic Systems Design

Assignments will be assessed based on the following components. Incomplete submissions will have severely reduced marks:
Report : Submit a .pdf report using the class Canvas site. The report can be very simple, and
needs only directly address the questions laid out in the assignment.
The cover page for your report should include your SID and tutorial section, but do not include
your name to comply with the University’s anonymous marking policy.
Code appendix : The appendix of your report must contain a printout (in text format) of all
source code written for the assignment. File header comments and proper formatting will be
critical to making this section readable. Unintelligible code attachments will result in loss of
marks.
Code : Submit your code (code only, no binaries) in a .zip file via the canvas site.
Please see Lab 1 for hints on preparing your report, including how to format code for inclusion in the appendix.
Logic Simulator Redesign
This lab has the following goals:
1. To allow you to revisit a familiar design problem with new learnings covered over the first four
weeks of the unit,
2. To simulate and build your understanding of a system of moderate complexity, and
3. To exercise design thinking and decision-making when faced with the many open design choices typical of a real-world engineering problem.
In the circuit simulator from Lab 2 we used hard-coded circuit designs. For this lab you will redesign the circuit simulator to load the description of the circuit from a circuit description file. This means your program should build the circuit dynamically at runtime rather than in a hard-coded manner.
You may design the circuit description language yourself, though an example of a suitable format and a means of reading it is provided in the code accompanying this lab handout.
As part of the refactor, we will lift a few simplifications applied in previous labs. We have previously allowed global constants and single-file submissions. These are not applicable to this lab:
1. Employ the “encapsulate everything” strategy of object-oriented design taught in lecture, such
that there are no global constants or floating functions or data,
2. Build your solution as a multi-file project, following the guiding principle that each class should
generally have its own header and implementation files, and
3. In general there should be very few constants or hard-coded circuitry, as the goal is to move those aspects of the program into the input files.
To make this lab more tractable the following new simplifications may be applied:
1. Support for subcircuits is not required,
2. You may limit the logic gates supported to AND, OR, XOR and NOT gates.
You may choose to start from your own Lab 2 solution or the one provided, or you may choose to start from scratch. Regardless, your submission should demonstrate the principles of object-oriented design and C++ coding best practices taught in lecture.
  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here is the code with the suggested modifications: ``` #include <iostream> #include <vector> #define BIAS -1000 #define MY_INT_MIN -20000001 #define MY_INT_MAX 20000001 int main() { int n, res = 0, tmp_pt = 0, last_pt = 0, tmp_val = MY_INT_MAX, last_val = 0, tmp_prt = 0; std::vector<int> queue; std::cin >> n; const int N = n; int mtrx[N][N], w[N], prt[N]; for (int i = 0; i < n; i++) { std::cin >> w[i]; if (w[i] < tmp_val) { tmp_val = w[i]; tmp_pt = i; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> mtrx[i][j]; if (i == j) { mtrx[i][j] = MY_INT_MIN; } } } mtrx[tmp_pt][tmp_pt] = tmp_val; for (int i = 0; i < n - 1; i++) { last_pt = tmp_pt; tmp_val = MY_INT_MAX; for (int j = 0; j < n; j++) { if (mtrx[j][last_pt] < (BIAS - mtrx[j][j])) { mtrx[j][j] = BIAS - mtrx[j][last_pt]; prt[j] = ~last_pt; if (mtrx[j][last_pt] < tmp_val) { tmp_val = mtrx[j][last_pt]; tmp_pt = j; } } else if (BIAS > mtrx[j][j] && mtrx[j][last_pt] < tmp_val) { tmp_val = mtrx[j][last_pt]; tmp_pt = j; } } mtrx[tmp_pt][tmp_pt] = ~prt[tmp_pt]; } for (int i = 0; i < n - 1; i++) { tmp_val = MY_INT_MAX; for (int j = 0; j < n; j++) { if (mtrx[j][j] < 0 && w[j] < tmp_val) { tmp_val = w[j]; tmp_pt = j; } } last_pt = tmp_pt; last_val = tmp_val; while (mtrx[tmp_pt][tmp_pt] < 0) { tmp_prt = ~mtrx[tmp_pt][tmp_pt]; if (mtrx[tmp_pt][tmp_prt] > tmp_val) { tmp_val = mtrx[tmp_pt][tmp_prt]; } tmp_pt = tmp_prt; } if (last_val != tmp_val) { queue.clear(); tmp_pt = last_pt; while (mtrx[tmp_pt][tmp_pt] < 0) { queue.push_back(tmp_pt); tmp_prt = ~mtrx[tmp_pt][tmp_pt]; if (mtrx[tmp_pt][tmp_prt] == tmp_val) { break; } tmp_pt = tmp_prt; } for (int j = queue.size() - 1; j > 0; j--) { mtrx[queue[j]][queue[j]] = ~queue[j - 1]; } mtrx[last_pt][last_pt] = w[last_pt]; } } for (int i = 0; i < n; i++) { if (mtrx[i][i] > 0) { res += mtrx[i][i]; } else { tmp_prt = ~mtrx[i][i]; res += mtrx[i][tmp_prt]; } } std::cout << res << std::endl; return 0; } ``` I hope this helps!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值