Question

Function Name: ​citizenWatch Inputs: Extra Credit 1. (double) T​ he current position of the hour hand...

Function Name: ​citizenWatch Inputs:

Extra Credit 1. (double) T​ he current position of the hour hand 2. (double) T​ he current position of the minute hand 3. (double)​ A positive or negative number of minutes

Outputs: 1. (double)​ The position of the hour hand after the specified time 2. (double) T​ he position of the minute hand after the specified time Background:

The moment is finally here. You’ve been saving up your whole life and now you can finally afford a Citizen watch! You decide to go to Ross to buy your very own, brand new Citizen watch. Unfortunately, your friend Sam presses a random button on your Citizen watch and you’re worried that he broke it. To make sure he didn’t, you decide to write a MATLAB function to determine where the hour and minute hands would be after a certain amount of time has passed so that you can make sure your Citizen watch is still working properly.

Function Description: This function will take in the current position of the hour hand, as an integer between ​0 and ​11 (​0 for noon/midnight), the current position of the minute hand, as an integer between ​0 and ​59​ (​0​ for "on-the-hour") and a positive or negative number of minutes elapsed. Given this information, determine the new position of the clock hands. You should assume that the hour hand does not move until the next hour has begun. For example, the hour hand stays on ​2​ from 2:00 until 2:59 and only at 3:00 does the hour hand move to ​3​.

Example [hour, min] = citizenWatch(11, 30, 122) hour → 1 min → 32

Notes: ● The ​mod()​ and ​floor()​ functions will be useful. ● As you do this problem, notice the behavior of ​mod()​ when the first input is negative.

Hints: ● Information on using mod in this manner: ○ Khan Academy​ - ​Better Explained

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [hour, min] = citizenWatch(hour,min,minsPassed)

totalMins=hour*60+min;

mins=totalMins+minsPassed;

hour=floor(mins/60);

min=mod(mins,60);

if mins<0

hour=12+hour;

end

if hour>=12

hour=mod(hour,12);

end

end

Add a comment
Know the answer?
Add Answer to:
Function Name: ​citizenWatch Inputs: Extra Credit 1. (double) T​ he current position of the hour hand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT