Perl语言入门(第四版)习题答案

合集下载

Perl语言入门(第四版)习题答案

Perl语言入门(第四版)习题答案

Perl语言入门(第四版)习题答案《Perl语言入门习题答案》2.12 练习1、写一个程序,计算半径为12.5的圆的周长。

圆周长等于2π(π约为3.1415926)乘以半径。

答案为78.5。

-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth#confish@ubuntu7.10$r=12.5;$g=12.5*2*3.1415;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。

如果,用户输入12.5,则应得到和上题一样的结果。

-----------------------/home/confish/perl/girthpro #!/usr/bin/perl -w#a better one to calculate girth#confish@ubuntu7.10print"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is".$r*2*3.1415."\n";}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。

-----------------------/home/confish/perl/girthzero #!/usr/bin/perl -w#calculate the girth and print 0 when the radius is lower than 0#confish@ubuntu7.10print"enter the radius of the line\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is$r*2*3.1415\n";}else{print"the girth of the circle is 0\n";}-----------------------/home/confish/perl/girthzero1、2、3:(一起实现的)#!/usr/bin/perl -w$pai=3.141592654;print "Please Input Radius:";$r=<STDIN>;if ( $r lt 0 ){print "The circumference is 0\n";}else{$l=$r*2*$pai;printf "The circumference is %.1f\n",$l;}4、写一个程序,用户能输入2 个数字(不在同一行)。

汇编语言程序设计(第四版)第1~4章【课后答案】

汇编语言程序设计(第四版)第1~4章【课后答案】

汇编语言程序设计第四版【课后习题答案】第1章汇编语言基础知识〔习题1.1〕简述计算机系统的硬件组成及各部分作用。

〔解答〕CPU:包括运算器、控制器和寄存器组。

运算器执行所有的算术和逻辑运算;控制器负责把指指令逐条从存储器中取出,经译码分析后向机器发出各种控制命令,并正确完成程序所要求的功能;寄存器组为处理单元提供所需要的数据。

存储器:是计算机的记忆部件,它用来存放程序以及程序中所涉及的数据。

外部设备:实现人机交换和机间的通信。

〔习题1.2〕明确下列概念或符号:主存和辅存,RAM和ROM,存储器地址和I/O端口,KB、MB、GB和TB。

〔解答〕主存又称内存是主存储器的简称,主存储器存放当前正在执行的程序和使用的数据,CPU可以直接存取,它由半导体存储器芯片构成其成本高、容量小、但速度快。

辅存是辅助存储器的简称,辅存可用来长期保存大量程序和数据,CPU需要通过I/O接口访问,它由磁盘或光盘构成,其成本低、容量大,但速度慢。

RAM是随机存取存储器的英语简写,由于CPU可以从RAM读信息,也可以向RAM写入信息,所以RAM也被称为读写存储器,RAM型半导体存储器可以按地址随机读写,但这类存储器在断电后不能保存信息;而ROM中的信息只能被读出,不能被修改,ROM型半导体通常只能被读出,但这类存储器断电后能保存信息。

存储器由大量存储单元组成。

为了区别每个单元,我们将它们编号,于是,每个存储单元就有了一个存储地址,I/O接口是由一组寄存器组成,为了区别它们,各个寄存器进行了编号,形成I/O地址,通常称做I/O端口。

KB是千字节、MB是兆字节、GB是吉字节和TB是太字节,它们都是表示存储器存储单元的单位。

〔习题1.3〕什么是汇编语言源程序、汇编程序、目标程序?〔解答〕用汇编语言书写的程序就称为汇编语言源程序;完成汇编工作的程序就是汇编程序;由汇编程序编译通过的程序就是目标程序。

〔习题1.4〕汇编语言与高级语言相比有什么优缺点?〔解答〕汇编语言与高级语言相比的优点:由于汇编语言本质就是机器语言,它可以直接地、有效地控制计算机硬件,因而容易产生运行速度快,指令序列短小的高效目标程序,可以直接控制计算机硬件部件,可以编写在“时间”和“空间”两方面最有效的程序。

Perl练习题

Perl练习题

2.12 练习写一个程序,计算半径为12.5的圆的周长。

圆周长等于2π(π约为3.1415926)乘以半径。

答案为78.5。

#!/usr/bin/perl$r=12.5;$pai=3.1415926 ;$C=2*$pai*$r;Print “$C\n”;修改上述程序,用户可以在程序运行时输入半径。

如果,用户输入12.5,则应得到和上题一样的结果。

#!/usr/bin/perl$r=<STDIN>;$pai=3.1415926 ;$C=2*$pai*$r;Print “$C\n”;修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。

#!/usr/bin/perl$r=<STDIN>;$pai=3.1415926 ;if($r>=0){$C=2*$pai*$r;}If($r<0){$C=0;}Print “$C\n”;写一个程序,用户能输入2 个数字(不在同一行)。

输出为这两个数的积。

#!/usr/bim/perl$a=<STDIN>;$b=<STDIN>;$c=$a*$b;Print”$c”;写一个程序,用户能输入1 个字符串和一个数字(n)(不在同一行)。

输出为,n 行这个字符串,1 次1 行(提示,使用“x”操作符)。

例如,如果用户输入的是“fred”和“3”,则输出为:3 行,每一行均为fred。

如果输入为“fred”和“299792”,则输出为299792 行,每一行均为fred。

#!/usr.bin/perl$string=<STDIN>;$int=<STDIN>;$output=$string x $intprint $output;3.9练习写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。

如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Windows 系统中使用CTRL+Z.写一个程序,读入一串数字(一个数字一行),将和这些数字对应的人名(下面列出的)输出来。

【Lua程序设计第四版练习题答案】ch01Lua语言入门

【Lua程序设计第四版练习题答案】ch01Lua语言入门

【Lua程序设计第四版练习题答案】ch01Lua语⾔⼊门
联系1.1: 运⾏阶乘的⽰例并观察,如果输⼊负数,程序会出现什么问题?试着修改代码来解决问题。

-- 定义⼀个计算阶乘的函数
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
print("enter a number:")
a = io.read("*n") -- 读取⼀个数字
print(fact(a))
这是本章最开始提到的阶乘⽰例程序,通过实际的运⾏,我们了解到由于程序没有对负数形式进⾏校验的逻辑,因此程序会⼀直迭代递归下去,没有终⽌条件lua编译器报出堆栈溢出的错误才结束。

在进⾏修改之后的代码如下:
opefunction fact(n)
n = n or 0
if n < 0 then
error("Cannot calculate the factorial of a negative number")
elseif n == 0 then
return 1
else
return n * fact(n-1)
end
end
print("Enter a number: ")
a = io.read("*n")
print("Answer is: ", fact(a))
这⾥加⼊对输⼊负数的终⽌条件的判断,因此不会再出现堆栈溢出的错误。

perl 复习题 (答案)

perl 复习题 (答案)

PERL复习题(答案不是标准答案,仅供参考)一、选择题1. What is the simplest type of data that Perl can work with?A elementB scalarC vectorD component2. Which operator can be used to take the bottom item from an array?A popB pushC pullD plant3. Which operator is used to arrange items in character order?A ascendB sortC arrangeD descend4. Rather than using print, what is often used in Perl when formatting is important?A printfB formatC alignD show5. Which modifier can be used when matching in Perl to ignore case?A sB vC iD c6. Which operator can be used to break up a string into more than one part based upon a separator?A chopB splitC divideD parse7. What option do you use when starting Perl to tell it to run in warning mode? _-w \ use warnings (Fill in the blank.)8. Which control structure can be used to execute only a condition is false?A untilB unlessC whileD without9. Which of the following commands should be used to open a filehandle named KAREN to an existing file named sw?A open KAREN “>sw”;B open KAREN, “>sw”;C open “sw” KAREN;D open “>sw”, KAREN;10. Within Perl, which operator is used to change the working directory?A cdB chdirC pwdD wd11. Which operator can be used to access the first item in an array?A shiftB startC right$D left$12. Within a loop, which operator immediately ends execution of the loop?A nextB lastC redoD leave13. Which function can be used to make sure your program exits with a nonzero status even if there a standard error?A hashB noexitC nozeroD die14. Which of the following operators work most like simple searching/pattern matching?A /fB /gC s///D m//15. Which keyword is used in Perl to define a subroutine?A branchB subC splitD make16. You want to close the directory handle EV AN. Which of the following should you use to accomplish this?A close EV AN;B closedir EV AN;C close_directory EV AN;D none of the above17. Which of the following lines of code accomplishes the same thing as $price = $price + 9;?A $price +9;B $price =+9;C $price +=9;D 9 + $price18. What value do variables have before they are first assigned?A undefB nullC 0D nil19. Which Perl function can be used to launch a child process to run a program?A splitB spinC forkD system20. Which Perl function can be used to identify the first found occurrence of a substring?A findB indexC locateD allocate21. Which control structure can be used to loop as long as a conditional expression returns true?A untilB unlessC whileD without22. Which operator can be used to create private variables within a subroutine?A nativeB limitedC myD regional23. Which of the following operators is used to return a value in a subroutine?A returnB sendC giveD show24. Your script has just read in a variable from the keyboard and you want to strip that variable of the newline character that came in. What operator should you use to perform this operation?A tidyB trimC chompD slim25. What is the default sort order in Perl?A alphabeticB numericC ASCIID none of the above26. Within a loop, which operator jumps to the end of the loop but does not exit the loop?A nextB lastC redoD leave27. (不确定)Which of the following should be used to print values in an array that do not contain newlines and add them to the end of each entry?A print @array;B print @array\n;C print “@array\n”;D print “$@array \\”;28. Which string comparison operator would be equivalent to the numeric > operator?A neB eqC geD gt29. Which function can be thought of as the opposite of split?A linkB joinC uniteD bond30. Which operator can be used to add an item to the bottom of an array?A popB pushC pullD plant31. Which of the following mathematical operations has the highest precedence in Perl?A **B ++C +D -32. 以下哪一个字符串直接量的定义方式是错误的()(1)'thank you'(2)" "(3)"a "friend" of yours"(4)"a \"friend\" of yours"33. 以下哪一条语句是错误的()(1)$_= 'hello world';(2)$a='hello world';(3)my $b,$a='hello world';(4)my ($a,$b)=(0,'hello world');34. 要使下面的程序正常运行,while后的表达式应选()。

Perl语言入门实战习题[试题]

Perl语言入门实战习题[试题]

Perl语言入门实战习题[试题] 《Perl语言入门实战习题》一、计算FASTA文件中每条序列的长度; 输入文件,FASTA格式:注:如果输入文件在windows下产生,在Linux系统下操作时,宜先用dos2unix处理:用法:dos2unix 输入文件输出文件:Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) { # @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.len>\n"; # 当命令行参数不是2的时候输出使用说明 }my ($infile,$outfile) = @ARGV; # 把命令行参数赋值给输入文件和输出文件 open IN,$infile || die"error: can't open infile: $infile"; # 打开输入文件句柄IN open OUT,">$outfile" || die$!; # 打开输出文件句柄OUT $/=">";<IN>; # 设置输入记录分隔符为”>”,并去除第一个”>”while ( my $seq = <IN>){ # 把序列ID行和序列赋值给$seqmy $id = $1 if($seq =~ /^(\S+)/); # 获取序列IDchomp $seq; # 去掉末尾的”>”$seq =~ s/^.+?\n//; # 删除第一行$seq =~ s/\s//g; # 删除序列中的空白字符my $len = length($seq); # 计算序列长度print OUT "$id\t$len\n"; # 输出结果到输出文件}$/="\n"; # 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT; # 关闭输出文件句柄二、计算FASTA文件中每条序列的GC含量; 输入文件同上,输出文件:Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) {# @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.gc>\n";# 当命令行参数不是2的时候输出使用说明}my ($infile,$outfile) = @ARGV;# 把命令行参数赋值给输入文件和输出文件open IN,$infile || die"error: can't open infile: $infile";# 打开输入文件句柄IN open OUT,">$outfile" || die$!;# 打开输出文件句柄OUT$/=">";<IN>;# 设置输入记录分隔符为”>”,并去除第一个”>” while(<IN>){# $_=<IN>,把序列ID行和序列赋值给$_,$_= 可以省略不写my $id = $1 if(/^(\S+)/);# 获取序列IDchomp; # 去掉末尾的”>”s/^.+?\n//;# 删除第一行s/\s//g; # 删除序列中的空白字符my $GC = (tr/GC/GC/);#计算G或C碱基个数my $AT = (tr/AT/AT/);#计算A或T碱基个数my $len = $GC + $AT;# 计算序列非N长度my $gc_cont = $len ? $GC / $len : 0; #计算GC含量,如果长度为0,GC含量算0print OUT "$id\t$gc_cont\n"; # 输出结果到输出文件 }$/="\n";# 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT;# 关闭输出文件句柄三、求反相互补序列;输入文件同上,输出文件也是FASTA格式 Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) {# @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.gc>\n";# 当命令行参数不是2的时候输出使用说明}my ($infile,$outfile) = @ARGV;# 把命令行参数赋值给输入文件和输出文件open IN,$infile || die"error: can't open infile: $infile";# 打开输入文件句柄IN open OUT,">$outfile" || die$!;# 打开输出文件句柄OUT $/=">";<IN>;# 设置输入记录分隔符为”>”,并去除第一个”>” while (<IN>){# $_=<IN>,把序列ID行和序列赋值给$_,$_= 可以省略不写my $id = $1 if(/^(\S+)/);# 获取序列IDchomp; # 去掉末尾的”>”s/^.+?\n//;# 删除第一行s/\s//g; # 删除序列中的空白字符$_ = reverse $_; # 序列方向tr/ATCG/TAGC/; # 序列互补print OUT ">$id\n",$_,"\n"; # 输出结果到输出文件}$/="\n";# 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT;# 关闭输出文件句柄四、列表信息整合;输入列表1:序列长度文件输入文件2:序列测序覆盖深度文件输出文件:把上述两个列表的信息整合成一个列表,并且最后一行给出汇总结果:Perl代码#!/usr/bin/perl -wuse strict;(@ARGV==3) || die"Usage: perl $0 <list1> <list2> <combine.list>\n"; # 当命令行参数不是3的时候输出使用说明my ($infile1,$infile2,$outfile) = @ARGV;# 把命令行参数赋值给输入文件1、输入文件2和输出文件 my %id_len; # 定义一个哈希open IN1,$infile1 || die$!; # 打开第一个文件句柄while(<IN1>){my ($id,$len) = split /\s+/,$_; # split函数用空白符号切割每一行的内容$id_len{$id} = $len; # 哈希赋值:id => length}close IN1; # 关闭第一个文件句柄open IN2,$infile2 || die$!; # 打开第2个文件句柄open OUT,">$outfile" || die$!; # 打开输出文件句柄my $tol_len = 0; # 定义总长度变量,并赋值为0my $tol_depth = 0; # 定义总深度变量,并赋值为0while (<IN2>){my ($id,$depth) = split; # split函数用空白符号切割每一行的内容my $len = $id_len{$id}; # 序列长度print OUT join("\t",$id,$len,$depth),"\n"; # 输出整合信息到输出文件$tol_len += $len; # 长度累加$tol_depth += $len * $depth; # 深度累加}$tol_depth /= $tol_len; # 计算总体平均深度print OUT "Total\t$tol_len\t$tol_depth\n"; # 输出汇总结果到输出文件close IN2; # 关闭第二个输入文件句柄close OUT; # 关闭输出文件句柄五、串流程;Perl在工作中常用于串流程,现有同事写了3个perl脚本分三步将输入文件,infile.txt处理成最终的final.result:第1步:perl step1.pl infile.txt output1 第2步:perl step2.pl infile.txt output2 第3步:perl step3.pl output1 output2 final.result为提高工作效率,现需要写一个脚本使用infile.txt 作为输入文件,直接得到final.result,中间产生的文件结果不保留。

汇编语言程序设计(第四版)第4章【课后答案】【精选】

汇编语言程序设计(第四版)第4章【课后答案】【精选】

汇编语言程序设计 第四版【课后习题答案】--囮裑為檤第4章 基本汇编语言程序设计〔习题4.1〕例题4.2如果要求算术右移8位,如何修改程序。

〔解答〕思路: 首先由最高位字节向次低位字节传送……次低位字节向最低位字节传送(共7次);再判最高位字节符号位,如为0,送00h 到最高位字节;如为1,送ffh 到最高位字节。

传送可参考例题4.2,不过应从第一号字节送第零号字节,……最高位字节向次低位字节传送;也可以用循环来完成: .model small .stack 256 .dataqvar dq 1234567887654321h .code .startup mov cx,7 mov si,1again: mov al, byte ptr qvar[si] mov byte ptr qvar[si-1],al inc siloop again test al,80h jz ezzmov bl,0ffh jmp done ezz: mov bl,0done: mov byte ptr qvar[7],bl .exit 0 end〔习题4.2〕例题4.2如果要求算术左移7位,如何用移位指令实现。

〔解答〕思路:可设计外循环体为8个字节左移一次,方法是:最低位字节算术左移一次, 次低位字节至最高位字节依次带 CF 位循环左移一次(内循环共8次),外循环体控制执行7次即可。

.model small .stack 256 .dataqvar dq 1234567887654321h4 11 201628.code.startupmov dx, 7 ;外循环次数mov ax, byte ptr qvar[0] ;最低位字节送axlpp: shl ax, 1 ;最低位字节左移一次,其d7移入CF 位 mov si, 1mov cx, 7 ;内循环次数again: rcl byte ptr qvar[si], 1 ;高位字节依次左移 P50 inc siloop again dec dx jnz lpp .exit 0 .end〔习题4.3〕将AX 寄存器中的16位数连续4位分成一组,共4组,然后把这4组数分别放在AL 、BL 、CL 和DL 寄存器中。

Perl语言入门(第四版)习题标准答案

Perl语言入门(第四版)习题标准答案

Perl语言入门(第四版)习题答案————————————————————————————————作者:————————————————————————————————日期:《Perl语言入门习题答案》2.12 练习1、写一个程序,计算半径为12.5的圆的周长。

圆周长等于2π(π约为3.1415926)乘以半径。

答案为78.5。

-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth#confish@ubuntu7.10$r=12.5;$g=12.5*2*3.1415;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。

如果,用户输入12.5,则应得到和上题一样的结果。

-----------------------/home/confish/perl/girthpro#!/usr/bin/perl -w#a better one to calculate girth#confish@ubuntu7.10print"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is ".$r*2*3.1415."\n";}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。

Perl语言学习练习及参考答案

Perl语言学习练习及参考答案

#题2:#使用for循环打印出如下的字符。

# 1# 12# 123# 12345#*******************#Fw_Print_Step ($step++,"使用for循环打印出如下的字符。

11212312345");my $str= "";for (1..4) {$str= $str.$_;if ($_==4) {$str= $str.$_+1;}print " $str\n";}#*******************##题3:my $str1 = "abc";my $str2 = "efg";#将上述2个字符串连接起来,并输出合并后的字符串长度#*******************#Fw_Print_Step ($step++,"将上述2个字符串\"$str1\"和\"$str2\"连接起来,并输出合并后的字符串长度");my $str =$str1.$str2;my $str_length=length($str);print "新字串$str的长度为:$str_length";#*******************##题4:#以逆序方式打印出字符串包含的各个字符,如变量为"123456789"则输出为"9","8",..."2","1". my $str1="abc123def456";#*******************#Fw_Print_Step ($step++,"以逆序方式打印出字符串包含的各个字符,如变量为\"123456789\"则输出为\"9\",\"8\",...\"2\",\"1\".");my $str=$str1;print "以逆序方式打印出字符串\"$str1\"包含的各个字符:\n";for($length=length($str1); $length>0; $length--) {$sub_str=chop($str);if ($length>1) {print "\"$sub_str\",";} else {print "\"$sub_str\".";}}#*******************##题5:#分别使用for与while循环来计算1+2+3+...+100的值#*******************#Fw_Print_Step ($step++,"分别使用for与while循环来计算1+2+3+...+100的值"); print "用for循环计算1+2+3+...+100的值:\n ";my $result=0;for (1..100) {$result=$result+$_;}print "1+2+3+...+100=$result";print "\n用while循环计算1+2+3+...+100的值:\n ";my $result=0;my $num=1;while ($num<=100) {$result=$result+$num;$num++;}print "1+2+3+...+100=$result";#*******************##题6:#以逆序的方式打印出端口列表包含的成员口my @cmdArray = ("config", "int fa 0/1", "no shutdonw", "end");#*******************#Fw_Print_Step ($step++,"以逆序的方式打印出端口列表包含的成员口");for (my $start=$#cmdArray; $start>=0; $start--) {my $array=$cmdArray[$start];print "$array\n";}#*******************##题7:#使用foreach打印出Hash表的所有下标与值my %map = ('red', 0xff0000,'green', 0x00ff00,'blue',0x0000ff);#*******************#Fw_Print_Step ($step++,"使用foreach打印出Hash表的所有下标与值");foreach $capword (sort keys(%map)) {print ("$capword: $map{$capword}\n");}#while( ($key, $value) = Each (%Map)) {# Print "\N$key=$value;"}#*******************##题8:#使用正则匹配判断字符串是否包含error,若是打印提示信息。

Perl面试题

Perl面试题

Perl语言面试题1.问题:什么是Perl?答案:Perl是一种解释型、功能丰富的编程语言,它具有动态的特性,能够处理文本和数据,非常适合用于文本处理、系统管理、网络编程、数据库操作等任务。

2.问题:Perl的基本语法是什么?答案:Perl的基本语法包括变量声明、控制结构(如if、while等)、循环结构(如for、foreach等)、函数定义和调用等。

3.问题:在Perl中如何声明变量?答案:在Perl中,可以使用$符号来声明变量,例如$var = 10;。

4.问题:在Perl中如何进行字符串操作?答案:Perl提供了丰富的字符串操作函数,如substr、index、length、tr 等,可以进行字符串的切割、查找、替换等操作。

5.问题:在Perl中如何进行数组操作?答案:Perl支持数组操作,可以使用@符号来声明数组,并使用push、pop、shift、unshift等函数进行数组的添加、删除、移除等操作。

6.问题:在Perl中如何进行文件操作?答案:Perl提供了丰富的文件操作函数,如open、readline、readlines 等,可以进行文件的打开、读取、写入等操作。

7.问题:在Perl中如何进行正则表达式匹配?答案:Perl支持正则表达式匹配,可以使用正则表达式函数如qr()和m()来进行模式匹配和替换操作。

8.问题:在Perl中如何使用循环结构?答案:Perl支持多种循环结构,如for、foreach、while等,可以根据需要选择合适的循环结构进行迭代操作。

9.问题:在Perl中如何定义和使用函数?答案:在Perl中,可以使用sub关键字定义函数,并使用&符号调用函数。

函数可以接受参数并返回值。

10.问题:请举一个使用Perl进行文本处理的例子?答案:例如,使用Perl提取一个文本文件中的特定行,可以根据行号或关键字进行提取。

具体实现可以使用open函数打开文件,并使用readline或readlines函数逐行读取文件内容,根据条件筛选出需要的行。

Proakis的数字通信第四版的习题答案中文版

Proakis的数字通信第四版的习题答案中文版

2.9 根据柯西分布有当x 很大时, 所以有 (b) 当当0v ≤, 因此有:2.10 (a)(b)(c)因为n →∞, 不是高斯分布,因此中心极限定理不适用,原因是柯西分布没有有限的差异。

2.11 假定 是实值随机过程。

复值过程的处理也类似。

(a)(b)当x (t ), y (t )不相关时, 同理因此(3)当x (t ), y (t )不相关并且零均值时:0v ≥2.12 随机过程x(t)的功率谱密度为:滤波器输出功率谱密度为:因此滤波器输出总功率为:2.14令因此2.16 滤波器的传递函数为:(a)(b)令a = RC, v =2πf. 那么2.19 因为输出序列的自相关:这里的最后等式来自于X(n)的自相关函数:因此离散时间系统的频率响应为:综上,系统输出的功率密度谱为:2.20 已知功率密度谱为:2.21 本题中引用下标d表示离散过程,下标a表示连续时间过程,同样,f表示模拟频率。

f d表示离散频率。

(a)因此取样信号的自相关函数等于X(t)的取样自相关函数。

(b)令fd = fT,则有:又因为离散时间的自相关函数是它的功率谱密度的反变换,于是有:比较(1),(2):得(c) 从(3)式可以得出:否则出现混叠。

2.22 (a)(b) 如果 那么:K=0其他因此序列X (n )是白噪声序列,T 的最小值可以从下图的取样过程的功率谱密度得到为了得到一个谱平坦序列,最大的抽样速率应满足:可由得到。

(c)因此2211sin w ()()()w πτφτφτπτ==,2.23 假设 那么:这里Y(f)是y (t )的傅里叶变换,因为:又有:当f=0时:2.24由于G=1,有对低通滤波器,可得到:将H(f)代入可得下式3.4 要证而利用不等式当且仅当可得因为3.6 通过定义,差熵为:对均匀分布随机变量(a) a=1,H(X)=0(b) a=4,H(X)=log4=2log2(c) a=1/4,H(X)=log 14=-2log23.7 (a)(b)每信源字符的平均二进制个数为:(c)信源熵为:通过比较,信源熵要少于每个码字的平均长度。

《标准C语言基础教程(第四版)》习题答案(一)

《标准C语言基础教程(第四版)》习题答案(一)

练习3.6编程练习1~3题#include<stdio.h>int main(){float x,y;x=(3+10)/2.0;y=(4+12)/2.0;printf("%f\n",x);printf("%f\n",y);return 0;}4题#include<stdio.h>#define ER 2.0int main(){int x1,y1,x2,y2;float x3,y3;printf("请输入数据:");scanf("%d %d %d %d",&x1,&y1,&x2,&y2);x3=(x1+x2)/ER; /*注意应先输入数据后在计算*/ y3=(y1+y2)/ER;printf("(%5.2f,%5.2f)\n",x3,y3);return 0;}5题#include<stdio.h>#include<math.h>int main(){int num1;float num2;printf(“请输入数据:”);scanf(“%d”,&num1);num2 = pow(num1,0.25);printf(“输入数据的4次方根为:%f\n”,num2);return 0;}6题#include<stdio.h>#include<math.h>int main(){int X,N,R;float A;printf(“输入初始存款金额:”);scanf(“%d”,&X);printf(“输入存期:”);scanf(“%d”,&N);printf(“输入年利率:”);scanf(“%d”,&R);A = X*pow((1.0+R/100.0),N);printf(“获得的货币量:%f\n”,A);return 0;}7题1、分析问题a 、确定期望的输出。

C++Primer中文版(第四版)题解整理

C++Primer中文版(第四版)题解整理

查看所用的编译器文档,了解它所用的文件命名规范。

编译并运行本节的main 程序。

【解答】一般而言,C++编译器要求待编译的程序保存在文件中。

C++程序中一般涉及两类文件:头文件和源文件。

大多数系统中,文件的名字由文件名和文件后缀(又称扩展名)组成。

文件后缀通常表明文件的类型,如头文件的后缀可以是.h 或.hpp 等;源文件的后缀可以是.cc 或.cpp 等,具体的后缀与使用的编译器有关。

通常可以通过编译器所提供的联机帮助文档了解其文件命名规范。

习题1.2修改程序使其返回-1。

返回值-1 通常作为程序运行失败的指示器。

然而,系统不同,如何(甚至是否)报告main 函数运行失败也不同。

重新编译并再次运行程序,看看你的系统如何处理main 函数的运行失败指示器。

【解答】笔者所使用的Windows操作系统并不报告main 函数的运行失败,因此,程序返回-1 或返回0 在运行效果上没有什么区别。

但是,如果在DOS 命令提示符方式下运行程序,然后再键入echo %ERRORLEVEL%命令,则系统会显示返回值-1。

习题1.3编一个程序,在标准输出上打印“Hello, World”。

#include <iostream>#include "windows.h"using namespace std;int main(){ system("CLS");cout<<"Hello,World!"<<endl;return 0;}习题1.4我们的程序利用内置的加法操作符“+”来产生两个数的和。

编写程序,使用乘法操作符“*”产生两个数的积。

#include <iostream>#include "windows.h"using namespace std;int main(){ system("CLS");cout<<"Enter two numbers:"<<endl;int v1,v2;cin>>v1>>v2;cout<<"The product of "<<v1<<" and "<<v2<<" is "<<v1*v2<<endl;return 0;}习题1.5我们的程序使用了一条较长的输出语句。

Perl语言入门习题

Perl语言入门习题

Perl语言入门习题_第四章1.[12]写一个名为&total 的子程序,返回一列数字的和。

提示:子程序不应当有任何的 I/O 操作;它处理调用的参数,返回处理后的值给调用者。

结合下面的程序来练习,它检测此子程序是否正常工作。

第一组数组之和我25。

2.[5]利用上题的子程序,写一个程序计算从 1 到1000的数字的和3.[18]额外的练习:写一个子程序,名为&above_average,将一列数字作为其参数,返回所有大于平均值的数字(提示:另外写一个子程序来计算平均值,总和除以数字的个数)。

#!/usr/bin/perluse strict;my@fred = qw{ 1 3 5 7 9 };my $fred_total = &total(@fred);print "The total of \@fred is $fred_total.\n";print "Enter some numbers on separate lines: ";my $user_total = &total(<STDIN>);print "The total of those numbers is $user_total.\n";sub total{my $sum;for(@_){$sum += $_;}return $sum;}#!/usr/bin/perluse strict;my @tmp = 1..1000;my $sum = &total(@tmp);print "total is : $sum.\n";sub total{my $sum;for(@_){$sum += $_;}return $sum;}#!/usr/bin/perluse strict;my @fred = &above_average(1..10);print "\@fred is @fred\n";print "(Should be 6 7 8 9 10)\n";my @barney = &above_average(100, 1..10); print "\@barney is @barney\n";print "(Should be just 100)\n";sub above_average{my $sum = &total(@_);my $average = $sum / @_;my @result;foreach(@_){if($_ > $average){push @result , $_ ;}}return @result;}sub total{my $sum;for(@_){$sum += $_;}return $sum;}----------------------------------------------------------------------------------Perl语言入门习题_第五章1.[7] 写一个程序,类似于cat,但保持输出的顺序关系。

C语言入门经典(第4版)课后练习参考答案

C语言入门经典(第4版)课后练习参考答案

目录目录 (1)第1章C语言编程 (4)练习1.1 (4)练习1.2 (5)练习1.3 (5)第2章编程初步 (6)习题2.1 (6)习题2.2 (7)习题2.3 (9)习题2.4 (10)第3章条件判断 (12)习题3.1 (12)习题3.2 (14)习题3.3 (19)习题3.4 (21)第4章循环 (24)习题4.1 (24)习题4.2 (26)习题4.4 (27)习题4.5 (29)第5章数组 (31)习题5.1 (31)习题5.2 (33)习题5.3 (35)习题5.4 (36)习题5.5 (39)第6章字符串和文本的应用 (41)习题6.1 (41)习题6.2 (50)习题6.3 (53)习题6.4 (53)第7章指针 (57)习题7.1 (57)习题7.2 (59)习题7.3 (61)习题7.4 (63)习题8.1 (65)习题8.2 (67)习题8.3 (69)习题8.4 (73)第9章函数再探 (79)习题9.1 (79)习题9.2 (80)习题9.3 (83)习题9.4 (85)第10章基本输入输出操作 (87)习题10.1 (87)习题10.2 (89)习题10.3 (91)习题10.4 (92)第11章结构化数据 (95)习题11.1 (95)习题11.2 (99)习题11.3 (103)习题11.5 (114)第12章处理文件 (119)习题12.1 (120)习题12.2 (121)习题12.3 (125)习题12.4 (127)第13章支持功能 (132)习题13.1 (133)习题13.2 (133)习题13.3 (135)《C语言入门经典(第4版)》课后练习参考答案第1章C语言编程练习1.1 编写一个程序,用两个printf()语句别离输出自己的名字和地址。

练习1.2将上一个练习修改成所有的输出只用一个printf()语句。

练习1.3编写一个程序,输出下列文本,格式如下所示:"It's freezing in here," he said coldly.第2章编程初步习题2.1 编写一个程序,提示用户用英寸输入一个距离,然后将该距离值输出为码、英尺和英寸的形式。

Perl+习题答疑

Perl+习题答疑

Perl 习题(11)1 写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。

如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Windows 系统中使用CTRL+Z.(第3章习题)unless(@ARGV) {die "<input file> <output file>\n";}open(IN,"<$ARGV[0]") or die;my @line=<IN>;open(OUT,">$ARGV[1]") or die;foreach(reverse(@line)) {print OUT "$_";}2 写一个子程序,名为&above_average,将一列数字作为其参数,返回所有大于平均值的数字(提示:另外写一个子程序来计算平均值,总和除以数字的个数)。

利用下面的程序进行测试:(第4章习题)my @fred = &above_average(1..10);print "\@fred is @fred\n";print "(Should be 6 7 8 9 10)\n";my @barney = &above_average(100, 1..10);print "\@barney is @barney\n";print "(Should be just 100)\n";#!\usr\bin\perl -wuse strict;my @fred = &above_average(1..10);print "\@fred is @fred\n";print "(Should be 6 7 8 9 10)\n";my @barney = &above_average(100, 1..10);print "\@barney is @barney\n";print "(Should be just 100)\n";sub above_average{my @in=@_;my $average_value=&average(@in);my @out;foreach(@in) {if($_>$average_value){push @out,$_;}}return @out;}sub average {my @in=@_;my $sum=0;foreach(@in){$sum+=$_;}return $sum;}3 写一个程序,要求用户在不同的行中输入一些字符串,将此字符串打印出来,规则是:每一条占20 个字符宽度,右对齐。

Perl语言入门实战习题[试题]

Perl语言入门实战习题[试题]

Perl语言入门实战习题[试题] 《Perl语言入门实战习题》一、计算FASTA文件中每条序列的长度; 输入文件,FASTA格式:注:如果输入文件在windows下产生,在Linux系统下操作时,宜先用dos2unix处理:用法:dos2unix 输入文件输出文件:Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) { # @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.len>\n"; # 当命令行参数不是2的时候输出使用说明 }my ($infile,$outfile) = @ARGV; # 把命令行参数赋值给输入文件和输出文件 open IN,$infile || die"error: can't open infile: $infile"; # 打开输入文件句柄IN open OUT,">$outfile" || die$!; # 打开输出文件句柄OUT $/=">";<IN>; # 设置输入记录分隔符为”>”,并去除第一个”>”while ( my $seq = <IN>){ # 把序列ID行和序列赋值给$seqmy $id = $1 if($seq =~ /^(\S+)/); # 获取序列IDchomp $seq; # 去掉末尾的”>”$seq =~ s/^.+?\n//; # 删除第一行$seq =~ s/\s//g; # 删除序列中的空白字符my $len = length($seq); # 计算序列长度print OUT "$id\t$len\n"; # 输出结果到输出文件}$/="\n"; # 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT; # 关闭输出文件句柄二、计算FASTA文件中每条序列的GC含量; 输入文件同上,输出文件:Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) {# @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.gc>\n";# 当命令行参数不是2的时候输出使用说明}my ($infile,$outfile) = @ARGV;# 把命令行参数赋值给输入文件和输出文件open IN,$infile || die"error: can't open infile: $infile";# 打开输入文件句柄IN open OUT,">$outfile" || die$!;# 打开输出文件句柄OUT$/=">";<IN>;# 设置输入记录分隔符为”>”,并去除第一个”>” while(<IN>){# $_=<IN>,把序列ID行和序列赋值给$_,$_= 可以省略不写my $id = $1 if(/^(\S+)/);# 获取序列IDchomp; # 去掉末尾的”>”s/^.+?\n//;# 删除第一行s/\s//g; # 删除序列中的空白字符my $GC = (tr/GC/GC/);#计算G或C碱基个数my $AT = (tr/AT/AT/);#计算A或T碱基个数my $len = $GC + $AT;# 计算序列非N长度my $gc_cont = $len ? $GC / $len : 0; #计算GC含量,如果长度为0,GC含量算0print OUT "$id\t$gc_cont\n"; # 输出结果到输出文件 }$/="\n";# 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT;# 关闭输出文件句柄三、求反相互补序列;输入文件同上,输出文件也是FASTA格式 Perl代码:#!/usr/bin/perl -wuse strict;unless (@ARGV==2) {# @ARGV 传给脚本的命令行参数列表die"Usage: perl $0 <input.fa> <out.gc>\n";# 当命令行参数不是2的时候输出使用说明}my ($infile,$outfile) = @ARGV;# 把命令行参数赋值给输入文件和输出文件open IN,$infile || die"error: can't open infile: $infile";# 打开输入文件句柄IN open OUT,">$outfile" || die$!;# 打开输出文件句柄OUT $/=">";<IN>;# 设置输入记录分隔符为”>”,并去除第一个”>” while (<IN>){# $_=<IN>,把序列ID行和序列赋值给$_,$_= 可以省略不写my $id = $1 if(/^(\S+)/);# 获取序列IDchomp; # 去掉末尾的”>”s/^.+?\n//;# 删除第一行s/\s//g; # 删除序列中的空白字符$_ = reverse $_; # 序列方向tr/ATCG/TAGC/; # 序列互补print OUT ">$id\n",$_,"\n"; # 输出结果到输出文件}$/="\n";# 把输入记录分隔符改为默认值close IN; # 关闭输入文件句柄close OUT;# 关闭输出文件句柄四、列表信息整合;输入列表1:序列长度文件输入文件2:序列测序覆盖深度文件输出文件:把上述两个列表的信息整合成一个列表,并且最后一行给出汇总结果:Perl代码#!/usr/bin/perl -wuse strict;(@ARGV==3) || die"Usage: perl $0 <list1> <list2> <combine.list>\n"; # 当命令行参数不是3的时候输出使用说明my ($infile1,$infile2,$outfile) = @ARGV;# 把命令行参数赋值给输入文件1、输入文件2和输出文件 my %id_len; # 定义一个哈希open IN1,$infile1 || die$!; # 打开第一个文件句柄while(<IN1>){my ($id,$len) = split /\s+/,$_; # split函数用空白符号切割每一行的内容$id_len{$id} = $len; # 哈希赋值:id => length}close IN1; # 关闭第一个文件句柄open IN2,$infile2 || die$!; # 打开第2个文件句柄open OUT,">$outfile" || die$!; # 打开输出文件句柄my $tol_len = 0; # 定义总长度变量,并赋值为0my $tol_depth = 0; # 定义总深度变量,并赋值为0while (<IN2>){my ($id,$depth) = split; # split函数用空白符号切割每一行的内容my $len = $id_len{$id}; # 序列长度print OUT join("\t",$id,$len,$depth),"\n"; # 输出整合信息到输出文件$tol_len += $len; # 长度累加$tol_depth += $len * $depth; # 深度累加}$tol_depth /= $tol_len; # 计算总体平均深度print OUT "Total\t$tol_len\t$tol_depth\n"; # 输出汇总结果到输出文件close IN2; # 关闭第二个输入文件句柄close OUT; # 关闭输出文件句柄五、串流程;Perl在工作中常用于串流程,现有同事写了3个perl脚本分三步将输入文件,infile.txt处理成最终的final.result:第1步:perl step1.pl infile.txt output1 第2步:perl step2.pl infile.txt output2 第3步:perl step3.pl output1 output2 final.result为提高工作效率,现需要写一个脚本使用infile.txt 作为输入文件,直接得到final.result,中间产生的文件结果不保留。

PERL解题

PERL解题

Note that atan2(0, 0) is not well-defined. 2. 单元 1 写一个程序,计算半径为 12.5 的圆的周长。圆周长等于 2л(л约为 3.141592654)乘以 半径。答案是 78.5。 ex2_1:
1
#! /usr/bin/perl $c=2*3.141592654*12.5; print $c."\n";
3 写一个程序,将一些字符串(在不同的行中)读入一个列表中。然后按 ASCII 顺序将它们 输出来。也就是说,当输入的字符串 为 fred,barney,wilma,betty,则输出为 barney betty fred wilma。分别在一行或不同 的行将之输出。 ex3_3: #! /usr/bin/perl @strings=<STDIN>; chomp(@cstring=@string); @cstring1=sort @cstring; print sort @strings; print "@cstring1"; 4. 单元 1 写一个名为&total 的子程序,返回一列数字的和。提示:子程序不应当有任何的 I/O 操 作;它处理调用的参数,返回处理后的值给调用者。结合下面的程序来练习,它检测此子程 序是否正常工作。第一组数组之和为 25。 ex4_1: #! /usr/bin/perl my @fred=qw { 1 3 5 7 9 }; my $fred_total=&total(@fred); print "The total of \@fred is $fred_total.\n"; print "Enter some numbers on separate lines:";

Perl语言入门_1

Perl语言入门_1
The length of an array $len_of_array=@my_array; $len_of_array=scalar @my_array; $len_of_array=$#array+1; Change array length $#array=10; # some array elements may not defined
当双引号括起来的字符串中间含有$符 号时,会进行变量替换 $name=”Alice“; $hello=“hello $name”; $test=“\n, \t, \007, \x63”; #变量$hello的内容为”hello Alice” 如果为单引号,则不进行替换

字符串函数



列表的操作

push和pop是在队尾进行的 shift和unshift是在队头进行的
0
1
2
3
4
5
列表的@b; @c=(1..4,@a); 数组@a的长度可以用$#a+1得到 注意数组的长度是在运行时决定的
Array related


不需要编译 运行平台:Windows, UNIX and LINUX
Perl的优点和缺点

优点:

跨平台 擅长文本处理操作 实用高效

缺点:

不擅长数学计算 不擅长实时任务 代码难读
Perl的安装
Windows平台下的Perl安装程序 在ftp搜索引擎里搜索,

ActivePerl *perl*.msi

Removing newlines
chomp($string); chomp(@list); # one element # every element

语言学教程第四版答案

语言学教程第四版答案

语言学教程第四版答案【篇一:《语言学教程》测试题答案】xt>i.1~5 b a c c c6~10 b a c a cii.11~15 f f t f f 16~20 f f f f fiii.21. verbal 22. productivity / creativity 23. metalingual function24. yo-he-ho25. scientific26. descriptive 27. speech 28. diachronic linguistic29. langue 30. competenceiv.31. design feature: it refers to the defining properties of human language that tell the differencebetween human language and any system of animal communication.32. displacement: it means that human languages enable their users to symbolize objects, events andconcepts, which are not present (in time and space) at the moment of communication.33. competence: it is an essential part of performance. it is the speaker’s knowledge of his or herlanguage; that is, of its sound structure, its words, and its grammatical rules. competence is, in a way, an encyclopedia of language. moreover, the knowledge involved in competence is generally unconscious.a transformational-generative grammar is a model of competence.34. synchronic linguistics: it refers to the study of a language at a given point in time. the timestudied may be either the present or a particular point in the past; synchronic analyses can also be made of dead languages, such as latin. synchronic linguistics is contrasted with diachronic linguistics, the study of a language over a period of time.v.35. duality makes our language productive. a large number of different units can be formed out of asmall number of elements – for instance, tens of thousands of words out of a small set of sounds,around 48 in the case of the english language. and out of the huge number of words, there can beastronomical number of possible sentences and phrases, which in turn can combine to formunlimited number of texts. most animal communication systems do not have this design feature ofhuman language.if language has no such design feature, then it will be like animal communicational system whichwill be highly limited. it cannot produce a very large number of sound combinations, e.g. words,which are distinct in meaning.36. it is difficult to define language, as it is such a general term that covers too many things. thus,definitions for it all have their own special emphasis, and are not totally free from limitations.vi.37. it should be guided by the four principles of science: exhaustiveness, consistency, economy andobjectivity and follow the scientific procedure: form hypothesis – collect data – check against theobservable facts – come to a conclusion.第二章:语音参考答案i1~5 a c d a a6~10 d b a b bii.11~15 t t t f f 16~20 t t t f fiii.21. voiced, voiceless, voiced 22. friction23. tongue 24. height 25. obstruction26. minimal pairs27. diphthongs 28. co-articulation29. phonemes30. air streamiv.31. sound assimilation: speech sounds seldom occur in isolation. in connected speech, under the influenceof their neighbors, are replaced by other sounds. sometimes two neighboring sounds influence eachother and are replaced by a third sound which is different from both original sounds. this process is called sound assimilation.32. suprasegmental feature: the phonetic features that occur above the level of the segments are calledsuprasegmental features; these are the phonological properties of such units as the syllable, the word, and the sentence. the main suprasegmental ones includes stress, intonation, and tone.33. complementary distribution: the different allophones of the same phoneme never occur in the samephonetic context. when two or more allophones of one phoneme never occur in the same linguistic environment they are said to be in complementary distribution.34. distinctive features: it refers to the features that can distinguish one phoneme from another. if we cangroup the phonemes into two categories: one with this feature and the other without, this feature is called a distinctive feature. v.35. acoustic phonetics deals with the transmission of speech sounds through the air. when a speech soundis produced it causes minor air disturbances (sound waves). various instruments are used to measure the characteristics of these sound waves.36. when the vocal cords are spread apart, the air from the lungs passes between them unimpeded. soundsproduced in this way are described as voiceless; consonants [p, s, t] are produced in this way. but when the vocal cords are drawn together, the air from the lungs repeatedly pushes them apart as it passes through, creating a vibration effect. sounds produced in this way are described as voiced. [b, z, d] are voiced consonants.vi. 37.omit.第三章:词汇参考答案i1~5 a a c b b6~10 b c a d bii. 11~15 f t f t t16~20 f t f f fiii.21. initialism, acronym 22. vocabulary 23. solid, hyphenated, open 24. morpheme25. close, open 26. back-formation 27. conversion 28. morpheme29. derivative, compound 30. affix, bound rootiv.31. blending: it is a process of word-formation in which a new word is formed by combining themeanings and sounds of two words, one of which is not in its full form or both of which are not in their full forms, like newscast (news + broadcast), brunch (breakfast + lunch)32. allomorph: it is any of the variant forms of a morpheme as conditioned by position or adjoiningsounds.33. close-class word: it is a word whose membership is fixed or limited. pronouns, prepositions,conjunctions, articles, etc. are all closed-class words.34. morphological rule: it is the rule that governs which affix can be added to what type of base to forma new word, e.g. –ly can be added to a noun to form an adjective.vi .37. (1) c (2) a (3) e (4) d (5) b第四章:句法参考答案i1~5 d c d d d 6~10 a d d b aii. 11~15 t t t t f16~20 f t f t tiii.21. simple 22. sentence 23. subject24. predicate25. complex 26. embedded 27. open28. adjacency29. parameters 30. caseiv.31. syntax: syntax refers to the rules governing the way words are combined to form sentences in alanguage, or simply, the study of the formation of sentences.32. ic analysis: immediate constituent analysis, ic analysis for short, refers to the analysis of a sentence interms of its immediate constituents – word groups (phrases), which are in turn analyzed into theimmediate constituents of their own, and the process goes on until the ultimate sake of convenience.33. hierarchical structure: it is the sentence structure that groups words into structural constituents andshows the syntactic category of each structural constituent, such as np, vp and pp.34. trace theory: after the movement of an element in a sentence there will be a trace left in the originalposition. this is the notion trace in t-g grammar. it’s suggested that if we have the notion trace, all the necessary information for semantic interpretation may come from the surface structure. e.g. thepassive dams are built by beavers. differs from the active beavers built dams. in implying that all dams are built by beavers. if we add a trace element represented by the letter t after built in the passive as dams are built t by beavers, then the deep structure information that the word dams was originally the object of built is also captured by the surface structure. trace theory proves to be not only theoretically significant but also empirically valid.v.35. an endocentric construction is one whose distribution is functionally equivalent, or approachingequivalence, to one of its constituents, which serves as the center, or head, of the whole. a typicalexample is the three small children with children as its head. the exocentric construction, opposite to the first type, is defined negatively as a construction whose distribution is not functionally equivalent to any of its constituents. prepositional phrasal like on the shelf are typical examples of this type.36. (1) more | beautiful flowers(2) more beautiful | flowers第五章:意义参考答案i1~5 a b d d b 6~10 c a c d aii. 11~15 f f t f t 16~20 t f t t tiii.21. semantics 22. direct 23. reference 24. synonyms25.homophones26. relational27. componential 28. selectional 29. argument 30. namingiv.31. entailment: it is basically a semantic relation (or logical implication), and it can be clarified withthe following sentences:a. tom divorced jane.b. jane was tom’s wife.in terms of truth value, the following relationships exist between these two sentences: when a is true,b must be also true; when b is false, a must also be false. when b is true, a may be true or false.therefore we can say a entails b.32. proposition: it is the result of the abstraction of sentences, which are descriptions of states of affairs andwhich some writers see as a basic element of sentence meaning. for example, the two sentences“caesar invaded gaul” and “gaul was invaded by caesar” hol d the same proposition.33. compositional analysis: it defines the meaning of a lexical element in terms of semantic components, orsemantic features. for example, the meaning of the word boy may be analyzed into three components: human, young and male. similarly girl may be analyzed into human, young andfemale.34. reference: it is what a linguistic form refers to in the real world; it is a matter of the relationshipbetween the form and the reality.v.35. hyponymy, metonymy or part-whole relationship36. (omit.)vi.37. (1)the (a) words and (b) words are male.the (a) words are human, while the (b) words are non-human.(2)the (a) words and (b) words are inanimate.the (a) words are instrumental, while the (b) words are edible.(3)the (a) words and (b) words are worldly or conceptual.the (a) words are material, while the (b) words are spiritual.第七章:语言、文化和社会参考答案i1~5 b c a a c 6~10 d a c a dii. 11~15 f t f f f 16~20 t f t f fiii.21. community22. variety 23. dialectal 24.planning25.sociolects26. stylistic 27. official28. superposed29. vernacular 30. inflectionaliv.31. lingua franca: a lingua franca is a variety of language that serves as a common speech for socialcontact among groups of people who speaks different native languages or dialects.32. regional dialect: regional dialect, also social or class dialect, is a speech variety spoken by themembers of a particular group or stratum of a speech community.33. register: register, also situational dialect, refers to the language variety appropriate for use in particularspeech situations on which degrees of formality depends.34. sociolinguistics: defined in its broadest way, sociolinguistics, a subdiscipline of linguistics, is the studyof language in relation to society. it is concerned with language variation, language use, the impact of extra-linguistic factors on language use, etc.v. 35. american english is not superior to african english. as different branches of english, africanenglish and american english are equal. similar as they are, they are influenced by their respective cultural context and thus form respective systems of pronunciation, words and even grammar.36. in china, chinese has a more strict and complex relationship system. so in chinese there are a lot morekinship words than in english.vi. 37. (omit.)第八章:语言的使用参考答案i1~5 d b c b a 6~10 c b c a dii. 11~15 f t t f f 16~20 f f f t tiii.21. context22. utterance 23. abstract 24. constatives 25. performatives26. locutionary 27. illocutionary28. commissive29. expressive30. quantityiv.31. conversational implicature: in our daily life, speakers and listeners involved in conversation aregenerally cooperating with each other. in other words, when people are talking with each other, they must try to conversesmoothly and successfully. in accepting speakers’ presuppositions, listenershave to assume that a speaker is not trying to mislead them. this sense of cooperation is simply one in which people having a conversation are not normally assumed to be trying to confuse, trick, orwithhold relevant information from one another. however, in real communication, the intention of the speaker is often not the literal meaning of what he or she says. the real intention implied in the words is called conversational implicature.32. performative: in speech act theory an utterance which performs an act, such as watch out (= a warning).33. locutionary act: a locutionary act is the saying of something which is meaningful and can beunderstood.34. horn’s q-principle: (1) make your contribution sufficient (cf. quantity); (2) say as much as you can(given r).v.35. pragmatics is the study of the use of language in communication, particularly the relationshipsbetween sentences and the contexts and situations in which they are used. pragmatics includes the study of(1) how the interpretation and use of utterances depends on knowledge of the real world;(2) how speakers use and understand speech acts;(3) how the structure of sentences is influenced by the relationship between the speaker and thehearer.pragmatics is sometimes contrasted with semantics, which deals with meaning without referenceto the users and communicative functions of sentences.36. yes, b is cooperative. on the face of it, b’s statement is not an answer to a’s question. b doesn’t say“when.” however, a will immediately interpret the s tatement as meaning “i don’t know” or “i am not sure.” just assume that b is being “relevant” and “informative.” given that b’s answer contains relevant information, a can work out that “an accident further up the road” conventionally involves “trafficja m,” and “traffic jam” preludes “bus coming.” thus, b’s answer is not simply a statement of “when the bus comes”; it contains an implicature concerning “when the bus comes.”vi.37. it occurs before and / or after a word, a phrase or even a longer utterance or a text. the context oftenhelps in understanding the particular meaning of the word, phrase, etc.the context may also be the broader social situation in which a linguistic item is used.(1)a. a mild criticism of someone who should have cleaned the room.b. in a language class where a student made a mistake, for he intended to say “tidy.”c. the room was wanted for a meeting. (2)a. a mild way to express disagreement with someone who has complimented on a lady’sappearance. b. a regret that the customer had not taken the dress. c. that she wore a red shirt was not in agreement with the custom on the occasion.第十二章:现代语言学理论与流派参考答案i1~5 b a c a a 6~10 a b d c cii. 11~15 f f t t f 16~20 f t t t fiii.21. synchronic22. phonetics23. j. r. firth 24. systemic25. sociologically26. distribution27. bloomfieldian 28. descriptivism29. innateness30. hypothesis-maker iv.31. fsp: it stands for functional sentence perspective. it is a theory of linguistic analysis which refers to ananalysis of utterances (or texts) in terms of the information they contain.32. cohesion: the cohesion shows whether a certain tagmeme is dominating other tagmemes or isdominated by others.33. lad: lad, that is language acquisition device, is posited by chomsky in the 1960s as a deviceeffectively present in the minds of children by which a grammar of their native language is constructed.34. case grammar: it is an approach that stresses the relationship of elements in a sentence. it is a type ofgenerative grammar developed by c. j. fillmore in the late1960s.v. vi. omit.【篇二:语言学教程(胡壮麟版)综合测试题含标准答案】 class=txt>英语语言学试卷(一)第一部分选择题i. directions: read each of the following statements carefully. decide which one of the fourchoices best completes the statement and put the letter a, b, cor d in the brackets.(2%x10=20%)1.saussure’s distinction and chomsky’s are very similar, but they differ in that ____________. a.saussure took a sociological view of language while chomsky took a psychological point of viewb. saussure took a psychological view of language while chomsky took a sociological point ofviewc. saussure took a pragmatic view of language while chomsky took a semantic point of viewd. saussure took a structural view of language while chomsky took a pragmatic point of view2. language is a system of ____________ vocal symbols used for human communication. a.unnatural b. artificialc. superficiald. arbitrary3. we are born with the ability to acquire language,_______________.a. and the details of any language system are genetically transmittedb. therefore, we needn’t learn the details of our mother tonguec. but the details of language have to be learnt.d. and the details are acquired by instinct4. a(n)________ is a phonological unit of distinctive value. it isa collection of distinctivephonetic features. a. phone b. allophonec. phonemed. sound5. the morpheme –ed in the word “worked” is a(n) __________ morpheme. a. derivationalb. inflectionalc. freed. word-forming6. wh-movement is __________ in english which changes a sentence from affirmative tointerrogative. a. obligatoryb. optionalc. selectionald. arbitrary7. naming theory, one of the oldest notions concerning meaning, was proposed by_____________. a. griceb. platoc. saussured. ogden and richards8. “john married a blond heiress.”__________ “john married a blond.” a. is synonymous withb. is inconsistent withc. entailsd. presupposes9. in semantic analysis of a sentence, the basic unit is called ____________, which is theabstraction of the meaning of a sentence. a. utterance b. referencec. predicationd. morpheme10. in austin’s speech act theory, ___________ is the act of expressing the speaker’s intention; itis the act performed in saying something. a. a perlocutionary act b. alocutionary actc. a constative actd. an illocutionary act第二部分非选择题ii. directions: fill in the blank in each of the following statements with one word, the first letter ofwhich is already given as a clue. note that you are to fill in one word only, and you are notallowed to change the letter given. (1%x10=10%)11. p___________ relates the study of language to psychology. it aims to answer such questionsas how the human mind works when people use language.12. a d_________ study of language is a historical study; it studies the historical development oflanguage over a period of time.13. language is a system, which consists of two sets of structures, or two levels. at the lower level,there is a structure of meaningless sounds, which can be combined into a large number ofmeaningful units at the higher level. this design feature is called d___________.14. the articulatory apparatus of a human being is containedin three important areas: thepharyngeal cavity, the o_________ cavity and the nasal cavity.15. the localization of cognitive and perceptual functions in a particular hemisphere of the brain iscalled l_____________.16. s_____________ features such as stress, tone and intonation can influence the interpretationof meaning.17. phrase structure rules can generate an infinite number of sentences, and sentences with infinitelength, due to their r_________ properties.18. h__________ refers to the phenomenon that words having different meanings are identical in sound or spelling, or in both.19. some important missions of historical linguists are to identify and classify families of related languages in a genealogical family tree, and to reconstruct the p____________, the original form of a language family that has ceased to exist.20. in sociolinguistics, speakers are treated as members of social groups. the social group isolated for any given study is called the speech c___________.iii. directions: judge whether each of the following statements is true or false. put a t for true or f for false in the brackets in front of each statement. (2%x10=20%)( ) 21. linguists believe that whatever occurs in the language people use should be described and analyzed in their investigation.( ) 22. language is arbitrary in the sense that there is no intrinsic connection between words and what these words actually refer to.( ) 23. the conclusions we reach about the phonology of one language can be generalized into the study of another language.( ) 24. the meaning-distinctive function of the tone is especially important in english because english, unlike chinese, is a typical tone language.( ) 25. the syntactic rules of any language are finite in number, and yet there is no limit to the number of sentences native speakers of that language are able to produce and comprehend.( ) 26. when we think of a concept, we actually try to see the image of something in our mind’s eye every time we come across a linguistic symbol.( ) 27. all utterances can be restored to complete sentences. for example, “good morning!” can be restored to “i wish you a good morning.”( ) 28. two people who are born and brought up in the same town and speak the same regional dialect may speak differently because of a number of social factors.( ) 29. black english is linguistically inferior to standard english because black english is not as systematic as standard english.( ) 30. any child who is capable of acquiring some particular human language is capable of acquiring any human language spontaneously and effortlessly.iv. directions: explain the following terms. (3%x10=30%)31. parole:32. broad transcription:33.allophones:34.phrase structure rules:35.context36.historical linguistics:37.standard language:38.linguistic taboo:39.acculturation:40.care-taker speech:v. answer the following questions. (10%x2=20%)41. enumerate three causes that lead to the systematic occurrence of errors in second language acquisition and give your examples.42. english has undergone tremendous changes since its anglo-saxon days. identify the major periods in its historicaldevelopment and name major historical events that led to the transition from one period to the next.英语语言学试卷答案(一)第一部分选择题i. directions: read each of the following statements carefully. decide which one of the four choices best completes the statement and put the letter a, b, c or d in the brackets.(2%x10=20%)1. a2. d3. c4. c5.b6. a7. b8. c9. c 10. d第二部分非选择题ii. directions: fill in the blank in each of the following statements with one word, the first letter of which is already given as a clue. note that you are to fill in one word only, and you are not【篇三:语言学教程第四版练习第一章】inguisticsi. mark the choice that best completes the statement.1.all languages’ have three major components: a sound system ,a system of___and a system of semantics.a. morphologyb. lexicogrammarc. syntaxd. meaning2.which of the following words is entirely arbitrary?3.the function of the sentence water boils at 100 degrees centigrade is ___.a.interpersonalb.emotivermatived.performative4.in chinese when someone breaks a bowl or a plate the host or the people present are likely to say 碎碎(岁岁)平安as a means of controlling the forces which they believe might affect their lives. which function does it perform?a.interpersonalb.emotivermatived.performative5.which of the following property of language enables language users to overcome the barriers caused by time and place of speaking (due to this feature of language, speakers of a language are free to talk about anything in any situation)?a. transferabilityb. dualityc. displacementd. arbitrariness6. what language function does the following conversation play?(the two chatters just met and were starting their conversation by the following dialogue.)a:a nice day, isn’t it?b : right! i really enjoy the sunlight.a. emotiveb. phaticc. performatived. interpersonal7.------- refers to the actual realization of the ideal language user’s knowledge of the rules of his language in utterances.8.when a dog is barking, you assume it is barking for something or at someone that exists here and now. it couldn’t be sorrowful for some lost love or lost bone. this indicates that dog’s language does not have the feature of --------- .a. referenceb. productivityc. displacementd.duality9.--------- answers such questions as we as infants acquire our first language.a. psycholinguisticsb. anthropological linguisticsc. sociolinguisticsd. applied linguistics10.-------- deals with the study of dialects in different social classes in a particular region.a. linguistic theoryb. practical linguisticsc. sociolinguisticsd. comparative linguisticsii. mark the following statements with “t” if they are true or “f” if they are false.(10%)1. the widely accepted meaning of arbitrariness was discussed by chomsky first.2. for learners of a foreign language, it is arbitrariness that is more worth noticing than its conventionality.3. displacement benefits human beings by giving them the power to handlegeneralizations and abstractions.4. for jakobson and the prague school structuralists, the purpose of communication is to refer.5. interpersonal function is also called ideational function in the framework of functional grammar.6. emotive function is also discussed under the term expressive function.7. the relationship between competence and performance in chomsky’s theory is that between a language community and an individual language user.8.a study of the features of the english used in shakespeare’s time is an example of the diachronic study of language.9.articulatory phonetics investigates the properties of the sound waves.10.the nature of linguistics as a science determines its preoccupation with prescription instead of description.iii.fill in each of the following blanks with an appropriate word. the first letter of the word is already given(10%)1. nowadays, two kinds of research methods co-exist in linguistic studies, namely,qualitative and q__________ research approaches.2. in any language words can be used in new ways to mean new things and can becombined into innumerable sentences based on limited rules. this feature is usually termed as p__________.nguage has many functions. we can use language to talk about language. this function is m__________function.4.the claim that language originated by primitive man involuntary making vocal noises while performing heavy work has been called the y_theory.5.p________ is often said to be concerned with the organization of speech within specific language, or with the systems and patterns of sounds that occur in particular language.6.modern linguistics is d_ in the sense that linguist tires to discover what language is rather than lay down some rules for people to observe.7.one general principle of linguistics analysis is the primacy of s___________over writing.8.the description of a language as it changes through time is a d___________ linguistic study.9.saussure put forward the concept l__________ to refer to the abstract linguistic system shared by all members of a speech community.10.linguistic potential is similar to saussure’ s langue and chomsky’ s c__________.iv. explain the following concepts or theories.1.design features2.displacement。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《Perl语言入门习题答案》练习1、写一个程序,计算半径为的圆的周长。

圆周长等于2π(π约为)乘以半径。

答案为。

-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth,$r=;$g=*2*;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。

如果,用户输入,则应得到和上题一样的结果。

-----------------------/home/confish/perl/girthpro#!/usr/bin/perl -w`#a better one to calculate girthprint"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is ".$r*2*."\n";;}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。

】-----------------------/home/confish/perl/girthzero#!/usr/bin/perl -w#calculate the girth and print 0 when the radius is lower than 0print"enter the radius of the line\n";chomp($r=<STDIN>);if($r>0)&{print"the girth of the circle is $r*2*\n";}else{print"the girth of the circle is 0\n";}-----------------------/home/confish/perl/girthzero$1、2、3:(一起实现的)#!/usr/bin/perl -w$pai=;print "Please Input Radius:";$r=<STDIN>;if ( $r lt 0 ){print "The circumference is 0\n";@}else{$l=$r*2*$pai;printf "The circumference is %.1f\n",$l;}4、写一个程序,用户能输入2 个数字(不在同一行)。

输出为这两个数的积。

-----------------------/home/confish/perl/product#!/usr/bin/perl -w、#print the two number'sprint"enter the two numbers:\n";chomp($m=<STDIN>);chomp($n=<STDIN>);print"the product of the two numbers are ".$m*$n."\n";-----------------------/home/confish/perl/product5、写一个程序,用户能输入1 个字符串和一个数字(n)(不在同一行)。

输出为,n 行这个字符串,1 次1 行(提示,使用“x”操作符)。

例如,如果用户输入的是“fred”和“3”,则输出为:3 行,每一行均为fred。

如果输入为“fred”和“299792”,则输出为299792 行,每一行均为fred'-----------------------/home/confish/perl/printer#!/usr/bin/perl -w#print a string certain times depend on the usr'sprint"enter a string and a number:\n";$str=<STDIN>;chomp($num=<STDIN>);print ${str}x$num;-----------------------/home/confish/perl/printer<练习1、写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。

如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Windows 系统中使用CTRL+Z.------------------------------------/home/confish/reprint#!/usr/bin/perl -w#read some input and print them in reverseprint "enter the string please:\n";@str=reverse <STDIN>;]print "\nthe reverse strings are:\n@str";------------------------------------/home/confish/reprint2、写一个程序,读入一串数字(一个数字一行),将和这些数字对应的人名(下面列出的)输出来。

(将下面的人名列表写入代码中)。

fred betty barney dino Wilma pebbles bamm-bamm 例如,当输入为1,2,4 和2,则输出的为fred, betty, dino, 和betty------------------------------------/home/confish/num_to_name#!/usr/bin/perl -w#read some numbers and output the match【$i=0;@names=qw /fred betty barney dino Wilma pebbles bamm-bamm/;print"enter the numbers please:\n";chomp(@nums=<STDIN>);foreach(@nums){@re=@names;while($i ne $_)/{$n=shift( @re);$i++;}$i=0;print $n,"\n";}------------------------------------/home/confish/num_to_name(3、写一个程序,将一些字符串(在不同的行中)读入一个列表中。

然后按ASCII 顺序将它们输出来。

也就是说,当输入的字符串为fred, barney, wilma, betty,则输出为barney betty fred wilma。

分别在一行或不同的行将之输出。

------------------------------------/home/confish/sort_str#!/usr/bin/perl -w#read some strings and sort them inchomp(@str=sort<STDIN>);#@str=sort<STDIN>; will print them in diffrent linesprint @str,"\n";《------------------------------------/home/confish/sort_str练习1、写一个名为&total 的子程序,返回一列数字的和。

提示:子程序不应当有任何的I/O 操作;它处理调用的参数,返回处理后的值给调用者。

结合下面的程序来练习,它检测此子程序是否正常工作。

第一组数组之和25。

my @fred = qw{ 1 3 5 7 9 };my $fred_total = &total(@fred);print "The total of \@fred is $fred_total.\n";'print "Enter some numbers on separate lines: ";my $user_total = &total(<STDIN>);print "The total of those numbers is $user_total.\n";--------------------------------/home/confish/perl/subr#!/usr/bin/perl -w#a subroutine named total returns sum ofsub total{】foreach $n(0..$#_){$sum+=$_[$n];}$sum;}my@fred=qw{1 3 5 7 9};—my $fred_total=&total(@fred);print"The total of \@fred is $fred_total.\n";print"Enter some numbers on separate lines:\n";my $user_total=&total(<STDIN>);print"The total of those numbers is $user_total.\n";--------------------------------/home/confish/perl/subr2、利用上题的子程序,写一个程序计算从1 到1000 的数字的和。

[--------------------------------/home/confish/perl/suber#!/usr/bin/perl -w#use the subroutine in last program to get the sum ofsub total{foreach $n(0..$#_){$sum+=$_[$n];;}$sum;}@num=(1..1000);$sum=&total(@num);print"The sum of 1..1000 is $sum\n";--------------------------------/home/confish/perl/suber'3、额外的练习:写一个子程序,名为&above_average,将一列数字作为其参数,返回所有大于平均值的数字(提示:另外写一个子程序来计算平均值,总和除以数字的个数)。

相关文档
最新文档