学习一种新的编程语言所要做的15个练习(中英文转载)

阅读: 评论:0

学习一种新的编程语言所要做的15个练习(中英文转载)

学习一种新的编程语言所要做的15个练习(中英文转载)

  学习一种新的编程语言所要做的15个练习(中英文转载)--from译言网


  虽然我已经可以使用很多种编程语言进行工作,但我的工作常常会要求我快速掌握一门新的语言。我没有选择去阅读几百页的程序手册,而是快速浏览10到15页的教程(可以在Google中搜索),并把程序语言的语法参考说明印在小卡片上(在google里搜索language to learn+reference card就能找到)。

  首先,我会熟悉这种程序语言的编译器、编译选项、编辑器或集成开发环境的的快捷键和小技巧,写一个简单的“你好世界”程序,编译并运行它,再用调试器进行简单的调试,如设置断电、查看变量值、跳转到某一位置等。

  为了能够快速地掌握一种新的程序语言,我会做以下几个练习。注意,有些程序对初学者来说是很困难的。

1、用无限循环语句显示一系列数字(1、2、3、4、5……),并设置当用户按下某个按钮时(如ESC键)程序就会中止;

2、斐波那契数列、交换两个变量的值、从一组数据中找出最大最小值等;

3、让用户输入一些数字或字符串,以升序或降序进行排列;

4、雷诺数的计算公式是(D*v*rho)/mu,其中D为直径,v为速度,rho为密度,mu为黏性。编写一个程序,接收一组数据并计算雷诺数。如果小于2100,则显示“层流”;在2100至4000之间,则显示“暂态流”;大与4000则显示“湍流”(使用分支语句if else then);

5、修改上面的程序,显示“开始新的计算?(是/否)”,如果选“是”,则重新输入一组数据;如果选“否”,则退出程序(使用循环语句)。如果mu的值为0,程序是否会提示“除数为0”的错误?或是给出“程序崩溃”的提示?怎样处理这种情况呢?该程序语言里是否提供了这样的机制?(异常处理)

6、编写一个科学计算器,包括加、减、乘、除、平方、立方、平方根、正弦、余弦、正切、阶乘、倒数、取模等操作;

7、用不同的格式进行输出(比如四舍五入到5位数字、截取前四位数字、用0填充左边或右边、左右对齐等)(输入输出操作)

8、将一个文本文件转换成网页文件(文件输入输出操作、字符串操作)

9、时间和日期:获取系统当前时间并将其转换成不同的格式;

10、创建一个文件名中含有时间日期的文件;

12、输入一个HTML表格,将其转换为以逗号或制表符分隔的文件;

13、实现自动换行的功能(看看Windows里记事本是怎样做的)

14、在数组的开头、结尾和中间添加或删除元素;

15、该程序语言是否支持以下特性:操作符重载、虚函数、引用、指针等;是否有命名空间、包、模块等;了解一下吧。

中文原文地址:  点击打开链接

-------------------------------------------------

I've working knowledge of a bunch of programming languages but job demands to learn a new language frequently in a short time. Instead of reading hundreds manual/book pages, I quickly read 10-15 pages of tutorial or primer. (As you know google is the best search engine to look for such stuff). I keep printed copy of the language syntax reference card handy. (There are many reference cards available over internet. Type in 'language to learn' + 'reference card' in google.)



 



First of all, get familiar with Compiler, compiler option, editor shortcuts or integrated development environment (IDE). Start with a simple 'Hello World' program. Compile it. Use basic functionalities of debugger like setting break points, printing variable values, moving to the next or specific position, stopping debugger etc.



 



To grasp basics of a new language quickly, here are the exercises I use. Remember some programs may not good for beginners.



 



(1) Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).



 



(2) Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.



 



(3) Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.



 



(4) Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity
Write a program that will accept all values in appropriate units (Don't worry about unit conversion) 
If number is < 2100, display Laminar flow, 
If it.s between 2100 and 4000 display 'Transient flow' and 
if more than '4000', display 'Turbulent Flow' (If, else, )



 



(5) Modify the above program such that it will ask for 'Do you want to calculate again (y/n), 
if you say 'y', it'll again ask the parameters. If 'n', it'll exit. (Do while loop)



 



While running the program give value mu = 0. See what happens. Does it give 'DIVIDE BY ZERO' error? 
Does it give ' dump?'. How to handle this situation. Is there something built 
in the language itself? (Exception Handling)



 



(6) Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, 
sin, cos, tan, Factorial, inverse, modulus



 



(7) Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, 
padding zeros to the right and left, right and left justification)(Input output operations)



 



(8) Open a text file and convert it into HTML file. (File operations/Strings)



 



(9) Time and Date : Get system time and convert it in different formats 'DD-MON-YYYY', 'mm-dd-yyyy', 'dd/mm/yy' etc.



 



(10) Create files with date and time stamp appended to the name



 



(11) Input is HTML table, Remove all tags and put data in a comma/tab separated file.



 



(12) Extract uppercase words from a file, extract unique words



 



(13) Implement word wrapping feature (Observe how word wrap works in windows 'notepad')



 



(14) Adding/removing items in the beginning, middle and end of the array.



 



(15) Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.



 



Is there something called 'namespace / package / module' supported by your language? (Name mangling) - Read More on this


本文发布于:2024-02-03 05:40:20,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170691001849012.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:要做   中英文   编程语言
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23