本程序灵感来源于《名校课堂》!!!
先放代码
#include "bits/stdc++.h"
#include <windows.h>
using namespace std;
//一次函数
int main() {
cout << "请输入一次函数的表达式:";
string hanshu;
cin >> hanshu;
int len = hanshu.size();
bool pos = false;
double k = 0, b = 0;
bool min = true, max = false;
for (int i = 0; i < len; i++) {
if (hanshu[i] == 'y') {
pos = true;
continue;
}
if (pos) {
if (hanshu[i] == 'x') {
min = false;
max = true;
continue;
}
if (min) {
if (hanshu[i] >= '0' && hanshu[i] <= '9') {
k = k * 10 + hanshu[i] - '0';
continue;
}
}
if (max) {
if (hanshu[i] >= '0' && hanshu[i] <= '9') {
b = b * 10 + hanshu[i] - '0';
continue;
}
}
}
}
for (int i = 0; i < 100; i++) {
cout << "当x=" << i << "时,y=";
cout << k * i + b << endl;
Sleep(500);
}
}