高中数学扩展/数学编程/输出例程
外观
添加了两个新的全局变量:double x_val 和 double delta。
添加了两个新函数:void output() 和 double process()。
更改了一个函数:void execute_command(char command)。
全局变量
double x_val:传递给 f(x) 的 x 值。
double delta:执行 + 或 - 命令时更改 x 的值。
函数添加
void output()
- 此函数调用 process 以获取 f(x) 的值,然后打印消息 f(x)=value。
double process()
- 执行 f(x) 的 C 实现。
函数更改
void execute_command(char command)
- 调用新的函数 output 以显示 f(x)=value。
- 实现变量 x_val 和 delta 的 '-' 和 '+' 命令。
//function prototypes
//...
float process();
void output();
//global variables
//...
float x_val;
float delta;
//function definitions
//...
void execute_command(char command)
{
switch (command)
{
case '=': output();
break;
case '+': output();
break;
case '-': output();
break;
case 'd':
case 'D': break;
case 'x':
case 'X': done++;
break;
}
}
float process()
{
return x_val * x_val;
}
void output()
{
float f_val;
f_val=process();
cprintf("f(%f)=%6f.\n",x_val,f_val);
}