重载运算符第 2 行和第 3 行,未编译

发布于 2024-09-01 00:07:57 字数 1347 浏览 5 评论 0原文

程序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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┈┾☆殇 2024-09-08 00:07:57

由于运算符重载,运算符可能是保留字。更改其名称。

结果是 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文