建一个公司网站多少钱,上海公司排名大全,石家庄的建筑公司,摄影网站免费实 验 目 的 掌握索引和关联数组#xff0c;以及下标和元素概念#xff1b; 掌握数组创建、初始化#xff0c;以及元素添加、删除、修改操作#xff1b; 掌握foreach作用、语法、执行过程和使用#xff1b; 能应用数组输出表格和数据。
任务1#xff1a;使用一维索引数… 实 验 目 的 掌握索引和关联数组以及下标和元素概念 掌握数组创建、初始化以及元素添加、删除、修改操作 掌握foreach作用、语法、执行过程和使用 能应用数组输出表格和数据。
任务1使用一维索引数组存储医生年龄(随机生成一组年龄数组年龄范围为22-60)使用foreach找出最大年龄、最小龄算出平均年龄。
任务2使用二维关联数组描述下表学生信息并用表格输出学生信息要求算出单科平均成绩。扩展选做借助数组函数分别按单科成绩从高到低排序。 姓名 英语成绩 数学成绩 语文成绩 张三 78 99 87 李四 88 88 79 老五 65 90 93 平均成绩 77 ? ?
任务一先搭建首页的页面 !DOCTYPE html
html langenheadmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/titlestyle* {margin: 0;padding: 0;box-sizing: border-box;}.box {width: 800px;height: 200px;background-color: #e4dfdf;margin: 100px auto;padding-top: 15px;}.box h1 {text-align: center;font-weight: 400;}.box .num {width: 400px;height: 50px;}form {margin-top: 55px;font-size: 22px;}/style
/headbodydiv classboxh1求医生年龄的最值/h1form actiondoctor_ages.php请输入您要生成的多少位医生的年龄input typenumber namenumber classnum/form/br/form/div
/body/html
首页页面是给用户去生成多少位医生的年龄。 生成了多少位医生的年龄后去求医生的最大年龄和最小年龄和平均年龄。
实验步骤
?php$Dnumber $_REQUEST[number];
Calculate($Dnumber);function Calculate($n){//创建一个年龄数组$ages array();for($i0;$i$n;$i){$ages[$i] rand(20,60);}echo 生成的数组是:;for($i0;$i$n;$i){if($i($n-1)){echo $ages[$i]. ;}else {echo $ages[$i] . , ;}}echo /br;$AgeMax $ages[0];$AgeMin $ages[0];$AgeSum0;for($i0;$i$n;$i){if($ages[$i]$AgeMax){$AgeMax$ages[$i];}if($ages[$i]$AgeMin){$AgeMin$ages[$i];}$AgeSum$AgeSum$ages[$i];} echo 医生的最大年龄是.$AgeMax./br;echo 医生的最小年龄是.$AgeMin./br;echo 医生的平均年龄.round($AgeSum/count($ages),2);}
?
任务二 使用HTMLCSS搭建琦基础页面
!DOCTYPE html
htmlhead meta charsetutf-8 title菜鸟教程(runoob.com)/title link relstylesheet hrefhttps://cdn.staticfile.net/twitter-bootstrap/3.3.7/css/bootstrap.min.cssscript srchttps://cdn.staticfile.net/jquery/2.1.1/jquery.min.js/scriptscript srchttps://cdn.staticfile.net/twitter-bootstrap/3.3.7/js/bootstrap.min.js/scriptstyleh1 {text-align: center;}table {margin: 0 auto;}tr h2 {margin-left: 20px;}form input {width: 70%;height: 40px;margin-bottom: 5px;border-radius: 10px;}form label {padding-left: 20px;}form button {background-color: #5bc0de;border-color: #46b8da;display: inline-block;padding: 6px 12px;margin-bottom: 0;font-size: 18px;font-weight: 400;line-height: 1.42857143;text-align: center;white-space: nowrap;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-image: none;border-radius: 4px;margin-left: 90px;margin-top: 10px;width: 69%;}form button a {color: #fff;}form button a:hover {color: #18f508;text-decoration: none;}/style
/headbodytable width80% border0trtd colspan2 stylebackground-color:#FFA500;h1学生成绩查询/h1/td/trtrtd stylebackground-color:#FFD700;width:200px;vertical-align:top;h2添加学生成绩信息/h2form methodget actionlabel forname学生 姓名:/labelinput typetext idname namename placeholder姓名brlabel forenglishScore英语 成绩:/labelinput typenumber idenglishScore nameenglishScore min0 max100 placeholder英语成绩brlabel formathScore数学 成绩:/labelinput typenumber idmathScore namemathScore min0 max100 placeholder数学成绩brlabel forchineseScore语文 成绩:/labelinput typenumber idchineseScore namechineseScore min0 max100 placeholder语文成绩brbutton typesubmit namesubmita href添nbsp;nbsp;nbsp;加/a/buttonh2删除学生成绩信息/h2label forname学生 姓名:/labelinput typetext idname namedname placeholder姓名brbutton typesubmit namedsubmita href删nbsp;nbsp;nbsp;除/a/button/form/td
完整的代码
!DOCTYPE html
htmlhead meta charsetutf-8 title菜鸟教程(runoob.com)/title link relstylesheet hrefhttps://cdn.staticfile.net/twitter-bootstrap/3.3.7/css/bootstrap.min.cssscript srchttps://cdn.staticfile.net/jquery/2.1.1/jquery.min.js/scriptscript srchttps://cdn.staticfile.net/twitter-bootstrap/3.3.7/js/bootstrap.min.js/scriptstyleh1 {text-align: center;}table {margin: 0 auto;}tr h2 {margin-left: 20px;}form input {width: 70%;height: 40px;margin-bottom: 5px;border-radius: 10px;}form label {padding-left: 20px;}form button {background-color: #5bc0de;border-color: #46b8da;display: inline-block;padding: 6px 12px;margin-bottom: 0;font-size: 18px;font-weight: 400;line-height: 1.42857143;text-align: center;white-space: nowrap;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-image: none;border-radius: 4px;margin-left: 90px;margin-top: 10px;width: 69%;}form button a {color: #fff;}form button a:hover {color: #18f508;text-decoration: none;}/style
/headbodytable width80% border0trtd colspan2 stylebackground-color:#FFA500;h1学生成绩查询/h1/td/trtrtd stylebackground-color:#FFD700;width:200px;vertical-align:top;h2添加学生成绩信息/h2form methodget actionlabel forname学生 姓名:/labelinput typetext idname namename placeholder姓名brlabel forenglishScore英语 成绩:/labelinput typenumber idenglishScore nameenglishScore min0 max100 placeholder英语成绩brlabel formathScore数学 成绩:/labelinput typenumber idmathScore namemathScore min0 max100 placeholder数学成绩brlabel forchineseScore语文 成绩:/labelinput typenumber idchineseScore namechineseScore min0 max100 placeholder语文成绩brbutton typesubmit namesubmita href添nbsp;nbsp;nbsp;加/a/buttonh2删除学生成绩信息/h2label forname学生 姓名:/labelinput typetext idname namedname placeholder姓名brbutton typesubmit namedsubmita href删nbsp;nbsp;nbsp;除/a/button/form/tdtd stylebackground-color:#eeeeee;height:550px;width:300px;vertical-align:top;padding-left:15px?php//二维数组$student array(张三 array(英语成绩 78, 数学成绩 99, 语文成绩 87),李四 array(英语成绩 88, 数学成绩 88, 语文成绩 79),王五 array(英语成绩 65, 数学成绩 90, 语文成绩 93));//平均值和最大值初始$average [英语成绩 0, 数学成绩 0, 语文成绩 0];$maxvalue [英语成绩 0, 数学成绩 0, 语文成绩 0];//添加修改用的button标签判断是否nullif (isset($_REQUEST[submit])) {//获取数据$name $_REQUEST[name];$englishScore $_REQUEST[englishScore];$chineseScore $_REQUEST[chineseScore];$mathScore $_REQUEST[mathScore];//判断数组中是否存在该键if (array_key_exists($name, $student)) {//存在提示echo 修改成功;} else {//不存在提示echo 添加成功!;}//存在替换不存在添加$student[$name] array(语文成绩 $chineseScore,数学成绩 $mathScore,英语成绩 $englishScore);}//删除if (isset($_REQUEST[dsubmit])) {//获取数据$name $_REQUEST[dname];//判断是否有键if (array_key_exists($name, $student)) {unset($student[$name]);echo 删除成功;} else {echo 没有该学生!;}}//遍历数组if ($student) {echo h2信息/h2;echo table border1;echo trth width150px姓名/thth width150px英语 成绩/thth width150px数学 成绩/thth width150px语文 成绩/th/tr;foreach ($student as $name $subjects) {//平均值先求和$average[英语成绩] $subjects[英语成绩];$average[数学成绩] $subjects[数学成绩];$average[语文成绩] $subjects[语文成绩];echo tr;echo td . $name . /td;//找出单科最高成绩foreach ($subjects as $subject $score) {if ($score $maxvalue[$subject]) {$maxvalue[$subject] $score;}echo td . $score . /td;}echo /tr;}//平均成绩求和结果除个数$average[英语成绩] / count($student);$average[数学成绩] / count($student);$average[语文成绩] / count($student);//取整数$average[英语成绩] round($average[英语成绩], 0);$average[数学成绩] round($average[数学成绩], 0);$average[语文成绩] round($average[语文成绩], 0);echo tr;echo td . 平均 . \n . /td . td . $average[英语成绩] . \n . /td . td . $average[数学成绩] . \n . /td . td . $average[语文成绩];echo /tr;echo tr;echo td . 单科最高成绩 . /td . td . $maxvalue[英语成绩] . /td . td . $maxvalue[数学成绩] . /td . td . $maxvalue[语文成绩] . /td;echo /tr;echo /table;}//运用数组函数排序rsort($student[张三]);rsort($student[李四]);rsort($student[王五]);echo br;echo 张三成绩降序排序;foreach ($student[张三] as $va) {echo \n . $va;}// echo 张三成绩排序.$student[张三][0].\n.$student[张三][1].\n.$student[张三][2];echo br;echo 李四成绩降序排序;foreach ($student[李四] as $va) {echo \n . $va;}echo br;echo 王五成绩降序排序;foreach ($student[王五] as $va) {echo \n . $va;}?/td/tr/table/body/html 注意本实验是笔者在校老师布置的任务。