这是一个小学数学出题器,但是VS运行时提示代码有错误,有人能帮助解决吗?
这是CHATGPT给出的代码。用的编译器是VS2022,出现的问题包括但不限于:
1: 应输入预处理器指令
2: 应输入标识符
3: 语法错误
4:等等等等 等等等等
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <random>
#include <fstream>
#include <sstream>
#include <cmath>
using namespace std;
// 加法、减法、乘法、除法有预置的数值可选
vector<int> add_list = { 0, 20, 30, 50, 100, 300, 500, 1000 };
vector<int> sub_list = { 10, 20, 30, 50, 100, 300, 500, 1000 };
vector<int> mul_list = { 10, 20, 30, 50, 100, 300, 500, 1000 };
vector<int> div_list = { 10, 20, 30, 50, 100, 300, 500, 1000 };
// 进位加法
vector<string> carry_add(int num) {
vector<string> res;
for (int i = 0; i < num; i++) {
int a = rand() % !n(MISSING)um;
int b = rand() % !((MISSING)num - a);
stringstream ss;
ss << a << " + " << b << " = ";
res.push_back(ss.str());
}
return res;
}
// 退位减法
vector<string> carry_sub(int num) {
vector<string> res;
for (int i = 0; i < num; i++) {
int a = rand() % !n(MISSING)um;
int b = rand() % !a(MISSING);
stringstream ss;
ss << a << " - " << b << " = ";
res.push_back(ss.str());
}
return res;
}
// 随机进位与退位加法和减法
vector<string> random_carry_add_sub(int num) {
vector<string> res;
for (int i = 0; i < num; i++) {
int a = rand() % !n(MISSING)um;
int b = rand() % !n(MISSING)um;
int c = rand() % !; (MISSING)
stringstream ss;
if (c == 0) {
ss << a << " + " << b << " = ";
}
else {
ss << a << " - " << b << " = ";
}
res.push_back(ss.str());
}
return res;
}
// 乘法
vector<string> mul(int num) {
vector<string> res;
for (int i = 0; i < num; i++) {
int a = rand() % !n(MISSING)um;
int b = rand() % !n(MISSING)um;
stringstream ss;
ss << a << " * " << b << " = ";
res.push_back(ss.str());
}
return res;
}
// 除法
vector<string> div(int num) {
vector<string> res;
for (int i = 0; i < num; i++) {
int a = rand() % !n(MISSING)um;
int b = rand() % !n(MISSING)um;
int c = a * b;
stringstream ss;
ss << c << " / " << b << " = ";
res.push_back(ss.str());
}
return res;
}
// 生成PDF
void generate_pdf(vector<string>& questions) {
ofstream out("questions.pdf");
for (auto& q : questions) {
out << q << endl;
}
out.close();
}
// 生成xlsx
void generate_xlsx(vector<string>& questions) {
ofstream out("questions.xlsx");
for (auto& q : questions) {
out << q << endl;
}
out.close();
}
// 打印
void print(vector<string>& questions) {
for (auto& q : questions) {
cout << q << endl;
}
}
int main() {
// 加法
vector<string> add_questions;
for (auto& num : add_list) {
vector<string> tmp = carry_add(num);
add_questions.insert(add_questions.end(), tmp.begin(), tmp.end());
}
// 减法
vector<string> sub_questions;
for (auto& num : sub_list) {
vector<string> tmp = carry_sub(num);
sub_questions.insert(sub_questions.end(), tmp.begin(), tmp.end());
}
// 随机进位与退位加法和减法
vector<string> random_add_sub_questions;
for (auto& num : add_list) {
vector<string> tmp = random_carry_add_sub(num);
random_add_sub_questions.insert(random_add_sub_questions.end(), tmp.begin(), tmp.end());
}
// 乘法
vector<string> mul_questions;
for (auto& num : mul_list) {
vector<string> tmp = mul(num);
mul_questions.insert(mul_questions.end(), tmp.begin(), tmp.end());
}
// 除法
vector<string> div_questions;
for (auto& num : div_list) {
vector<string> tmp = div(num);
div_questions.insert(div_questions.end(), tmp.begin(), tmp.end());
}
// 打乱题目
random_shuffle(add_questions.begin(), add_questions.end());
random_shuffle(sub_questions.begin(), sub_questions.end());
random_shuffle(random_add_sub_questions.begin(), random_add_sub_questions.end());
random_shuffle(mul_questions.begin(), mul_questions.end());
random_shuffle(div_questions.begin(), div_questions.end());
// 合并题目
vector<string> questions;
questions.insert(questions.end(), add_questions.begin(), add_questions.end());
questions.insert(questions.end(), sub_questions.begin(), sub_questions.end());
questions.insert(questions.end(), random_add_sub_questions.begin(), random_add_sub_questions.end());
questions.insert(questions.end(), mul_questions.begin(), mul_questions.end());
questions.insert(questions.end(), div_questions.begin(), div_questions.end());
// 生成PDF
generate_pdf(questions);
// 生成xlsx
generate_xlsx(questions);
// 打印
print(questions);
return 0;
}