You are to write a GUI program that will allow a user to buy, sell and view stoc
ID: 3576767 • Letter: Y
Question
You are to write a GUI program that will allow a user to buy, sell and view stocks in a stock portfolio. This document will describe the minimum expected functions for a grade of 90. Your mission is to “go and do better.” The meaning of “do better” is largely up to you. For example, you might track the profit or loss on the trades. You might allow for sales of partial holdings, or subsequent purchases to be added to an existing holding. Be creative. Objectives By the end of this project, the student will be able to • write a GUI program that maintains a cash balance, list of stock holdings, supports buying and selling of stocks and displays the current portfolio inventory • demonstrate the ability to assemble already-written classes into a larger, more complicated program • demonstrate the ability to segregate business logic from user interface code. Capabilities At a minimum, the program should • allow a user to buy a stock with a given number of shares and price per share. • display the current portfolio (stock ticker, number of shares, initial price). • update the portfolio display for purchases and sales. • allow the user to sell all of the shares of a given stock. • give the user an initial cash balance, and update and display the balance according to the user's purchases and sales. • ignore any transaction that causes the cash position to go below $0. Sample Execution The initial frame has text fields for the stock ticker, number of shares, and price per share. It has a label for the current cash balance. It also has “buy” and “sell” buttons. Figure 1 Initial Frame Let's buy Apple (ticker AAPL) shares. First we enter the ticker, number of shares and price per share. Figure 2 Data for Apple Purchase Then we click “Buy.” Note our cash was reduced accordingly. Our portfolio inventory now displays since it's no longer empty. Figure 3 Click Buy to Purchase Apple Let's buy IBM. We enter the ticker, number of shares and price per share. Figure 4 Data to Purchase IBM We click “Buy.” Our cash is reduced appropriately, our portfolio is updated. WidgetView moves things around. We won't worry about that. We also won't worry about the not-quite-right truncation of the last penny of the cash balance. Figure 5 Click Buy to Purchase IBM Let's buy Microsoft (MSFT). We'll just skip to the completed transaction. Figure 6 Purchase of Microsoft We're losing faith in IBM's CEO; let's sell it. We need to tell our portfolio manager which stock we want to sell, and the selling price per share. Since we're selling all of our shares, we don't need to fill in that field. Figure 7 Data to Sell IBM We click “Sell,” and the portfolio listing and cash are updated. Figure 8 IBM is Sold Hints The StockHolding and PortfolioList classes from earlier Lessons (Writing Classes Better) should be directly usable in this project. The sample screens above were generated with a version of that code that had slightly different toString methods, but that's not significant to the function of the program.
Explanation / Answer
void metric linear unit (int c[][], int a[][], int b[][])
Here's my unit code:
.text
main:
j mm
mm:
la $a3, array_A # base address for array_A loaded into $a3
la $a1, array_B # base address for array_B loaded into $a1
la $a2, array_C # base address for array_C loaded into $a2
li $t1, four # $t1 = four (row-size and loop end)
li $s0, zero # i = 0; initialize first for loop
loop1:
li $s1, zero # j = 0; restart second for loop
loop2:
li $s2, zero # k = 0; restart third for loop
sll $t2, $s0, two # $t2 = i * four (size of row of c)
addu $t2, $t2, $s1 # $t2 = i * size(row) + j
sll $t2, $t2, two # $t2 = computer memory unit offset of [i][j]
addu $t2, $a2, $t2 # $t2 = computer memory unit offset of [i][j]
lw $t4, 0($t2) # $t4 = two bytes of c[i][j]
loop3:
sll $t0, $s2, two # $t0 = k * four (size of row of b)
addu $t0, $t0, $s1 # $t0 = k * size(row) + j
sll $t0, $t0, two # $t0 = computer memory unit offset off [k][j]
addu $t0, $a1, $t0 # $t0 = computer memory unit address of b[k][j]
lw $t5, 0($t0) # $t5 = two bytes of b[k][j]
sll $t0, $s0, two # $t0 = i * four (size of row of a)
addu $t0, $t0, $s2 # $t0 = i * size(row) + k
sll $t0, $t0, two # $t0 = computer memory unit offset of [i][k]
addu $t0, $a3, $t0 # $t0 = computer memory unit address of a[i][k]
lw $t6, 0($t0) # $t6 = two bytes of a[i][k]
mul $t5, $t6, $t5 # $t5 = a[i][k] * b[k][j]
add $t4, $t4, $t5 # $t4 = c[i][j] + a[i][k] * b[k][j]
addiu $s2, $s2, one # $k = k + one
bne $s2, $t1, loop3 #if (k != 4) head to loop3
sw $t4, 0($a2) # c[i][j] = $t4
#----------TEST-------------
li $v0, 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.