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

Implement a program named main_starWars; program main_starWars makes a call to t

ID: 3806266 • Letter: I

Question

Implement a program named main_starWars; program main_starWars makes a call to the function named createClone; In createClone you should ask the user about the total_number of clone warrior that should be created, returning it to the main_starWars function; Function main_starWars calls the function inputClones, sendig the total_number of clone warrior asking the user for each of the clones, warrior(i).name and warrior(i).timeCounter; the function inputClones return to the function main_starWars the information for all clone using struct. As clones are believed to have a shorter lifespan, from the function main_starWars, make a call to the function lifeSpan, sending to the function lifeSpan the respective warrior information such as warrior(i).name and warrior(i).timeCounter for each clone; run the function lifespan with a loop counting the biological clock from each clone as follow: every loop iteration, print the warrior name and timeCounter; the timeCounter is decreased by 1 in each iteration; if for that clone timeCounter is zero print name and timeCounter with the message: "The clone NAME with TIMER is dead", or "The clone NAME with TIMER is alive" if timeCounter is larger and zero (where NAME and TIMER is the respective name and lifespan/time from the respective clone); inform when all clones are dead, then finish the program.

Explanation / Answer

function total_number = createClone()
total_number=input('Enter the Number of Clones to be created')
end

function [warriors]= inputClones(n)
field1 = 'name'; value1 = {};
field2 = 'timeCounter'; value2 = [];
warriors = struct(field1,value1,field2,value2);
for i=1:n
warriors(i).name=input('Enter the warrior name :');
warriors(i).timeCounter=input('Enter the warrior Time Counter :');
end
end

function []=lifeSpan(`w)
while(1)
p =w.timeCounter - 1;
w.timeCounter=p;
if p <=0
disp(' The clone is dead')
break;
else
disp(w.timeCounter)
end
end
end

%% Main Program starts here
clc;
clear ;
close all;
%% Part 1
n=createClone();
%% Part 2
warriors=inputClones(n);
%% Part 3
for i=1:n
lifeSpan(warriors)
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote