rsandlas Posted May 3, 2010 Share Posted May 3, 2010 User Requirements Input: user's choice of greeting tree type. You are required to provide the following three types: Holiday, Sac State, Surprise. You may implement them using Radio Buttons which are used when you want the user to select one of a limited number of choices. Refer to your on-line calculator for use of radio buttons in the program examples. Output: display the greeting tree pattern based on the user's request and a greeting message accordingly. For example, for choice of "holiday greeting tree", the generator display the following pattern with two major colors: red (for 0) and green (for *). 00000000000 00000000000 00000*00000 0000***0000 000*****000 00*******00 0*********0 00000*00000 00000*00000 00000*00000 00000000000 Happy Holidays! For choice of "Sac State", the two major colors are: gold (for 0) and green (for *); and for choice of "surprise", the two major colors can be any two of your favorite colors. Here is an example of greeting tree generator. For choice of color, you may find this site helpful to you to decide which hexadecimal color codes to apply! Extra Credit (30%): collect one more input from the user: size of the greeting tree, an odd integer between 9 and 17 (or other range you can display in full in one screen). This improved one should be able to generate the three different greeting trees in different sizees. Programming Requirements (a) You are required to 2 new user defined functions: 1. function DisplayChar ($type, $char) //display leave color when $char = "*" and background color when $char = "0" //according to the tree type { your function body goes here} 2. function DisplayGreeting ($type) //display greeting of the given tree type {your function body goes here} You may use two PHP files as you did in Part A. One file contains all of the functions, called gt_functions.php and another contains the form and main program, called Greeting_tree.php. For example, we can have the outline like this one for gt_functions.php: <?php # A collection of functions that will be included in Greeting_tree.php function html_begin ($title, $header) {...} function html_end () {...} function DisplayChar ($type, $char) //display leave color when $char = "*" and background color when $char = "0" according to given tree type {...} function DisplayGreeting ($type) //display greeting message according to given tree type {...} ?> (b) You are required to use a two-dimensional array (11x11 in the above example) for greeting tree generator implementation. The following is an outline of Greeting_tree.php: <?php /* Your brief description of this program which may include input, output, requirements, and your design highlights */ include_once("gt_functions.php"); # MAIN-PROGRAM $title = "The Greeting Trees"; html_begin ($title, $title); if ($submit) { if (!$type) { (your user input validation goes here) } else { //set up the data in a 2-dimensional array to mark the background $A =array(array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0"), array("0","0","0","0","0","0","0","0","0","0","0")); //this array A is 11x11, therefore the center of a row is 5 $N = 11; $center = 5; //mark tree leaves for ($i=0; $i < 5; $i++) { for($j= ($center - $i); $j<= ($center + $i); $j++) { $A[$i+2][$j]= "*"; } } //mark tree trunk for ($i = 7; $i < 10; $i++) { $A[$i][$center] = "*"; } //display elements of the array in colors of the tree type for ($i=0; $i< $N; $i++) { for($j=0; $j< $N; $j++) { DisplayChar ($type, $A[$i][$j]); } echo "<BR>"; } DisplayGreeting($type); } } //Form to collect user input: one of the 3 greeting tree types ?> <FORM METHOD="post" ACTION="Greeting_tree.php"> (your form design goes here, a form variable $type will store user's selection to be used in main program) </FORM> <? html_end () ?> Im a beginning Programing student and my teacher is horrible and i cant figure out how to do this....pleas help. If you could keep it keep it the format shown above that would be awesome. i have two files gt_functions.php and greeting_tree.php. so if you could write it out like gt_functions.php .... .... ... greeting_tree.php .... ... ... Thank you soo much!!!! Quote Link to comment Share on other sites More sharing options...
ejaboneta Posted May 3, 2010 Share Posted May 3, 2010 You want us to do your homework? haha... It seems a little more complicated than necessary... i'll take a look and try to decipher this... oh and this should be in the php section. Quote Link to comment Share on other sites More sharing options...
rsandlas Posted May 4, 2010 Author Share Posted May 4, 2010 i kno man this is hw but the teacher isnt fluent in English and doesn't answer any questions correctly...and this is only a beginner class and i have no clue on what to do , I really would appreciate if you could help me... Quote Link to comment Share on other sites More sharing options...
ignace Posted May 4, 2010 Share Posted May 4, 2010 This is a really simple assignment function GenerateTree($size) { $tree = ''; if ($size < 9 || $size > 17) $size = 9; //credit JonnyThunder for ($x = 0; $x < $size; $x++) { $spacer = str_repeat('0', ($size - $x)); $stars = str_repeat('*', ($x*2)+1); $tree .= $spacer . $stars . $spacer . "\n"; } //end credit $spacer = str_repeat('0', ceil($size/2)-1); $tree .= $spacer . '*' . $spacer . "\n"; $tree .= $spacer . '*' . $spacer . "\n"; $tree .= $spacer . '*' . $spacer . "\n"; return $tree; } function DisplayGreeting($type, $size = 9) { $tree = GenerateTree($size); $coloredTree = ''; foreach (str_split($tree) as $char) { $coloredTree .= DisplayChar($type, $char); } return $coloredTree; } function DisplayChar($type, $char) { $colors = array('red', 'gold');//favorites if ($type === 'holiday greeting tree') $colors = array('red', 'green'); if ($type === 'Sac State') $colors = array('gold', 'green'); //if ($type === 'surprise') // default if ($char != 0 && $char != '*') return $char; if ($char == 0) return '<span style="color:'.$colors[0].'">0</span>'; if ($char == '*') return '<span style="color:'.$colors[1].'">*</span>'; } Seems like you will be the only one who gets that extra 30% Quote Link to comment Share on other sites More sharing options...
trq Posted May 4, 2010 Share Posted May 4, 2010 Seems like you will be the only one who gets that extra 30% Yeah, until the teacher asks him to explain it. Well done. Quote Link to comment Share on other sites More sharing options...
ignace Posted May 4, 2010 Share Posted May 4, 2010 Seems like you will be the only one who gets that extra 30% Yeah, until the teacher asks him to explain it. Well done. Life is full of risks Besides I made his assignment the least he can do is try to figure out how it works quite possibly he got 3 weeks to finish it That will be 3 weeks of healthy studying I am certain this exercise will have taught him more then what his fellow students will have learned over these 3 weeks... It has always worked for me anyway. I have always found that I learned more when I got the solution from the teacher then when I had to actually create it (stack of failures leading to a correct outcome). If I could see the solution, I could find the thought process behind it, and learn from it. This forum is a good example, I have learned a lot from you (thorpe), Daniel, Mchl, and many others, just by looking at their code examples to a given problem. Just look at that code of JonnyThunder (I had to look up the name though), he posted that years ago and I still remembered. Quote Link to comment Share on other sites More sharing options...
rsandlas Posted May 5, 2010 Author Share Posted May 5, 2010 Thank you for all the help but i still do not understand what i am supposed to do. i think you are gonna have to spoon feed it to me . sorry for the inconvenience..... Quote Link to comment Share on other sites More sharing options...
ignace Posted May 5, 2010 Share Posted May 5, 2010 you are gonna have to spoon feed it to me I take my words back thorpe, you were right. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.