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

.11 T-Mobile 9:09 AM @* 95% Lab Assignment 3 S17-Chinese Zoc ] Open with Print C

ID: 3586221 • Letter: #

Question

.11 T-Mobile 9:09 AM @* 95% Lab Assignment 3 S17-Chinese Zoc ] Open with Print CSCI 251 Problem Statement The Chinese Zodiac is based on a tweve-year cycle, with each year represented by an animal: monkey rooster, pg rat, ar tiger, tatbitdeagon, snake, horse, or sheep By taking the modulus of the year, you can debermine which animal corresponds to that year animal-year mod 12 0: monkey 2 dog & pig T: rabbin 9 snake 11: shc For example, the year 1900 is the year of the Rat since (1900 mod 12) 4 The Chinese New Year, however, is based on alunar cycle and is not the same day each year. Typically the new year sometime in February. So, using the above example, i the date was January 1900, the year would be the Pig M the date, however, was February through December, it would be the year of the Rat Write a program tht prompts for the month and year. Using a switch statement, output the Chinese codiac animal (Assume January is the previous year's animal. Allother months are that years animal). Input Data "year Output Data . The Chinese zodiac animal Before You Begin 1 Start MATLAB (Start> All Programs MATLAB R2013a) and change your Cwrent Folder to the location of your hard drive (e g.K/MATLAB programs/) If you forget to do this, your MATLAB programs will not be accessible whenever the computers in this lab are cleared, which throughout the semester 2. In the Command Window, type edit ChineseZodiac.m MATLAB should prompt that the file does not cumently exist select OK so MATLAB will create the ile in your Curment Folder Starting File Include header comments ie at the beginning of your fle) formatted as show below. Your electronic submisson of program file w represent your endorsement ofthe Honor Code Statement. % csci 251, Sector, x %lntoep ng with the Honor Code of he School of Engreenrg. I have nether %given nor assistance from he instructo

Explanation / Answer

PLEASE REFER BELOW CODE

clear all
clc

prompt ='Enter the month and year (mm/yyyy):'; %Taking user input
n = input(prompt,'s'); %taking input as string
C = strsplit(n,'/'); %split string using /
mm = str2num(C{[ 1]}); %first splitted string
yyyy = str2num(C{[ 2]}); %second splitted string

%switch for month
switch mm
case 1
month = "Jaunary";
case 2
month = "February";
case 3
month = "March";
case 4
month = "April";
case 5
month = "May";
case 6
month = "June";
case 7
month = "July";
case 8
month = "August";
case 9
month = "September";
case 10
month = "October";
case 11
month = "November";
case 12
month = "December";
otherwise
month = "Invalid Month";
end
animal = mod(yyyy,12);

%If month is Jaunary
if mm == 1
animal = mod(yyyy-1,12);
end

%switch for animal
switch animal
case 0
anim_out = "Monkey";
case 1
anim_out = "Rooster";
case 2
anim_out = "Dog";
case 3
anim_out = "Pig";
case 4
anim_out = "Rat";
case 5
anim_out = "Ox";
case 6
anim_out = "Tiger";
case 7
anim_out = "Rabbit";
case 8
anim_out = "Dragon";
case 9
anim_out = "Snake";
case 10
anim_out = "Horse";
case 11
anim_out = "Sheep";
otherwise
anim_out = "Invalid animal";
end
%printing output
fprintf("%s %d is the year of the %s ", month,yyyy,anim_out);

PLEASE REFER BELOW OUTPUT

1)

Enter the month and year (mm/yyyy):02/2020
February 2020 is the year of the Rat
>>

2)

Enter the month and year (mm/yyyy):01/2020
Jaunary 2020 is the year of the Pig
>>

3)

Enter the month and year (mm/yyyy):08/2015
August 2015 is the year of the Sheep
>>

4)

Enter the month and year (mm/yyyy):01/2015
Jaunary 2015 is the year of the Horse
>>