CSCI1120 Assignment 1: Stems and Branches Solved

30.00 $

Category:

Description

5/5 - (2 votes)

Introduction

This assignment allows you to become familiar with Visual Studio Community 2017. (Details on using Visual Studio will be covered in Tutorial 1.) You will write a simple program on the topic of Stems-andBranches (干支; 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 Ten 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 Twelve Earthly Branches

Branch Number 1 2 3 4 5 6 7 8 9 10 11 12
Chinese Character
Cantonese Romanizatio n ji2 chau

2

yan

4

maau

5

san

4

ji6 ng

5

mei

6

san

1

yau

5

seut 1 hoi 6

 

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 甲子. 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 2018 is called a 戊戌 year (S5-B11). The next year 2019 is 己亥 (S6-B12), and so on. Similarly, the cycle can indicate dates. For example, 31/8/2018 is called a 乙未 day (S2-B8). The next day 1/9/2018 is called a 丙申 day (S3-B9), 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:

Note that  is the modulo operation. For example, .

Example: year 2013

. As , we set  instead.

.

Thus, year 2013 is S10-B6 (癸巳).

Converting from Western Dates to Cyclic Dates

Note that  means the floor of , that is, the largest integer not greater than . For example,

.

Example: date 4/9/2018

 

𝑝𝑑 = 186 mod 10 = 6

𝑞𝑑 = 276 mod 12 = 0 As 𝑞𝑑 = 0, we set 𝑞𝑑 = 12 instead. Thus, 4/9/2018 is a S6-B12 day (己亥).

Program Specification

The program should 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 methods to compute the cyclic year and cyclic dates of the input, and print out the result.

Program Output

The following shows some sample output of the program. The blue text is user input and the other text is the program output. You can try the provided sample program for other input. Your program output should be exactly the same as the sample program (i.e., same text, same symbols, same letter case, same number of spaces, etc.). Otherwise, it will be considered as wrong, even if you have computed the correct result.

Enter a date (D M Y): 4 9 2018↵

Year:  S5-B11 Month: 9

Day:   S6-B12

 

Enter a date (D M Y): 14 2 2013↵

Year:  S10-B6 Month: 2

Day:   S8-B12

 

  • assg1.zip