重载运算符第 2 行和第 3 行,未编译
程序PROG15(输入、输出); var invalid_operator : 布尔值; 运算符:字符; 数字1,数字2,结果:实数;
procedure MULTIPLY;
begin
result := number1 * number2
end;
procedure DIVIDE;
begin
result := number1 / number2
end;
procedure ADD;
begin
result := number1 + number2
end;
procedure SUBTRACT;
begin
result := number1 - number2
end;
procedure GET_INPUT;
begin
writeln('Enter two numbers and an operator in the format');
writeln(' number1 operator number2');
readln(number1); readln(operator); readln(number2)
end;
begin
invalid_operator := FALSE;
GET_INPUT;
case operator of
'*': MULTIPLY;
'/': DIVIDE;
'+': ADD;
'-': SUBTRACT;
otherwise invalid_operator := TRUE
end;
if invalid_operator then
writeln('Invalid operator')
else
writeln(number1:4:2,' ', operator,' ', number2:4:2,' is '
,result:5:2)
end.
{Special changes for Turbo are
case operator of
'*': result := MULTIPLY;
'/': result := DIVIDE;
'+': result := ADD;
'-': result := SUBTRACT;
else invalid_operator := TRUE
end;
program PROG15 (input,output);
var invalid_operator : boolean;
operator : char;
number1, number2, result : real;
procedure MULTIPLY;
begin
result := number1 * number2
end;
procedure DIVIDE;
begin
result := number1 / number2
end;
procedure ADD;
begin
result := number1 + number2
end;
procedure SUBTRACT;
begin
result := number1 - number2
end;
procedure GET_INPUT;
begin
writeln('Enter two numbers and an operator in the format');
writeln(' number1 operator number2');
readln(number1); readln(operator); readln(number2)
end;
begin
invalid_operator := FALSE;
GET_INPUT;
case operator of
'*': MULTIPLY;
'/': DIVIDE;
'+': ADD;
'-': SUBTRACT;
otherwise invalid_operator := TRUE
end;
if invalid_operator then
writeln('Invalid operator')
else
writeln(number1:4:2,' ', operator,' ', number2:4:2,' is '
,result:5:2)
end.
{Special changes for Turbo are
case operator of
'*': result := MULTIPLY;
'/': result := DIVIDE;
'+': result := ADD;
'-': result := SUBTRACT;
else invalid_operator := TRUE
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于运算符重载,运算符可能是保留字。更改其名称。
结果是 afaik 不保留(但函数结果的伪变量类似于 Delphi 模式),最好也给它一个不同的名称。
您可能还想尝试启用 Turbo 模式 (-So)
Operator is probably reserved word due to operator overloading. Change its name.
Result is afaik not reserved (but a pseudo variable for the functions result in Delphi like modes), better give it a different name too.
You might also want to try enabling Turbo mode (-So)