a code walk thru explaining significant pieces of functionality copy paste code listed below

Get perfect grades by consistently using our affordable writing services. Place your order and get a quality paper today. Take advantage of our current 20% discount by using the coupon code GET20


Order a Similar Paper Order a Different Paper

• Create: short, simple side-notes that explains what happens during each line of code (Explanation Can be done in word)

• Run Program: in Matlab while screen recording (The “Demo Screen Recording”: should have No Sound and should be about 5-10 minutes in length) – This is only to show how the program works.

==============================================================================================================================================================

COPY/ PASTE the program listed – BELOW – into Matlab

===============================================================================

% Load information from account database file if file exists, otherwise

% Create new database.

filename = ‘AccountDatabase.mat’;

try

% Load file if it exists.

account = load(filename);

catch ME

% Create new account database.

% Map container variable to store all users account information

% Account number is key and struct container user info is value.

accountDB= containers.Map;

% Add two dummy users to account database

accountDB(‘001122’) = struct(‘firstName’, ‘John’, ‘lastName’, ‘Doe’, ‘balance’, 1000);

accountDB(‘997722’) = struct(‘firstName’, ‘Jane’, ‘lastName’, ‘Smith’, ‘balance’, 700);

end

%% Welcome prompt. Inquire if user have account or not.

% Create account if user is new.

while(true)

disp(‘Welcome to Student Bank’)

selection = getResponse(‘Do you have an account [Y/N]: ‘);

fprintf(“n”)

if (selection == ‘N’)

fprintf(“Okay. Let’s open a new account for you.n”)

data = createAccount(accountDB);

accountNumber = data{1};

accountDB = data{2};

fprintf(“nAccount created. nYour account number is: %sn”, accountNumber);

break

else

accountNumber = input(‘Enter your 6 digit account number: ‘, ‘s’);

if isKey(accountDB, accountNumber)

break

else

fprintf(‘Account not found. Try again.nn’)

end

end

end

%% Display Transaction options to the user.

fprintf(“nWelcome %s %sn”, accountDB(accountNumber).firstName, accountDB(accountNumber).lastName);

fprintf(“Account Balance: $%.2fn”, accountDB(accountNumber).balance);

prompt = ‘What would you like to do today?’;

while (true)

option = displayMenu(prompt);

if (option == 1)

accountDB = deposit(accountNumber, accountDB);

fprintf(“Deposit successful.n”)

printAccountBalance(accountNumber, accountDB, ‘New Account Balance is: ‘)

elseif (option == 2)

accountDB = withdraw(accountNumber, accountDB);

fprintf(“Withdrawal successful.n”)

printAccountBalance(accountNumber, accountDB, ‘New Account Balance is: ‘)

elseif(option == 3)

printAccountBalance(accountNumber, accountDB, ‘Account Balance: ‘)

elseif (option == 4)

save(filename, ‘accountDB’);

fprintf(“Thank you %s %s for banking with us.n”, accountDB(accountNumber).firstName, accountDB(accountNumber).lastName)

break

end

prompt = ‘Perform another transaction?’;

end

%% Function to print account balance.

function printAccountBalance(accountNumber, accountDB, prompt)

if accountDB(accountNumber).balance >= 0

fprintf(“%s$%.2fnn”, prompt, accountDB(accountNumber).balance);

else

fprintf(“%s-$%.2fnn”, prompt, abs(accountDB(accountNumber).balance));

end

end

%% Function to perform withdrawal transactions

function db = withdraw(accountNumber, accountDB)

overdraftFee = 35;

while(true)

try

withdrawAmount = input(‘Enter the amount to withdraw: ‘);

% Validate the entered amount

if (isnumeric(withdrawAmount))

if withdrawAmount > accountDB(accountNumber).balance

fprintf(“The amount you want to withdraw exceeds your account balance.n”)

printAccountBalance(accountNumber, accountDB, ‘Account Balance: ‘)

fprintf(“If you wish to continue, an overdraft fee of $%.2f would be charged to your account.n”, overdraftFee);

selection = getResponse(‘Do you wish to continue withdrawal [Y/N]: ‘);

if selection == ‘Y’

break;

else

disp(‘Please enter another amount to withdraw’);

end

else

break;

end

else

disp(‘Invalid input. Try again.’)

end

catch ME

fprintf(“Error: %sn”, ME.message);

end

end

accountDetails = accountDB(accountNumber);

if withdrawAmount > accountDetails.balance

accountDetails.balance = accountDetails.balance – withdrawAmount – overdraftFee;

else

accountDetails.balance = accountDetails.balance – withdrawAmount;

end

accountDB(accountNumber) = accountDetails;

db = accountDB;

end

%% Function to perform deposit transactions.

function db = deposit(accountNumber, accountDB)

while(true)

try

depositAmount = input(‘Enter deposit amount: ‘);

% Validate the entered amount

if (isnumeric(depositAmount) && depositAmount >= 0)

break;

else

disp(‘Invalid input. Enter a positive amount’)

end

catch ME

fprintf(“Error: %sn”, ME.message);

end

end

accountDetails = accountDB(accountNumber);

accountDetails.balance = accountDetails.balance + depositAmount;

accountDB(accountNumber) = accountDetails;

db = accountDB;

end

%% Function to create new bank account.

function newData = createAccount(accountDB)

firstName = input(‘Please enter your first name: ‘, ‘s’);

lastName = input(‘Please enter your last name: ‘, ‘s’);

% Generate new account number.

while (true)

accountNumber = ”;

for i = 1:6

accountNumber = strcat(accountNumber, num2str(randi(9)));

end

if (isKey(accountDB, accountNumber) == false)

break

end

end

newData{1} = accountNumber;

accountDB(accountNumber) = struct(‘firstName’, firstName, ‘lastName’, lastName’, ‘balance’, 0.0);

newData{2} = accountDB;

end

%% Function to display welcome menu to user.

function selection = getResponse(prompt)

while(true)

selection = upper(input(prompt, ‘s’));

if (selection == “YES” || selection == “Y”)

selection = ‘Y’;

break;

elseif (selection == “NO” || selection == “N”)

selection = ‘N’;

break

else

disp(‘Invalid input. Try again.’)

end

end

end

%% Function to display account transaction options

% user’s selection.

function option = displayMenu(prompt)

while(true)

disp(prompt)

disp(‘ 1: Deposit’)

disp(‘ 2: Withdraw’)

disp(‘ 3: Check Account Balance’)

disp(‘ 4: Exit’)

fprintf(“n”)

try

option = input(‘Enter selection: ‘);

if isnumeric(option) && (option == 1 || option==2 || option==3 || option==4)

break

else

disp(‘Invalid input. Try again’)

end

catch ME

fprintf(“Error: %sn”, ME.message);

end

end

end

Have your paper completed by a writing expert today and enjoy posting excellent grades. Place your order in a very easy process. It will take you less than 5 minutes. Click one of the buttons below.


Order a Similar Paper Order a Different Paper