Tạo đề tự động
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
// Hàm sinh số nguyên ngẫu nhiên trong khoảng [min, max]
int randomInt(int min, int max) {
return min + rand() % (max - min + 1);
}
void toado_vector(char i, char j, int number_problems = 5) {
for (int k = 0; k < number_problems; k++) {
int a = randomInt(-14, 14); // Số ngẫu nhiên từ -14 đến 14
int b = randomInt(-14, 14);
while (a==0 && b==0){
int a = randomInt(-14, 14); // Số ngẫu nhiên từ -14 đến 14
int b = randomInt(-14, 14);
}
stringstream va,vb;
if (a>1 || a<-1) {
va << a << "\\vec{" << i << "}";
} else if (a == 1){
va << "\\vec{" << i << "}";
} else if (a == -1){
va << "-" << "\\vec{" << i << "}";
} else {
va << "";
}
if (b>1 || b<-1) {
vb << b << "\\vec{" << j << "}$";
} else if (b == 1){
vb << "\\vec{" << j << "}$";
} else if (b == -1){
vb << "-" << "\\vec{" << j << "}$";
} else {
vb << "";
}
if (a != 0 && b > 0) {
cout << "Câu " << k+1 << ": Trong hệ trục $\\left( O;\\vec{i};\\vec{j} \\right)$, tọa độ của vectơ $\\vec{u}=" << va.str() <<"+" << vb.str() << " là:" << endl;
} else if (a != 0 && b < 0) {
cout << "Câu " << k+1 << ": Trong hệ trục $\\left( O;\\vec{i};\\vec{j} \\right)$, tọa độ của vectơ $\\vec{u}=" << va.str() << vb.str() << " là:" << endl;
} else if (a==0 && b!=0) {
cout << "Câu " << k+1 << ": Trong hệ trục $\\left( O;\\vec{i};\\vec{j} \\right)$, tọa độ của vectơ $\\vec{u}=" << va.str() << vb.str() << " là:" << endl;
} else if (a!=0 && b==0) {
cout << "Câu " << k+1 << ": Trong hệ trục $\\left( O;\\vec{i};\\vec{j} \\right)$, tọa độ của vectơ $\\vec{u}=" << va.str() << "$ là:" << endl;
}
if (i=='i') {
cout << "Đáp án: $\\vec{u}=\\left(" << a << ";" << b << "\\right)$\n";
} else if (i=='j') {
cout << "Đáp án: $\\vec{u}=\\left(" << b << ";" << a << "\\right)$\n";
}
}
}
void toado_vectorAB(int number_problems = 5){
for (int i = 0; i < number_problems; i++) {
int xA = randomInt(-14, 14); // Số ngẫu nhiên từ -14 đến 14
int yA = randomInt(-14, 14);
int xB = randomInt(-14, 14);
int yB = randomInt(-14, 14);
cout << "Câu " << i+1 << ": Trong hệ trục Oxy cho hai điểm $A\\left(" << xA << "; " << yA << "\\right)$, ";
cout << "$B\\left(" << xB << ", " << yB << "\\right)$, ";
cout << "tọa độ của vectơ $\\overrightarrow{AB}$ là:" << endl;
cout << "Đáp án: $\\overrightarrow{AB}$=\\left(" << xB-xA << "; " << yB-yA << "\\right)$\n";
}
}
void tim_trungdiem(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Tạo tọa độ ngẫu nhiên cho hai điểm M và N
int xM = randomInt(-20, 20);
int yM = randomInt(-20, 20);
int xN = randomInt(-20, 20);
int yN = randomInt(-20, 20);
// Tính tọa độ trung điểm I
double xI = (xM + xN) / 2.0;
double yI = (yM + yN) / 2.0;
// In bài tập ra màn hình
cout << "Câu " << i << ": ";
cout << "Cho hai điểm $M\\left(" << xM << ", " << yM << "\\right)$ và $N\\left(" << xN << ", " << yN << "\\right)$. ";
cout << "Tìm tọa độ điểm I là trung điểm của MN.\n";
// In đáp án
cout << "Đáp án:$I\\left(" << fixed << setprecision(1) << xI << ", " << yI << "\\right)$\n";
}
}
void dinh_hinhbinhhanh_biettam(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Tọa độ tâm I
int xI = randomInt(-10, 10);
int yI = randomInt(-10, 10);
// Tọa độ đỉnh B
int xB = randomInt(-10, 10);
int yB = randomInt(-10, 10);
// Tọa độ đỉnh C
int xC = randomInt(-10, 10);
int yC = randomInt(-10, 10);
// Tọa độ đỉnh D tính từ công thức trung điểm
int xE = 2 * xI - xB;
int yE = 2 * yI - yB;
// Tọa độ đỉnh A tính từ công thức trung điểm
int xA = 2 * xI - xC;
int yA = 2 * yI - yC;
// In bài toán ra màn hình
cout << "Câu " << i << ":";
cout << "Cho hình bình hành ABCE có tọa độ tâm $I\\left(" << xI << "; " << yI << "\\right)$ và hai đỉnh $B\\left("
<< xB << "; " << yB << "\\right)$, $C\\left(" << xC << "; " << yC << "\\right)$.";
cout << "Tìm tọa độ hai đỉnh A và E.\n";
// In lời giải
cout << "Đáp án: ";
cout << "$E\\left(" << xE << ", " << yE << "\\right)$,";
cout << "$A\\left(" << xA << ", " << yA << "\\right)$.\n";
}
}
void trongtam_tamgiac(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Tạo tọa độ ngẫu nhiên cho hai điểm M và N
int xM = randomInt(-20, 20);
int yM = randomInt(-20, 20);
int xN = randomInt(-20, 20);
int yN = randomInt(-20, 20);
int xP = randomInt(-20, 20);
int yP = randomInt(-20, 20);
// Tính tọa độ trung điểm I
double xG = (xM + xN + xP) / 3.0;
double yG = (yM + yN + yP) / 3.0;
// In bài tập ra màn hình
cout << "Câu " << i << ": ";
cout << "Cho tam giác MNP có $M\\left(" << xM << ", " << yM << "\\right)$, ";
cout << "$N\\left(" << xN << ", " << yN << "\\right)$ và ";
cout << "$P\\left(" << xP << ", " << yP << "\\right)$. ";
cout << "Tìm tọa độ điểm G là trọng tâm của tam giác MNP (làm tròn số các số trong kết quả đến hàng phần mười).\n";
// In đáp án
cout << "Đáp án:$G\\left(" << fixed << setprecision(1) << xG << ", " << yG << "\\right)$\n";
}
}
void dinh_tamgiac_biettrongtam(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Sinh tọa độ ngẫu nhiên cho điểm A, B và trọng tâm C
int xA = randomInt(-10, 10);
int yA = randomInt(-10, 10);
int xB = randomInt(-10, 10);
int yB = randomInt(-10, 10);
int xC = randomInt(-10, 10);
int yC = randomInt(-10, 10);
// Tính tọa độ điểm D
int xE = 3 * xC - xA - xB; // Tính x_D từ công thức trọng tâm
int yE = 3 * yC - yA - yB; // Tính y_D từ công thức trọng tâm
// In bài toán ra màn hình
cout << "Câu " << i << ": ";
cout << "Trong hệ tọa độ Oxy, cho $A\\left(" << xA << "; " << yA << "\\right)$, $B\\left("
<< xB << "; " << yB << "\\right)$ và $C\\left(" << xC << "; " << yC << "\\right)$. ";
cout << "Tìm tọa độ điểm E sao cho C là trọng tâm của tam giác ABE.\n";
// In đáp án
cout << "Đáp án:$E\\left(" << xE << "; " << yE << "\\right)$\n";
}
}
void dinh_thu_4_hinhbinhhanh(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Sinh tọa độ ngẫu nhiên cho các điểm A, B, C
int xA = randomInt(-10, 10);
int yA = randomInt(-10, 10);
int xB = randomInt(-10, 10);
int yB = randomInt(-10, 10);
int xC = randomInt(-10, 10);
int yC = randomInt(-10, 10);
// Tính tọa độ điểm E
int xE = xA + xC - xB; // Tọa độ x của D từ: xD - xA = xC - xB
int yE = yA + yC - yB; // Tọa độ y của D từ: yD - yA = yC - yB
// In bài toán ra màn hình
cout << "Câu " << i << ": ";
cout << "Trong hệ tọa độ Oxy, cho $A\\left(" << xA << "; " << yA << "\\right)$, $B\\left("
<< xB << "; " << yB << "\\right)$ và $C\\left(" << xC << "; " << yC << "\\right)$. ";
cout << "Tìm tọa độ điểm E sao cho ABCE là hình bình hành.\n";
// In đáp án
cout << "Đáp án:$E\\left(" << xE << "; " << yE << "\\right)$\n";
}
}
void dinh_tamgiac_biettrungdiem(int number_problems = 5){
for (int i = 1; i <= number_problems; i++) {
// Sinh tọa độ ngẫu nhiên cho M, N, P
int xM = randomInt(-10, 10);
int yM = randomInt(-10, 10);
int xN = randomInt(-10, 10);
int yN = randomInt(-10, 10);
int xP = randomInt(-10, 10);
int yP = randomInt(-10, 10);
// Tính tọa độ điểm B
int xB = xP + xM - xN; // x_B = x_P + x_M - x_N
int yB = yP + yM - yN; // y_B = y_P + y_M - y_N
// Tính tọa độ điểm A
int xA = xP - xM + xN; // x_A = x_P - x_M + x_N
int yA = yP - yM + yN; // y_A = y_P - y_M + y_N
// Tính tọa độ điểm C
int xC = -xP + xM + xN; // x_B = -x_P + x_M + x_N
int yC = -yP + yM + yN; // y_B = -y_P + y_M + y_N
// In bài toán ra màn hình
cout << "Câu " << i << ": ";
cout << "Trong hệ tọa độ Oxy, cho $M\\left(" << xM << "; " << yM << "\\right)$, $N\\left("
<< xN << "; " << yN << "\\right)$ và $P\\left(" << xP << "; " << yP << "\\right)$ "
<< "lần lượt là trung điểm các cạnh BC, CA, AB của $\\Delta ABC$.";
cout << "Tìm tọa độ điểm A, B, C của tam giác.\n";
// In đáp án
cout << "Đáp án:$A\\left(" << xA << "; " << yA << "\\right)$, ";
cout << "$B\\left(" << xB << "; " << yB << "\\right)$, ";
cout << "$C\\left(" << xC << "; " << yC << "\\right)$\n";
}
}
// Hàm tạo tọa độ ngẫu nhiên của một điểm
pair<int, int> diem_ngau_nhien(int min_coord, int max_coord) {
int x = rand() % (max_coord - min_coord + 1) + min_coord;
int y = rand() % (max_coord - min_coord + 1) + min_coord;
return make_pair(x, y);
}
void toado_chanduong_phangiac(int num_problems = 10, int min_coord = -10, int max_coord = 10, int min_side = 1) {
for (int i = 1; i <= num_problems; ++i) {
// Tạo ngẫu nhiên tọa độ điểm A
int a = rand() % 15 + 2;
int b = rand() % 15 + 2;
// Tạo ngẫu nhiên tọa độ điểm B và C
pair<int, int> DiemB = diem_ngau_nhien(min_coord, max_coord);
pair<int, int> DiemC = diem_ngau_nhien(min_coord, max_coord);
int xB = DiemB.first;
int yB = DiemB.second;
int xC = DiemC.first;
int yC = DiemC.second;
// Tính độ dài các cạnh BC
int BC = sqrt(pow(xC - xB, 2) + pow(yC - yB, 2));
// Đảm bảo tam giác tồn tại và các cạnh lớn hơn min_side
while (xB == xC && yB == yC && BC > min_side) {
DiemB = diem_ngau_nhien(min_coord, max_coord);
DiemC = diem_ngau_nhien(min_coord, max_coord);
xB = DiemB.first;
yB = DiemB.second;
xC = DiemC.first;
yC = DiemC.second;
BC = sqrt(pow(xC - xB, 2) + pow(yC - yB, 2));
}
// In đề bài
cout << "Câu " << i << ": ";
cout << "Cho tam giác ABC với $AB:AC=" << a << ":" << b << "$. ";
cout << "Tính tọa độ điểm D là chân đường phân giác trong góc A, ";
cout << "biết $B\\left(" << xB << "; " << yB << "\\right)$,$C\\left(" << xC << "; " << yC << "\\right)$. " << endl;
// In đáp án
cout << "Đáp án: $D\\left(\\frac{" << b*xB+a*xC << "}{" <<a+b<< "};\\frac{" << b*yB+a*yC <<"}{" <<a+b<<"}\\right)$.\n";
}
}
// Hàm chính
int main() {
srand(time(0)); // Khởi tạo seed cho random
toado_vector('i','j',2);
toado_vector('j','i',2);
toado_vectorAB(2);
tim_trungdiem(2);
dinh_hinhbinhhanh_biettam(2);
trongtam_tamgiac(2);
dinh_tamgiac_biettrongtam(2);
dinh_thu_4_hinhbinhhanh(2);
dinh_tamgiac_biettrungdiem(2);
toado_chanduong_phangiac(2);
return 0;
}