/*************************************** ***************************************
Calculation by year-code implementation in multiple languages
Author: chinayaosir
QQ: 44633197
Blog http://blog.csdn.net/chinayaosir
**************************************** ****************************************/
1. Implementation of the algorithm for computing zodiac signs (c)
2. Implementation of the algorithm for computing zodiac signs (C ++ LANGUAGE)
3. Implementation of the algorithm for computing zodiac signs (PHP language)
4. Implementation of computing Zodiac algorithm (Java language)
5. Implementation of the algorithm for computing zodiac signs (C # language)
6. Implementation of the algorithm for computing zodiac signs (VB.net)
/*************************************** ***********************************
Chinayaosir uses multiple computer languages to calculate the Zodiac function code by year,
It is a very good method for us to know each language!
I hope to provide a learning and analysis method for the majority of programmers, TKs!
The idea of computing the Zodiac Algorithm in different languages is that chinayaosir thought of it on the evening of 11/09/2007!
/*************************************** **********************************/
1. Implementation of the algorithm for computing zodiac signs (c)
// Filename calxx. C compiled through VC ++ 6.0
# Include <stdio. h>
Char * calxs (INT year ){
Int I = year % 12;
Char * name [12] = {"monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger", "rabbit ", "Dragon", "snake", "horse", "goat "};
Return name [I];
}
Int main (){
Int birth = 300;
Printf ("Year of birth :");
Scanf ("% d", & birth );
Printf ("% d: % s \ n", birth, calxs (birth ));
Return 0;
}
---------------------------------------------------------------------------
2. Implementation of the algorithm for computing zodiac signs (C ++ LANGUAGE)
// Filename calxx. cpp compiled through VC ++ 6.0
# Include <string>
# Include <iostream>
Using namespace STD;
String calxs (INT year ){
Int xx = year % 12;
String name [12] = {"monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger", "rabbit ", "Dragon", "snake", "horse", "goat "};
Return name [XX];
}
Int main (INT argc, char * argv []) {
Int Birthday = 3000;
Cout <"birthdate [3000]:";
Cin> birthday;
Cout <Endl <birthday <"the Chinese zodiac Of The Year is:" <calxs (birthday) <"\ n ";
Return 0;
}
---------------------------------------------------------------------------
3. Implementation of the algorithm for computing zodiac signs (PHP language)
3.1 main program index. php
<! -- File name is index. php -->
<! -- Edit tools is Dreamweaver 8.0 -->
<! -- Test OK in Windows + Apache + MySQL + PhP running environment -->
<HTML> <Title> calculate the Zodiac year </title>
</Head>
<Body>
<Form action = "calxs. php" method = "Post">
<Table border = "1" align = "center" bordercolor = "#000066" bgcolor = "#66cc66">
<Tr bgcolor = "#666666" type = "codeph" text = "/codeph">
& Lt; TD width = "128" bgcolor = "# ffcccc" & gt;
<Div align = "center"> year calculation Zodiac </div> </TD>
<TD width = "80" bgcolor = "# ffcccc"> <Div align = "center"> input year </div> </TD>
<TD align = "center"> <input name = "birth" type = "text" value = "2000" size = "8" maxlength = "4"/> </TD>
<TD colspan = "2"> <input type = "Submit" name = "Submit" value = "computing"/> </TD>
</Tr>
</Table>
</Form>
</Body>
</Html>
3.2 processing program calxs. php
<! -- File name is calxs. php -->
<? Phpfunction calxs ($ Y ){
$ Name = array ('Monkey ', 'chicken', 'Dog', 'pig', 'rat ', 'ox', 'tiger ', 'rabbit ', 'long', 'snake ', 'Ma', 'yang ');
$ I = $ Y % 12;
Return $ name [$ I];
}
$ Birthyear = $ _ post ['birth'];
Calxs ($ birthyear );
Echo $ birthyear. 'The Zodiac Of The Year is: '. calxs ($ birthyear).' </BR> ';?>
---------------------------------------------------------------------------
4. Implementation of the algorithm for computing zodiac signs (Java language)
// File name is ABC. Java
// Compile javac ABC. Java
// Call Java ABC 2007.
// Result: the year number is read as a parameter in Java ABC 2007 on the command line. The result is pig.
// Development Environment: j2sdk1.4.2 + editplus
// Chinese zodiac
Calxsclass calxs {
Private string name [] = new string [12];
Private int year;
Private string Xs;
// Constructor initialization data
Public calxs (){
Name [0] = "monkey"; name [1] = "chicken"; name [2] = "dog ";
Name [3] = "pig"; name [4] = "rat"; name [5] = "Ox ";
Name [6] = "tiger"; name [7] = "rabbit"; name [8] = "dragon ";
Name [9] = "snake"; name [10] = "horse"; name [11] = "goat ";
Xs = ""; year = 3000;
}
// Obtain the year method readyear ()
Public void setyear (INT y) {year = y ;}
// Method for converting year to zodiac sign CAL ()
Public void CAL () {int y; y = year % 12; xs = Name [y];}
// Print ()
Public void print () {system. Out. println (Year + "year's zodiac:" + XS );}}
// Call the main Class ABC of the Zodiac class calxs, including the main method
Class ABC {
Public static void main (string ARGs []) {
Int year = 2000;
Year = integer. parseint (ARGs [0]);
Calxs A = new calxs ();
A. setyear (year );
A. CAL ();
A. Print ();
}
}
---------------------------------------------------------------------------
5. Implementation of the algorithm for computing zodiac signs (C # language)
// Filename calxs. CS
Using system;
Namespace consoleapplication1 {
Class program {
Static void main (string [] ARGs ){
Console. Write ("Year of birth :");
Int birth = 2010;
Birth = int. parse (console. Readline ());
Console. writeline (birth + "the year's zodiac is:" + calxs (birth ));
Console. Readline ();
}
Static Public String calxs (INT year ){
Int I = year % 12;
String [] Name = {"monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger", "rabbit ", "Dragon", "snake", "horse", "goat "};
Return name [I];
}
}
}
---------------------------------------------------------------------------
6. Implementation of the algorithm for computing zodiac signs (VB.net)
// Filename module1.vb
Imports system
Module module1
Sub main ()
Dim birth as integer
Dim sbirth as string
Console. Write ("Year of birth :")
Sbirth = console. Readline ()
Birth = CINT (sbirth)
Console. writeline (sbirth + "the Zodiac Of The Year is:" + calxs (birth ))
Console. Readline ()
End sub
Public Function calxs (byval year as integer) as string
Dim I as integer = CINT (Year mod 12)
Dim name as string () = {"monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger", "rabbit ", "Dragon", "snake", "horse", "goat "}
Return name (I)
End Function
End Module
---------------------------------------------------------------------------