Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please! Chinese Zodiac assigns an animal and its reputed attributes to each year in a repeating 12-year cycle . It is known that

In C++ please!

Chinese Zodiac assigns an animal and its reputed attributes to each year in a repeating 12-year cycle. It is known that 2008 is a Rat year, followed by Ox (2009), Tiger(2010), Rabbit(2011), Dragon(2012), Snake(2013), Horse(2014), Sheep(2015), Monkey(2016), Rooster(2017), Dog(2018), Pig (2019). Write a program that takes a positive integer from the user as the input and outputs what Chinese Zodiac year it corresponds to. For instance, if the user inputs 2009, the program will output

2009 is an Ox year. 

If the user inputs 1976, the program will output

1976 is a Dragon year. 

If the input is not a positive integer, the program will output "Invalid year" and exit.

Hint: Since the Chinese Zodiac has a repeating 12-year cycle, and we know the 12 animal signs from 2008 to 2019, we can use 2008 as the baseline year. If the user inputs a year that is 2008 or later, we can use (input_year-2008)%12 to determine which animal sign that year corresponds to. That is, if that calculation returns 0, it corresponds to the Rat year; if it returns 1, it corresponds to the Ox year; if it returns 11, it corresponds to the Pig year.

However, if the user inputs a year that is 2007 or earlier, the search of its corresponding animal sign using the reference years 2008-2019 is from back to front. That is, if the calculation of (2008-input_year)%12 returns 0, it corresponds to the Rat year, if it returns 1, it corresponds to the Pig year not Ox year! If it returns 2, it corresponds to the Dog year; if it returns 3, it corresponds to the Rooster year; if it returns 11, it corresponds to the Ox year.

Any attempt to hard code answers will result in a 0 for the exercise.

image text in transcribed

Chinese Zodiac assigns an animal and its reputed attributes to each year in a repeating 12-year cycle. It is known that 2008 is a Rat year, followed by Ox (2009), Tiger(2010), Rabbit(2011), Dragon(2012), Snake(2013), Horse(2014), Sheep(2015), Monkey(2016), Rooster (2017), Dog(2018), Pig (2019). Write a program that takes a positive integer from the user as the input and outputs what Chinese Zodiac year it corresponds to. For instance, if the user inputs 2009, the program will output 2009 is an Ox year. If the user inputs 1976, the program will output 1976 is a Dragon year. If the input is not a positive integer, the program will output "Invalid year" and exit. Hint: Since the Chinese Zodiac has a repeating 12-year cycle, and we know the 12 animal signs from 2008 to 2019, we can use 2008 as the baseline year. If the user inputs a year that is 2008 or later, we can use (input_year-2008)%12 to determine which animal sign that year corresponds to. That is, if that calculation returns 0, it corresponds to the Rat year, if it returns 1, it corresponds to the Ox year, ... if it returns 11, it corresponds to the Pig year. However, if the user inputs a year that is 2007 or earlier, the search of its corresponding animal sign using the reference years 2008-2019 is from back to front. That is, if the calculation of (2008-input_year)%12 retu 0, it corresponds to the Rat year, if it returns 1, it corresponds to the Pig year not Ox year! If it returns 2, it corresponds to the Dog year; if it returns 3, it corresponds to the Rooster year, ... if it returns 11, it corresponds to the Ox year. Any attempt to hard code answers will result in a 0 for the exercise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions