Assignment 7.docx - 6 A Pseudocode class StockTransaction Declarations private string stockSymbol private string stockName private num pricePerShare

Assignment 7.docx - 6 A Pseudocode class StockTransaction...

This preview shows page 1 - 5 out of 14 pages.

6. A. Pseudocode: class StockTransaction Declarations private string stockSymbol private string stockName private num pricePerShare public void setStockSymbol(string symbol) stockSymbol = symbol return public void setStockName(string name) stockName = name return public void setPricePerShare(num price) pricePerShare = price return public string getStockSymbol() return stockSymbol public string getStockName() return name public num getPricePerShare() return pricePerShare endClass B. start Declarations StockTransaction stockTrans1 StockTransaction stockTrans2 stockTrans1 = getStockData() stockTrans2 = getStockData() display(stockTrans1) display(stockTrans2) stop StockTransaction getStockData() Declarations StockTransaction trans string stockSym string name num price output “Enter stock symbol ” input stockSym output “Enter stock name ” input name output “Enter price ” input price
trans.setStockSymbol(stockSym) trans.setStockName(name) trans.setPricePerShare(price) return trans void display(StockTransaction trans) output “Stock Transaction data” output “Stock symbol: ”, trans.getStockSymbol() output “Name: ”, trans.getStockName() output “Price: ”, trans.getPricePerShare() return C. start Declarations num x = 0 num MAX = 10 StockTransactions trans[MAX] while x < MAX trans[x] = getStockData() x = x + 1 endwhile x = 0 while x < MAX display(trans[x]) x = x + 1 endwhile stop StockTransaction getStockData() Declarations StockTransaction trans string stockSym string name num price output “Enter stock symbol ” input stockSym output “Enter stock name ” input name output “Enter price ” input price trans.setStockSymbol(stockSym) trans.setStockName(name) trans.setPricePerShare(price) return trans void display(StockTransaction trans) output “Stock Transaction data” output “Stock symbol: ”, trans.getStockSymbol() output “Name: ”, trans.getStockName() output “Price: ”, trans.getPricePerShare() return
D. start Declarations num x = 0 num MAX = 10 StockTransactions trans[MAX] while x < MAX trans[x] = getStockData() x = x + 1 endwhile displayHighLowPrices(trans) stop StockTransaction getStockData() Declarations StockTransaction trans string stockSym string name num price output “Enter stock symbol ” input stockSym output “Enter stock name ” input name output “Enter price ” input price trans.setStockSymbol(stockSym) trans.setStockName(name) trans.setPricePerShare(price) return trans void displayHighLowPrices(StockTransaction[] transactions) Declarations num high = transactions[0].getPricePerShare() num low = transactions[0].getPricePerShare() num MAX = 10 while x < MAX if transactions[x] < low then low = transactions[x].getPricePerShare() else if transactions[x] > high then high = transactions[x].getPricePerShare() endif endif x = x + 1 endwhile output “The highest value is ”, high output “The loweset value is ”, low return 7. A. class Pizza Declarations private string topping private num diameter
private num price public void setTopping(string topping) this.topping = topping return public void setDiameter(num size) diameter = size return public void setPrice(num price) this.price = price return public string getTopping() return topping

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture