Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1: The Basics [20pt] You get a summer job as a software engineer. Your b

ID: 3738712 • Letter: P

Question

Problem 1: The Basics [20pt] You get a summer job as a software engineer. Your boss wants you to work on a project to create software for playing card games online. He does not want you to complete the whole software but work on only pieces of it. He calls you into his office and hands you a piece of paper showing the pseudocode of what he wants you to do: Goal is to create a program which asks a single user how many cards he/she wants and then displays the cards to the screen in a specific format. Pseudocode: 1. ask a user how many cards he/she wants 2. initialize a deck of cards (52 cards, not shuffled) 3. shuffle the deck of cards 4. give the user his/her cards 5. display the cards to the screen -T E- He warns that the whole code should only consist of I program and 6 functions. He provides you with a description of what the functions MUST input and MUST output (function input not keyboard input). He also warns that the cards must look like the ones shown.

Explanation / Answer

init_deck.m

function y = init_deck()

f1='suit';
f2='name';
f3='val';

k=1;
for i=1:4
for j=1:13
switch i
case 1
val1='heart';
case 2
val1='spade';
case 3
val1='diamond';
case 4
val1='Club';
  
end
switch j
case 1
val2='A';
case 11
val2='J';
case 12
val2='Q';
case 13
val2='K';
end
  
s(k)=struct(f1,val1,f2,val2,f3,j);
k=k+1;
end
end
  
  
end

shuffle_deck.m

function d = shuffle_deck(order)
i=1:52;
new=randomize_order();
d(new)=order(i);

end

randomize_order.m

function n = randomize_order()
n=randperm(52,52);
end