典型教学视频 案例简介 潍坊学院计算机技术实验中心
一 C 语言程序设计 实验六函数基础 一 实验目的 1. 掌握自定义函数的一般结构及定义函数的方法 2. 掌握形参 实参 函数原型等重要概念 3. 掌握函数声明 函数调用的一般方法 二 实验内容及参考程序 1. 求三角形面积函数 编写一个求任意三角形面积的函数, 并在主函数中调用它, 计算任意三角形的面积 参考程序 : #include "math.h" main() float area(float,float,float); float a,b,c; printf("input a,b,c="); scanf("%f,%f,%f",&a,&b,&c); if(a+b>c&&a+c>b&&b+c>a&&a>0.0&&b>0.0&&c>0.0) /* 构成三角形的条件 */ printf("area=%-7.2f\n",area(a,b,c)); float area(float a,float b,float c) float s,area_s; s=(a+b+c)/2.0; area_s=sqrt(s*(s-a)*(s-b)*(s-c)); return(area_s); 2. 求素数函数 ⑴ 编写一个判断素数的函数, 当一个数为素数时, 函数返回值为 1, 否则为 0 ⑵ 在主函数中从键盘任意输入 10 个整数, 求所有的素数和 对素数的判断要求调用上面的素数函数实现 参考程序 : #include "math.h" #define M 10 main() int i,n,s=0; printf("input data:"); for(i=1;i<=m;i++)
scanf("%d",&n); if(prime(n)) s+=n; printf("sum=%d\n",s); int prime(int n) int flag=1,i,sn; sn=sqrt(n); for(i=2;i<=sn;i++) if(n%i==0) flag=0; break; return(flag); n m! 3. 用函数求解组合数问题 已知组合数 : C = m n!( m n)!, 求对于任意 m n 时的值 参考程序 : float fac(int k) int i; float f; for(i=1,f=1;i<=k;i++) f*=i; return(f); float cmn(int m,int n) float res; res=fac(m)/(fac(n)*fac(m-n)); return(res); main() int m,n; float t; printf("m,n="); scanf("%d,%d",&m,&n); t=cmn(m,n); printf("c(%d,%d)=%f\n",m,n,t);
4.( 选做题 ) 猴子吃桃问题的函数化 把猴子吃桃问题写成一个函数, 能够求得指定一天开始时的桃子数 参考程序 : main() int day; printf("peach number asking a which day for help when beginning?\n"); loop:scanf("%d",&day); if(day<1 day>10) goto loop; printf("total=%d\n",monkey(day)); int monkey(int k) int i,m,n; for(n=1,i=1;i<=10-k;i++) m=2*n+2; n=m; return(n); n 5.( 选做题 ) 用递归方法求 : sum( n) = i i= 1 参考程序 : int sum(int n) if(n==1) return(1); else return(sum(n-1)+n); main() int n; scanf("%d",&n); printf("%d\n",sum(n));
二 计算机网络 实验四动态路由协议配置 1 实验目的 (1) 理解动态路由协议在计算机网络通信中所起作用 ; (2) 掌握动态路由协议在路由器中的配置方法 (3) 认识路由表的构成, 并理解各路由表项在不同网段间通信所起的作用 2 实验内容 (1) 讲解路由器串口的作用, 路由器串口之间连线的特点, 了解路由器 DCE 与 DTE 间的配置区别 ; (2) 在 RACK 实验台上搭建网络环境模拟如下场景 : 假设校园网通过一台路由器连接到校园外的另一台路由器上, 实现校园网内部主机与校园网外部主机的相互通信 ; R R Fa1/0 s1/2 s1/2 172.16.1.1/24 172.16.2.1/24 172.16.2.2/24 Fa1/0 172.16.3.1/24 PC1:172.16.1.22/24 PC2:172.16.3.22/24 图 1 网络拓朴图 (3) 选择 RIP V2 作为路由选择协议, 在路由器上做相应配置, 使得校园网内 外部主机可以相互通信 ; (4) 测试主机的连通性, 并记录配置参数与结果 ; (5) 查看并记录路由表内容, 描述每一路由表项的作用 3 实验步骤步骤一 配置路由器 (1) 查看路由器配置 Router1#show ip interface brief! 显示端口配置 Router1#show ip route! 显示路由表 Router2#show ip interface brief Router2#show ip route (2) 路由器基本配置配置 Router1 Router1(config)#interface fastethernet 1/0 Router1(config-if)#ip address 172.16.1.1 255.255.255.0! 进入端口模式! 配置端口 IP 地址
Router1(config-if)#no shutdown Router1(config-if)#exit! 打开端口 Router1(config)#interface serial 1/2 Router1(config-if)#ip address 172.16.2.1 255.255.255.0 Router1(config-if)#clock rate 64000 Router1(config-if)#no shutdown Router1(config-if)#exit! 设置时钟频率 配置 Router2 Router2(config)#interface fastethernet 1/0 Router2(config-if)#ip address 172.16.3.1 255.255.255.0 Router2(config-if)#no shutdown Router2(config-if)#exit Router2(config)#interface serial 1/2 Router2(config-if)#ip address 172.16.2.2 255.255.255.0 Router2(config-if)#no shutdown Router2(config-if)#exit 验证测试 : 验证路由器接口的配置和状态 Router1#show ip interface brief Router2#show ip interface brief (3) 配置 RIP V2 协议 Router1(config)#router rip Router1(config-router) #network 172.16.1.0 Router1(config-router) #network 172.16.2.0 Router1(config-router)#version2 Router1(config-router)#no auto-summary! 开启 RIP 协议进程! 申明本设备的直连网段! 定义 RIP 协议 v2! 关闭路由信息的自动汇总功能 Router2(config)#router rip Router2(config-router) #network 172.16.2.0 Router2(config-router) #network 172.16.3.0 Router2(config-router)#version2 Router2(config-router)#no auto-summary (4) 验证路由表 Router1#show ip route Router2#show ip route! 定义 RIP 协议 v2! 关闭路由信息的自动汇总功能
步骤二 测试 (1) 搭建硬件实验环境, 如图 1 如示. (2) 测试网络的连通性 C:\> ping 172.16.3.22! 从 PC1 ping PC2 [ 注意事项 ] (1) 对于路由器之间串口连接要区分是 DCE 口还是 DTE 口 例如观察 s0 哪种接口, 可以在特权模式下输入命令 :show controller s0 对于 DCE 口要配置时钟 (2) 使用 ip address 配置路由器的 ip 时, 不要忘了子网掩码 (3) 配置路由器接口 (ethernet,fastethernet,serial) 后, 要输入 :Router(config-if)# no shut, 以激活该接口 4 实验要求 (1) 提前预习路由选择 路由选择协议及路由表等相关知识 ; (2) 记录实验数据, 写出实验报告
三 网站建设与管理 实验六 : 使用表单进行交互 一 实验目的 掌握表单集里控件对象的使用方法 运用所学知识能够进行人机交互的界面设计 二 实验内容 用户登录页面的设计 留言板页面设计 客户意见反馈表页面设计 三 实验要求 记录实验中遇到的问题及解决方法 ; 写出实验报告 四 实验过程 1 预习知识 (1) 表单对象 表单按钮 文本域 隐藏域 文本区域 复选框 单选按钮 单选按钮组 列表 / 菜单 跳转菜单 图像域 文件域 按钮 标签 字段集
(2) 表格标签 <table> </table> <tr> <td> </td> 2 实验步骤 (1) 用户登录页面的设计 ( 源码参考 ) <! 主程序 index.htm <html> <head> <title> 用户登录 </title> </head> <body> <form name="form1" method="get" action="p1.asp"> <table width="317" border="1"> <tr> <td width="85"> 用户 :</td> <td width="216"><input name="txtname" type="text" id="txtname"></td> <tr> <td> 密码 </td> <td><input name="txtpsw" type="password" id="txtpsw"></td> <tr> <td colspan="2"><div align="center"> <input type="submit" name="submit" value=" 提交 "> <input type="reset" name="submit" value=" 重置 "> </div></td> </table> </form> </body> </html> <!--** 跳转程序 p1.asp <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title> 无标题文档 </title> </head>
<body> <% x=request("txtname") response.write(" 你的用户名 :",x, "<br>") x=request("txtpsw") response.write(" 你的密码是 :",x) %> </body> </html> (2) 留言板页面设计 ( 源码参考 ) <html> <head> <title> 留言板页面设计 </title> </head> <body> <form action="f1.asp" method="post" enctype="application/x-www-form-urlencoded" name="form1" target="_self"> <table width="481" border="0" cellspacing="1" bgcolor="#ff0000"> <td width="71"> 姓名 </td> <td width="394"><input name="txtname" type="text" id="txtname" value=" 张三 "></td> <td> 性别 </td><td><input name="radsex" type="radio" value="m" checked> 男 <input type="radio" name="radiobutton" value="f"> 女 </td> <td> 电子邮件 </td><td><input name="txtemail" type="text" id="txtemail" onblur="mm_validateform('textfield2','','nisemail');return document.mm_returnvalue" value="abc@163.com"> </td> <td> 联系电话 </td> <td><input name="txttel" type="text" id="txttel" onblur="mm_validateform('textfield','','nisnum');return document.mm_returnvalue" value="05368888888"></td> <td> 爱好 </td> <td><input type="checkbox" name="checkbox" value=" 打游戏 "> 游戏 <input type="checkbox" name="checkbox" value=" 看书 "> 看书 <input type="checkbox" name="checkbox" value=" 出去旅游 "> 旅游 <input type="checkbox" name="checkbox" value=" 外出购物 "> 购物 </td>
<td> 居住城市 </td> <td><select name="select"> <option selected> 北京 </option> <option> 天津 </option> <option> 山东 </option> <option> 吉林 </option> <option> 辽宁 </option> <option> 河北 </option> </select></td> <td> 留言 </td> <td><textarea name="txtly" cols="50" rows="5" id="txtly"></textarea></td> <tr> <td colspan="2"><div align="center"> <input type="submit" name="submit2" value=" 提交 "> <input type="reset" name="submit" value=" 重置 "> </div></td> </table> </form> </body> </html> (3) 客户意见反馈表页面设计 ( 源码参考 ) <html> <body> <form action="" method="gett" name="form1" target="_self"> <table width="481" border="0" cellspacing="1" bgcolor="#ff0000"> <td width="71"> 姓名 </td> <td width="394"><input name="txtname" type="text" id="txtname" value=" 张三 "></td> <td> 性别 </td> <td><input name="radsex" type="radio" value=" 男 " checked> 男 <input type="radio" name="radiobutton" value=" 女 "> 女 </td> <td> 电子邮件 </td><td><input name="txtemail" type="text" " onblur="mm_validateform('textfield2','','nisemail');return document.mm_returnvalue" value="abc@163.com"> </td>
<td> 联系电话 </td> <td><input name="txttel" type="text" id="txttel" value="05368888888"></td> <td> 反馈意见 </td> <td><textarea name="txtfkyj" cols="50" rows="5" id="txtfkyj"></textarea></td> <tr><td colspan="2"><div align="center"> <input type="submit" name="submit2" value=" 提交 "> <input type="reset" name="submit" value=" 重置 "> </div></td> </table> </form> </body> </html>