Pascal程序设计初步练习题含答案.docx
- 文档编号:24710621
- 上传时间:2023-05-31
- 格式:DOCX
- 页数:14
- 大小:32.14KB
Pascal程序设计初步练习题含答案.docx
《Pascal程序设计初步练习题含答案.docx》由会员分享,可在线阅读,更多相关《Pascal程序设计初步练习题含答案.docx(14页珍藏版)》请在冰豆网上搜索。
Pascal程序设计初步练习题含答案
Pascal练习一
1.工人每工作一小时可得工资80元,求工作130小时的工资。
进入Qpascal,并打入以下程序:
1programWages(input,output);
2varh,r,w:
integer;
3begin
4h:
=130;
5r:
=80;
6w:
=h*r;
7writeln(w)
8end.
a)程序中三个变量代表甚么资料?
变量
代表资料
值
h
工作的总小时数目
130
r
每小时的时薪
80
w
本月所得的工资
11400
b)将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
1
1
4
0
0
c)如果将行7改为‘Totalwages=’,如下列所示:
writeln(‘Totalwages=’,w)
将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
T
o
t
a
l
w
a
g
e
s
=
1
1
4
0
0
d)试在行6和行7之间加多两程序语句,使程序产生以下的输出。
Totalworkinghours=130
Hourlyrate=80
Totalwages=10400
writeln(‘Totalworkinghours=’,h);
writeln(‘Hourlyrate=’,r);
e)用有意义的变量名称,将(d)部份的程序重写。
将程序储存于A磁盘。
Pascal练习二
1.计算某学生在三次考试所得的平均分。
进入Qpascal,并打入以下程序:
1programAverageMark(input,output);
2varExam1,Exam2,Exam3:
integer;
3begin
4Exam1:
=65;
5Exam2:
=80;
6Exam3:
=72;
7Average:
=(Exam1+Exam2+Exam3)/3;
8writeln(‘Theaveragemarkis’,Average)
9end.
a)程序中四个变量代表甚么资料?
变量
代表资料
值
Exam1
在第一次考试所得的分数
65
Exam2
在第二次考试所得的分数
80
Exam3
在第三次考试所得的分数
72
Average
在三次考试所得的平均分
72.33
b)i)执行程序时,计算机显示器显示出一程序错误讯息,这讯息是甚么?
UnknownIdentifier‘Average’
ii)
程序有甚么错误?
在程序说明部分欠缺了变量‘Average’的宣告。
iii)
如何修改这程序?
在第2与第3行中间加入以下:
Average:
real;
c)
将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
d)该名学生在新一次考试四取得83分,请修改程序以计算新的平均分。
programAverageMark;
varExam1,Exam2,Exam3,Exam4:
integer;Average:
real;
begin
Exam1:
=65;
Exam2:
=80;
Exam3:
=72;
Exam4:
=83;
Average:
=(Exam1+Exam2+Exam3+Exam4)/4;
writeln(‘Theaveragemarkis’,Average)
end.
Pascal练习三
1.计算某消售所得的盈利。
进入Qpascal,并打入以下程序:
1programFindProfit(input,output);
2varCost,SellPrice,Profit:
real;
3begin
4Cost:
=45000;
5SellPrice:
=52500.5;
6Profit:
=SellPrice-Cost;
7writeln(‘Theprofitis’,Profit:
9:
2)
8end.
a)在说明部分中,变量宣告采用了甚么数据类型?
实数类real
b)将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
T
h
e
p
r
o
f
i
t
i
s
7
5
0
0
.
5
0
c)假如将行7的输出语句改写为:
writeln(‘Theprofitis’,Profit)
再将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
T
h
e
p
r
o
f
i
t
i
s
7
.
5
0
0
5
0
0
0
0
0
0
0
0
0
0
0
E
+
0
0
0
3
d)在行7输出语句中的:
9:
2是甚么意思?
:
9表示总显示长度为9个字符位,:
2表示小数字为2个。
e)试修改程序以产生以下输出:
SellingPrice52500.50
Cost45000.00
-----------------------------------------
Profit7500.50
行7以后需改为:
writeln(‘----------------------------------------’);
writeln(‘Profit’,Profit:
9:
2)
Pascal练习四
1.进入Qpascal,并打入以下程序:
1programOutputTest1(input,output);
2begin
3writeln(135);;
4writeln(135:
10);
5write(‘TestingPrintout’);
6writeln;
7writeln(135.7:
1);
8writeln(135.7:
10);
9writeln(135.7:
0:
1);
10writeln(135.7:
8:
2);
11writeln(0.001357:
10:
4)
12end.
将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
1
3
5
1
3
5
T
e
s
t
i
n
g
P
r
i
n
t
o
u
T
1
.
4
E
+
0
0
0
2
1
.
3
E
+
0
0
0
2
1
3
5
.
7
1
3
5
.
7
0
0
.
0
0
1
4
2.进入Qpascal,并打入以下程序:
1programOutputTest2(input,output);
2varA,B,C:
integer;D:
real;
3begin
4A:
=2;
5B:
=4;
6C:
=6;
7D:
=(A+B)*C/2;
8write(‘A=’,A);
9writeln(‘B=’:
4,B);
10write(‘C=’,C);
11writeln(‘D=’:
4,D:
6)
12end.
将程序编译(Make-Compile)后,执行程序(Run-Go),写下屏幕所看到输出。
A
=
2
B
=
4
C
=
6
D
=
1
.
8
E
+
0
0
0
1
Pascal练习五
1.进入Qpascal,并打入以下程序:
1programInputTest(input,output);
2vara,b,c,d,e,f,g,h:
integer;
3begin
4readln(a);
5readln(b,c);
6readln(d,e,f);
7readln(g,h);
8writeln(a,',',b,',',c,',',d,',',e,',',f,',',g,',',h)
9end.
将程序编译(Make-Compile)后,执行程序(Run-Go),并以下列四行作为数据输入,
12345
56789
1112131415
1516171819
最后写下屏幕所看到的输出。
1
5
6
1
1
1
2
1
3
1
5
1
6
2.进入Qpascal,并打入以下程序:
1programInputTest(input,output);
2vara,b,c,d,e,f,g,h:
integer;
3begin
4read(a);
5readln(b,c);
6read(d,e,f);
9readln(g,h);
10writeln(a,',',b,',',c,',',d,',',e,',',f,',',g,',',h)
9end.
将程序编译(Make-Compile)后,执行程序(Run-Go),并以第一部分之四行输入作为数据输入,
最后写下屏幕所看到的输出。
1
2
3
5
6
7
8
9
Pascal练习六
1.某人想编写一个有下列输出的PASCAL程序:
程序输出
Pleaseenteraninteger:
2
Pleaseenteranotherinteger:
3
60
Pleaseenterarealnumber:
5.25
Yourrealnumberis5.2500
他所编写的程序如下(内有多处错误):
10)programBugs(input,output)
20)consttimes:
=10,
30)varN2;integer;
40)N3:
char;
50)begin
60)writeln('Pleaseenteraninteger:
');
70)readln(N1);
80)writeln('Pleaseenteranotherinteger:
');
90)readln(N2);
100)writeln(N1*N2*times);
110)write('Pleaseenterarealnumber:
');
120)readln(N3);
130)writeln(N3:
1:
1)
140)end.
程序中有几处错误,试找出来并加以订正。
行号
修改后的语句
10
programBugs(input,output);
20
consttimes=3;
30
varN1,N2:
integer;
40
N3:
real;
60
write(‘Pleaseenteraninteger:
’);
80
write(‘Pleaseenteranotherinteger:
’);
125
writeln;
130
writeln(N3:
1:
4)
Pascal练习七
1.某人想编写一个有下列输出的PASCAL程序:
程序输出
Whatisthecoefficientofthex^2term?
2
Whatisthecoefficientofthexterm?
3
Whatistheconstantterm?
5
Whatisthevalueofx?
5
Thepolynomialis2x^2+3x+5
Whenx=5,thepolynomial=70
他所编写的程序如下(内有多处错误):
1)programPolynomial(input,output);
2)varcoef0,coef1,coef2:
integer;
3)x:
real;
4)begin
5)write(Whatisthecoefficientofthex^2term?
);
6)readln(coef2);
7)write('Whatisthecoefficientofthexterm?
');
8)readln(coef1);
9)write('Whatistheconstantterm?
');
10)readln(coef0);
11)writeln('Whatisthevalueofx?
');
12)readln(coef1);
13)writeln;
14)writeln('Thepolynomialis',coef1,'x^2+',coef2,
15)'x+',coef0);
16)writeln('Whenx=',x,',thepolynomial=',
17)coef2*x*x+coef1*x+coef0)
18)end.
试完成下表,替以上程序除错。
行号
修改后的语句
3
x:
integer;
5
write('Whatisthecoefficientofthex^2term?
');
11
write('Whatisthevalueofx?
');
12
readln(x);
14
writeln('Thepolynomialis',coef2,'x^2+',coef1,'x+',coef0);
Pascal练习八
.试写PASCAL程序计算通过两点的直线的斜率(slope),而两点的坐标是由使用者自行输入。
(所有在“:
”号后的数字皆由使用者自行输入)
斜率的计算公式如下:
斜率=
程序输出
Whatisx-coordinateoffirstpoint:
5
Whatisy-coordinateoffirstpoint:
9
Whatisx-coordinateofsecondpoint:
12
Whatisy-coordinateofsecondpoint:
18
Theslopeofthestraightlineis1.2875
将以下程序打入QPascal内(并尝试在横线上填上适当答案):
programFindSlope(input,output);
varx1,x2,y1,y2:
integer;
slope:
real;
begin
write(‘Whatisx-coordinateoffirstpoint:
’);
readln(x1);
write(‘Whatisy-coordinateoffirstpoint:
’);
readln(y1);
write(‘Whatisx-coordinateofsecondpoint:
’);
readln(x2);
write(‘Whatisy-coordinateofsecondpoint:
’);
readln(y2);
slope:
=(y2-y1)/(x2-x1);
writeln;
writeln(‘Theslopeofthestraightlineis’,slope)
end.
Pascal练习九
试写一个程序,其能跟据用者所输入的半径去计算圆形的面积
圆形面积的计算公式如下:
圆形面积=
假设π=3.14
如果输入的半径是30.0,屏幕输出会如以下:
(所有在“:
”号后的数字皆由使用者自行输入)
程序输出
Entertheradiusofthecircle:
30.0
Theareaofthecircleis2.826000000000000E+0003
将以下程序打入QPascal内(并尝试在横线上填上适当答案):
以下是一个PASCAL程序:
1)programFindAreaOfCircle(input,output);
2)constPi=3.14;
3)varradius,area:
real;
4)begin
5)write(‘Entertheradiusofthecircle:
’);
6)readln(radius);
7)writeln;
8)area:
=Pi*radius*radius;
9)writeln(‘Theareaofthecircleis’,area)
9)end.
如果输入的半径是225.0,屏幕输出会是甚么﹖
程序输出
Entertheradiusofthecircle:
225.0
Theareaofthecircleis1.5896250000000000E+0005
1、用字符输出一个等边三角形。
2、a,b,c分别等于1、12、123,把它们按向左对齐、向右对齐的方式打印出来。
3、输入一个四位整数,把它的各位数字倒序输出。
(提示:
用MOD和DIV运算完成)
4、从键盘上读入小写的"pascal",利用CHR()和ORD()函数,输出大写的"PASCAL"。
5、从键盘上读入长方形的边长a,b,计算它的面积和周长,输出。
6、输入一个秒数把它转换为一个时、分、秒时间格式。
7、从键盘上读入一个实数,利用ROUND()和TRUNC()函数,输出该实数本身、整数部分、小数部分、四舍五入后的值。
要求:
分三行输出;输出实数本身时,格式与读入时相同;整数部分、小数部分在同一行输出;其它各占一行。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Pascal 程序设计 初步 练习题 答案