using Mat lab CSCI 1371 Fall 2018 Lab 3 Create a program that allows you to purc
ID: 3747565 • Letter: U
Question
using Mat lab CSCI 1371 Fall 2018 Lab 3 Create a program that allows you to purchase stock shares of either Tesla or Facebook. Your program should initiate some number of stock shares that you own for each company. Your program should determine if you want to purchase or sell stock shares of either Tesla or Facebook. Your program should update the number of shares that you own for each company. Your program should display the beginning number of shares that you own and the number you own after you choose to buy or sell. Your program should consist of a main function and sub functions. Your program should be modular, readable, and well structured.Explanation / Answer
function [facebook_shares,twitter_shares] = main()
facebook_shares = initiate_facebook();
twitter_shares = initiate_twitter();
facebook_shares = purchase_facebook(facebook_shares);
twitter_shares = purchase_twitter(twitter_shares);
facebook_shares = sell_facebook(facebook_shares);
twitter_shares = sell_twitter(twitter_shares);
print (facebook_shares)
print (twitter_shares)
end
function m = initiate_facebook()
m = randi([1, 100]) % initialize facebook with random shares
end
function m = initiate_twitter()
m = [1,100] % initialize twitter with random shares
end
function m = purchase_facebook(x)
m = x + randi([0,x]) %add purchased stocks
end
function m = purchase_twitter(x)
m = x + randi([0,x]) %add purchased stocks
end
function m = sell_facebook(x)
m = x - randi([0,x]) %remove sold stocks
end
function m = sell_twitter(x)
m = x - randi([0,x]) %remove sold stocks
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.