level 1
八月摄Dh
楼主
Perimeters of Regular Polygons
This assignment introduces the following concepts:
Formatting output using commas “,” causes each data field to start at the next default TAB
READ and DATA statements go hand in hand. Your program can have one or more DATA statements
anywhere. To access the data in DATA statements, use READ statements. Each time you do a READ
The next DATA value is obtained in order top to bottom in DATA statements, and left to right within a
DATA statement. If you read past the end of the data, you get an error. If you read a string into a
number variable, you get an error. It is NOT an error to stop reading before all the data is read.
The DO WHILE – LOOP has the format
DO WHILE some_test
loop_code
LOOP
Example:
CLS
DATA 1,2,3,-1
READ N ' get the first value to prime the loop
DO WHILE N >= 0
SUM = SUM + N
PRINT N, SUM
READ N
LOOP
END
Write a QBASIC computer program with a READ statement and a DATA statement that lists regular
polygons and the side length of each. Your program will read the data until “Stop”. The data statement
DATA Square, 5, Octagon, 3, Triangle, 1, Hexagon, 2.5, Pentagon, 2, Stop
Use the following formulas to calculate the perimeter:
For each regular polygon read, the program will output the polygon and its perimeter, as follows:
Triangle 3 * length
Square 4 * length
Pentagon 5 * length
Hexagon 6 * length
Octagon 8 * length
Use a comma between each field to line up the output columns.
POLYGON PERIMETER
Square 20
Octagon 24
Triangle 3
Hexagon 15
Pentagon 10
Use a SELECT CASE structure within a DO WHILE – LOOP to do this.
2015年12月04日 00点12分
1
This assignment introduces the following concepts:
Formatting output using commas “,” causes each data field to start at the next default TAB
READ and DATA statements go hand in hand. Your program can have one or more DATA statements
anywhere. To access the data in DATA statements, use READ statements. Each time you do a READ
The next DATA value is obtained in order top to bottom in DATA statements, and left to right within a
DATA statement. If you read past the end of the data, you get an error. If you read a string into a
number variable, you get an error. It is NOT an error to stop reading before all the data is read.
The DO WHILE – LOOP has the format
DO WHILE some_test
loop_code
LOOP
Example:
CLS
DATA 1,2,3,-1
READ N ' get the first value to prime the loop
DO WHILE N >= 0
SUM = SUM + N
PRINT N, SUM
READ N
LOOP
END
Write a QBASIC computer program with a READ statement and a DATA statement that lists regular
polygons and the side length of each. Your program will read the data until “Stop”. The data statement
DATA Square, 5, Octagon, 3, Triangle, 1, Hexagon, 2.5, Pentagon, 2, Stop
Use the following formulas to calculate the perimeter:
For each regular polygon read, the program will output the polygon and its perimeter, as follows:
Triangle 3 * length
Square 4 * length
Pentagon 5 * length
Hexagon 6 * length
Octagon 8 * length
Use a comma between each field to line up the output columns.
POLYGON PERIMETER
Square 20
Octagon 24
Triangle 3
Hexagon 15
Pentagon 10
Use a SELECT CASE structure within a DO WHILE – LOOP to do this.