CSCI1120 Assignment 1: Stems and Branches solved

$30.00

Category: Tags: , , , , , , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (1 vote)

Introduction

The objective of this assignment is to: (1) become familiar with Visual Studio Community 2022, and (2)
learn how to use variables, operators, expressions, and console input/output.

You will write a simple
program on the topic of Stems-and-Branches (干支; Cantonese romanization gon1
-ji1
).
Stems-and-Branches, a.k.a. sexagenary cycle, is a cycle of sixty terms used for indicating dates, years,
etc. in ancient China.

Each term in the cycle consists of two Chinese characters: the first is called a
Heavenly Stem (天干; Cantonese romanization tin1
-gon1
) and the second is called an Earthly Branch
(地支; Cantonese romanization dei6
-ji1
).

Heavenly Stem can have 10 possibilities, while Earthly Branch
can have 12 possibilities. Tables 1 and 2 show the characters for the 10 stems and 12 branches
respectively.

Table 1: The 10 Heavenly Stems
Stem
Number 1 2 3 4 5 6 7 8 9 10
Chinese
Character 甲 乙 丙 丁 戊 己 庚 辛 壬 癸
Cantonese
Romanization gaap3 yut3 bing2 ding1 mou6 gei2 gang1 san1 yam4 gwai3
Table 2: The 12 Earthly Branches
Branch
Number 1 2 3 4 5 6 7 8 9 10 11 12
Chinese
Character 子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
Cantonese
Romanization ji2 chau2 yan4 maau5 san4 ji6 ng5 mei6 san1 yau5 seut1 hoi6

The first term in the sexagenary cycle is called 甲子 which combines the first stem and the first branch.
The second term in the cycle is called 乙丑 which combines the second stem and the second branch.

This pattern continues as 甲子, 乙丑, 丙寅, 丁卯, 戊辰, 己巳, 庚午, 辛未, 壬申, 癸酉, 甲戌, 乙亥, 丙
子, 丁丑, …, until it concludes at the 60th term 癸亥. After that, the cycle begins again at 甲子. If you
have interest to visualize the combinations in a circular chart format, you may visit this page.

In this
assignment, for the convenience of those unfamiliar with Chinese characters, we use the notation “S�-
B�” to denote a term in the sexagenary cycle, where � and � are the stem number and branch number
respectively. For example, S8-B12 means 辛亥.

The sexagenary cycle can be used for indicating years. For example, year 2022 is called a 壬寅 year
(S9-B3). The next year 2023 is 癸卯 (S10-B4), and so on. Similarly, the cycle can indicate dates. For
example, 31/8/2022 is called a 丙辰 day (S3-B5). The next day 1/9/2022 is called a 丁巳 day (S4-B6),
and so on. (Obviously, using this method of numbering years and dates is not unique, because the
cycle contains 60 terms only. But this method plays an important role in Chinese fortune telling.)

In
this assignment, you will write a program to convert a Western date into sexagenary dates. The
conversion method is stated below.

Converting from Western Years to Cyclic Years
Given a Western year �, its stem number �! and branch number �! can be computed as follows:
�! = (� − 3) mod 10 (However, if �! = 0, then set �! = 10 instead.)
�! = (� − 3) mod 12 (However, if �! = 0, then set �! = 12 instead.)

Note that mod is the modulo operation. For example, 7 mod 3 = 1.
Example: year 2013
�! = (2013 − 3) mod 10 = 2010 mod 10 = 0. As �! = 0, we set �! = 10 instead.
�! = (2013 − 3) mod 12 = 2010 mod 12 = 6.

Thus, year 2013 is S10-B6 (癸巳).
Converting from Western Dates to Cyclic Dates
Given a Western date �/�/�, its stem number �” and branch number �” can be computed as follows:
� = 5
� − 1, � ≤ 2
�, � > 2
� = 5
� + 12, � ≤ 2
�, � > 2
� = < �
100=
� = � mod 100
� = 4� + <

4
= + 5� + B

4
C + <
3(� + 1)
5 = + � − 3
� = E
6, � is odd
0, � is even
� = 8� + <

4
= + 5� + B

4
C + <
3(� + 1)
5 = + � + 1 + �
�” = � mod 10 (However, if �” = 0, then set �” = 10 instead.)
�” = � mod 12 (However, if �” = 0, then set �” = 12 instead.)

Note that ⌊�⌋ means the floor of �, that is, the largest integer not greater than �. For example, ⌊3.2⌋ =
⌊3.98⌋ = 3.
Example: date 7/9/2022
� = 2022
� = 9
� = <
2022
100 = = 20
� = 2022 mod 100 = 22
� = 4 × 20 + <
20
4 = + 5 × 22 + <
22
4 = + <
3 × (9 + 1)
5 = + 7 − 3 = 210
� = 6
� = 8 × 20 + <
20
4 = + 5 × 22 + <
22
4 = + <
3 × (9 + 1)
5 = + 7 + 1 + 6 = 300

�” = 210 mod 10 = 0 As �” = 0, we set �” = 10 instead.
�” = 300 mod 12 = 0 As �” = 0, we set �” = 12 instead.
Thus, 7/9/2022 is a S10-B12 day (癸亥).

Program Specification

The program shall obtain three integers as user input, which represents a date. You do not have to
validate the inputs. (That is, we assume that all inputs are always valid dates.) Then you apply the
above method to compute the cyclic year and cyclic dates of the input, and print the result.
Note: you may use any function in the C++ standard library if you see fit.

Sample Run
In the following sample runs, the blue text is user input and the other text is the program printout.

You can try the provided sample program for other input. Your program output should be exactly the
same as what the sample program produces(same text, symbols, letter case, spacings, etc.). Note that
there is a trailing space after the ‘:’ symbol in the user prompt text “Enter a date (D M Y): ”.

Enter a date (D M Y): 7 9 2022↵
Year: S9-B3
Month: 9
Day: S10-B12
Enter a date (D M Y): 14 2 2013↵
Year: S10-B6
Month: 2
Day: S8-B12
Enter a date (D M Y): 25 12 2046↵
Year: S3-B3
Month: 12
Day: S5-B7

Submission and Marking
§ Your program file name should be stembranch.cpp. Submit the file in Blackboard
(https://blackboard.cuhk.edu.hk/).

§ Insert your name, student ID, and e-mail as comments at the beginning of your source file.
§ You can submit your assignment multiple times. Only the latest submission counts.

§ Your program should be free of compilation errors and warnings.

§ Your program should include suitable comments as documentation.

§ Do NOT plagiarize. Sending your work to others is subject to the same penalty for copying work.