|
A farmer wishes to build a fence around his field. Figure 1 gives an example of a field with four corners. The positions of the corners are measured as (x, y) co-ordinates relative to the farmhouse (0, 0). Write a C++ program to calculate how long the fence must be, given the number of corners and the position of each of them.
一个农民想建个维栏,Figure 1给出4个角。每个角得位置已屋子(0,0)为坐标,用C++ 程序去求维栏得长度,坐标给出如下图。
Figure 1 Farmer's Field
Part A.
A1. The programme should operate as follows:
程序应如下操作:
· Requests the user (i.e. the farmer) to enter the number of corners and then asks for the co-ordinates of each corner relative to the farmhouse.(Use a loop and store the x and y co-ordinates of each corner of the field in separate arrays.)
· 要求(农民)输入角的数量,然后输入每个角相对屋子(0。0)的坐标。(用LOOP语言和分别储存每个角的坐标(x,y))
Displays the co-ordinates of each corner. (Use a loop.)
(陈列出每个角的坐标(用loop))
Calculates the distances between all corners. (Use the following formula to calculate the distance between any two corners i and i-1: . )
(计算每个角之间的距离(用 方程去计算每个角之间的距离))
Displays the distances between all corners. Example:
(陈列出所有每个角间的距离,例如:)
The distance between corner 1 (1,1) and corner 2 (2,2) is: 1.41
Calculates and displays the total length of the fence.
(角1(1,1)和角2(2,2)间的的是:1。41
计算和列出栏的总长度)
· The user should be able to repeat these steps as many times as required.
A2. Test your programme. Provide sufficient evidence of testing.
(使用者应该能重复可以做这些步骤像它要求的这么多
测试你的程序)
Part B.
B1. Implement a simple option menu to make your program easier to use.
B1(运用简单的操作去做程序,可以容易的用)
B2. Improve your programme. Consider cases such as choosing an option that is not available in the menu, starting from option 2,3, etc. instead of 1, entering a negative number of corners, entering the same co-ordinates for two or more corners, entering corner co-ordinates that form a line, not a field, etc.). Provide an option to change the number of corners or their co-ordinates without exiting the menu or re-entering those co-ordinates that remain unchanged.
改善你的计划.例如认为这不是一个选择可供选择的菜单,选择由2,3,等不是一日进入负多少角落,进入同一统筹为两个或两个以上的角落,进入角落协调,形成一条线,不是一个领域,等等).提供一个选择改变一些死角或协调无退出菜单或重新进入那些协调,维持不变.
[ 本帖最后由 iptton 于 2006-12-11 18:20 编辑 ] |
|