设为首页 加入收藏

TOP

tcl脚本语言的笔试题 很简单的
2014-11-20 04:02:21 来源: 作者: 【 】 浏览:27
Tags:tcl 脚本 语言 试题 简单

一.填空题(每题3分,共30分)


1. regexp { ([0-9]+) *([a-z]+)} ” there is 100 apples” total num word


puts ” $total ,$num,$word”


最后输出结果为___________________.


参考:100 apples ,100,apples


2. regsub there ”They live there lives ” their x


puts $x


最后输出结果为___________________.


参考:They live their lives


3.(每空一分)


TCL提供三种形式的置换:_________,_____________和____________.


参考:变量置换、命令置换和反斜杠置换


4. set x 10


Set y $x+100


最后输出结果为___________________.


参考:10+100


5.(每空1分)


Set x 100


Set y “$x ddd” 此句输出内容为__________
set y {/n $x} 此句输出内容为__________


Set y [expr {$x+10}]此句输出内容为__________


参考:100 ddd


/n $x


110


6.建立一个数组day,它有两个元素Monday,Tuesday,值分别为1 2


创建语句为:_______________


_______________


参考:set day(monday) 1
set day(tuesday) 2


7. lindex {1 2 {3 4}} 2


输出结果为_______________


参考:3 4


8. linsert { 1 2 {3 4} 1 7 8 {9 10}


输出结果为_______________


参考:1 7 8 {9 10} 2 {3 4}


9.string first ab defabc


输出结果为_______________


参考:3


10. catch {return “all done”} string


Set string


输出结果为_______________


参考:all done




二.简答题(每题10分,共30分)


1.#!/usr/bin/tclsh


#


#Demonstrate operators and


#math functions


set PI [expr 2*asin(1.0)]


if {$argc==3} {


set X [lindex $argv 0]


set Y [lindex $argv 1]


set Rad [lindex $argv 2]


set Dist [expr sqrt(($X*$X)+($Y*$Y))]


set Cir [expr 2*PI*$Rad]


set Area [expr $Rad*$Rad]


puts stdout “Distance = $Dist”


puts stdout “Circumference = $Cir”


} else {


puts stdout “Wrong argument count!”


puts stdout “Needs X,Y ,and Radius”


}


提示,asin(1.0)值为1.5707963 Linux下以上脚本程序输出内容为:


______________________________________


参考: Wrong argument count!


Needs X,Y ,and Radius


2. #!/usr/bin/tclsh


#


#Demonstate global variables


#and backslash substitution


if {$argc >=1 } {


set N 1


foreach Arg $argv {


puts stdout “$N:$Arg\n”


set N [expr $N +1 ]


if {$Arg==”ring”} {


puts stdout “\a”


}


}


} else {


puts stdout “$argv0 on X Display $env(DISPLAY)\n”


}


Linux中以上脚步命名为hello3,则运行脚本以下结果为:


$ ./hello3.tcl


______________________


$ ./hello3.tcl ring


_______________________



3.当 y值分别为 a b c时


以下程序运行结果是什么?为什么会是这个结果


set x 10


switch $y {


a {incr $x}


b {incr $y}


default {incr $x}


}


_________________


参考:均出错,incr表达式应为 incr 变量 数值



三.编程题(每题20分,共40分)


参考代码:


proc main {x} {


if {$x==0} {


return 1


} else {


set sum 1


for { set i 0} {$i<=[expr $x-1]} {incr i 1} {


set sum [expr $sum+[expr $sum*$i]]


}


return $sum


}


}



参考代码:


proc 2to10 {x} {


set sum 0


proc length {x} {


string length $x


}


set n [length $x]



for {set i 0} {$i<=$n-1} {incr i 1} {


proc a {x i} {


string index $x end-$i


}


if {[a $x $i]==0} {



} elseif {[a $x $i]==1} {


set a [expr pow(2,$i)]


set b [expr [a $x $i]]


set p [expr [expr $a*$b]]


set sum [expr $sum+$p]


} else {


puts stdout “请正确输入二进制!”


return


}


}


puts stdout $sum


}



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇可靠的数据流传输TCP 下一篇深入、实践与展现自己

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: