PASCAL 程序设计简单题目~急求完整答案~

高一的同学们学习了PASCAL程序设计,请你给小学生编写一个加法练习程序,每套10道题,每题正确的加10分,错误的不给分,并计算总分。

说明:1、10道题用FOR循环语句实现。

2、每个加数不超过1000,用随机函数random(n)产生。

3、小学生的答案用read()语句读入。

4、判断正误用IF语句实现。

5、程序头和变量说明如下:

program ss(input,output);

var

a,b,c,i,s:integer;

begin

randomize;{使每次运行时产生的随机数都不相同}
program ss(input,output);
var
a,b,c,i,s:integer;
begin
randomize;
s:=0;
for i:=1 to 10 do
begin
a:=random(100);
b:=random(100);
writeln(a,'+',b);
read(c);
if a+b=c then
begin
s:=s+10;
writeln('correct');
end
else
writeln('wrong');
end;
writeln('total=',s);
end.

第1个回答  2007-01-15
program SS;
//Created By Chely
// 2007-01-15
{$APPTYPE CONSOLE}

uses
SysUtils,
Math;

type
TExamMGR = class
private
FScore: Integer;

procedure ShowTitle();
procedure ShowScore();
procedure ShowEndTip();
public
constructor Create();

procedure BeginExam();

property Score: Integer read FScore;

end;
var
ExamMGR: TExamMGR;
{ TExamMGR }

procedure TExamMGR.BeginExam;
var
I: Byte;
V1,V2,R: Integer;
begin
//Todo: Flow For ExamMGR.BeginExam;
//Step1: Show Title;
//Step2: Begin
//Step3: ShowScore;
//Step4: Show Query Infos;

Self.ShowTitle;

for I := 0 to 9 do
begin
Randomize();
V1 := RandomRange(0,1000);
V2 := RandomRange(0,1000);

Writeln(I + 1,'(th) Test: ',V1,' + ',V2,' = ');
Readln(R);
if R = V1 + V2 then
Inc(Self.FScore,1);
end;

Self.ShowScore;
Self.ShowEndTip;
end;

constructor TExamMGR.Create;
begin
inherited;

Self.FScore := 0;
end;

procedure TExamMGR.ShowEndTip;
var
R: String;
begin
Writeln('You Wanna Try Again?');
Writeln('Press "Y" 2 Try Again');
Readln(R);
if LowerCase(R) = 'y' then
Self.BeginExam;

end;

procedure TExamMGR.ShowScore;
begin
Writeln('Yer Final Score Is: ',Self.Score);
end;

procedure TExamMGR.ShowTitle;
var
tmp: String;
begin
Writeln('You Gotta Finish 10 Test,Press Any Key 2 Continue...');
Readln(tmp);
end;

begin
ExamMGR := TExamMGR.Create;//Build TExamMGR Instance;

ExamMGR.BeginExam;

ExamMGR.Free;//Recircle System Resource;
end.
//运行Delphi,创建控制台工程,清除所有框架代码,然后将上面代码粘贴上,Ctrl + F9编译即可使用.
第2个回答  2007-01-15
program ss(input,output);
var
a,b,c,i,s:integer;
begin
randomize;
s:=0;
for i:=1 to 10 do
begin
a:=random(1000);
b:=random(1000);
writeln(str(a),'+',str(b));
read(c);
if a+b=c then
begin
s:=s+10;
writeln('correct');
end
else
writeln('wrong');
end;
end;
writeln('total=',s);
end.本回答被提问者采纳
相似回答
大家正在搜