Difference between revisions of "PHP test"

From Nick Jenkins
Jump to: navigation, search
(add PHP test.)
 
m (move circle question to be first, to get people started.)
 
Line 5: Line 5:
  
 
<pre>
 
<pre>
/**
 
* Write a function that returns a boolean to indicate whether a string starts with an upper-case letter A-Z
 
* 写一个函数,判断一个字符串首字母是否以大写字母A-Z开头。
 
* @param string $str
 
* @return boolean Whether string starts with an upper-case letter A-Z
 
*/
 
function startsWithUpper( $str ) {
 
    // --- Your code here ---
 
}
 
 
 
 
/**
 
/**
 
  * Write a function that returns the area of a circle, given the radius.
 
  * Write a function that returns the area of a circle, given the radius.
Line 24: Line 13:
 
function areaOfCircle( $radius ) {
 
function areaOfCircle( $radius ) {
 
     // --- Your code here ---
 
     // --- Your code here ---
 +
}
 +
 +
 +
/**
 +
* Write a function that returns a boolean to indicate whether a string starts with an upper-case letter A-Z
 +
* 写一个函数,判断一个字符串首字母是否以大写字母A-Z开头。
 +
* @param string $str
 +
* @return boolean Whether string starts with an upper-case letter A-Z
 +
*/
 +
function startsWithUpper( $str ) {
 +
    // --- Your code here ---
 
}
 
}
  
Line 67: Line 67:
  
 
// You are given this sample code:  
 
// You are given this sample code:  
//给出一些代码(例子)
+
// 给出一些代码(例子)
 
$a = new A();
 
$a = new A();
 
$a->addNumber( 3 );
 
$a->addNumber( 3 );

Latest revision as of 06:17, 19 September 2007

Instructions:

  • Please complete the following test, and email us your answers. Do not add your answers to this web page.
  • Please do not change any function names, or add new function parameters.
  • If possible, please include any comments in both Chinese and English, if at all possible.
/**
 * Write a function that returns the area of a circle, given the radius.
 * 写一个函数,判断一个给定半径的圆的面积。
 * @param integer $radius
 * @return integer Area of the circle.
 */
function areaOfCircle( $radius ) {
     // --- Your code here ---
}


/**
 * Write a function that returns a boolean to indicate whether a string starts with an upper-case letter A-Z
 * 写一个函数,判断一个字符串首字母是否以大写字母A-Z开头。
 * @param string $str
 * @return boolean Whether string starts with an upper-case letter A-Z
 */
function startsWithUpper( $str ) { 
    // --- Your code here ---
}


/**
 * Write a function to add up all the values in a 1-dimensional array of numbers, and return the result.
 * 给一个数值型数组添加值(成员)
 * @param array $array A 1-dimensional array of numbers.
 * @return integer sum of array's values.
 */
function addValuesInArray( $array ) {
     // --- Your code here ---
}


/**
 * Write a recursive function to multiply all the values in an array of numbers, and return the result.
 * 写一个递归函数,用来遍历一个数值型数组中的所有值(成员)
 * @param array $array A 1-dimensional array of numbers.
 * @return integer result of multiplying all the array's values together.
 */
function recursiveArrayMultiply( $array ) {
     // --- Your code here ---
}


/**
 * Please correct any bugs in the following function, or its definition.
 * 在下边的函数中是否有小bug,如果有,是什么bug? 
 *
 * Determines whether the string contains a certain character.
 * @param char $char A single character 
 * @param string $string A string of characters (is not modified).
 * @return boolean True if the string contains the specified character. 
 */
function stringContainsChar( $char, & $string ) {
   for( $i=1; $i<=strlen( $string ); $i++) { 
       if( $string[$i] = $char ) return true;
   }
   return 'false';
}


// You are given this sample code: 
// 给出一些代码(例子)
$a = new A();
$a->addNumber( 3 );
$a->addNumber( 5 );
print $a->getNumber() . "\n"; // prints "8\n";
// From the above code, write an implementation of class A. 
// 从上边的代码开始,写一个完整的类A.


/**
 * Create a web page that:
 *  - Displays a list of countries in alphabetical order.
 *  - Allows countries to be removed from the list.
 *  - Allows new countries to be added to the list.
 * The list of countries should be stored in a text file, called "countries.txt" ,
 * in the same directory as your PHP script, and each line of the file should 
 * correspond to one country. An example countries.txt file is shown in the 5 lines below.
 */
United States
Australia
Serbia
Canada 
China