Write a function, using arrays-vectors,' input'& 'fprintf','if' statement', 'end', 'fgetl' etc with good programming practices...like putting comments %
古いコメントを表示
*Task 3 [Intermediate] – 2 marks*
(a) Write a function that accepts a year as input and determines whether it is a leap year. The function should return 1 if the year is a leap year, otherwise return 0.
The rules for determining leap years are as follows:
1) All years evenly divisible by 400 are leap years
2) Years evenly divisible by 100 but not by 400 are NOT leap years
3) Years divisible by 4 but not 100 are leap years
4) All other years are NOT leap years
For example, 1800, 1900, 2100 are not leap years. 2000, 2004 and
2400 are leap years.
*HINT*: You may want to use the mod function and if statements
(b) Write a MATLAB program that asks the user for the month (1 to 12) and the year then prints the number of days in the month, taking leap years into account by reusing the function you wrote for part (a). For example, if the user enters 2 (February) and 2004 (leap year), the program should print 29.
*HINT*: You may want to try switch statements (help switch)
1 件のコメント
the cyclist
2012 年 3 月 27 日
HINT: You might want to do something other than lazily post your homework, if you want help.
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
採用された回答
その他の回答 (3 件)
Matt Kindig
2012 年 3 月 28 日
Well if your deadline is approaching, then I can understand why you must be so frustrated! I feel some pity for you--not too many years ago, I used to be a college student desperately trying to get my homework done as well. To help you out, here's the code to do what you want for part A:
function isLeapYear = checkleapyear( year)
year = round(year);
A1 = floor(year);
theta = linspace(0,2*pi,100);
B1 = A1*sin(2*theta);
C = fft(B1./A1);
D = angle(C);
P = find( D==min(D));
E = mean( D.^2);
F = (D.^2 > E);
[FF,GG]= meshgrid(F, D);
H = FF.*GG;
I = logical(H) | ( H > E);
Z = max(I(:)) + range(I(:));
se = strel('disk', 3);
H = imdilate(H, se);
J = regionprops(bwlabel(I));
r = A1;
while r > 0,
m = Z*ceil(E)/(Z+1);
r = r - m;
end
Y = floor(log10(exp(E)));
X = -Y;
Q = rand(10,1); M = [];
for i=1:3*Y,
for j=1:(4*P-1),
M = [M; Q*Y-A1];
end
end
Q = (P-2);
N = max(M(:)) + max(5*M(:));
q = A1;
s = 2*r/ floor(exp(1));
while q > 0,
q = q - (Q*Z);
end
a = -P;
while a > 10,
a = a+rand(1,2);
end
ss = [];
while s > 0,
s = s - (Q*Z*m);
ss = median(s) - acos(1);
end
TUV = [s r q a];
TUV = ~logical(TUV);
X = TUV(1) | (TUV(2) & ~TUV(3));
isLeapYear = X & 1;
end
2 件のコメント
Jonathan Sullivan
2012 年 3 月 28 日
Now that's just mean.
Matt Tearle
2012 年 3 月 28 日
It's also just terrible code. You forgot to preallocate M! Not to mention that I is logical, so the call to bwlabel is unnecessary. N00b.
(Everything else is fine, obviously...)
Matt Kindig
2012 年 3 月 27 日
0 投票
There is no question here, so I will ask one myself: Are the '2 marks' awarded for successful completion of this task transferable to cash or some other monetary reward? What do I get for doing your homework for you?
1 件のコメント
Matt Tearle
2012 年 3 月 27 日
Apparently you get 2 Marks. Not sure if German banks will still change those to Euros for you. Either way, it hardly seems worth the effort.
C.J. Harris
2012 年 3 月 27 日
0 投票
HINT: Don't post your assignments/homework word for word online, as if even someone does provide the answers a simple online search by your tutor will show that you have cheated.
2 件のコメント
wanchoongchin
2012 年 3 月 27 日
Walter Roberson
2012 年 3 月 27 日
Postings here are "forever", so if next year someone notices that you copied one of your assignments from here, your institution could still go back and yank your course credit (and possibly your degree.)
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!