1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #pragma once #include<string> #define _CRT_SECURE_NO_WARNINGS #include "MySQLCAPI.h" #include <iostream> #include<stdio.h> using namespace std;
class grade { public: char name[20]; int number; int literature; int math; int language; int science; int sum;
public: grade(); ~grade(); void grade::grade_Get(void) { MySQLCAPI c_apiconn;
c_apiconn.OpenConn("localhost", "root", "1541812541", "db_1"); string sql = "use db_1;"; c_apiconn.ExecuteSQL(sql.c_str()); printf("请输入准证号:"); printf("\n"); cin >> number; printf("请输入姓名:"); printf("\n"); cin >> name; printf("请输入语文成绩:"); printf("\n"); cin >> literature; printf("请输入数学成绩:"); printf("\n"); cin >> math; printf("请输入外语成绩:"); printf("\n"); cin >> language; printf("请输入理综成绩:"); cin >> science; string sql0 ; sum = literature + math + language + science; char *SQL = (char *)malloc(sizeof(char)* 500); sprintf(SQL, "insert into db_1.students values(%d,'%s',%d,%d,%d,%d,%d);", number, name, literature, math, language, science, sum); sql0 = SQL; c_apiconn.ExecuteSQL(sql0.c_str()); delete SQL; SQL = NULL; }
void grade::grade_Read(void){ MySQLCAPI c_apiconn;
c_apiconn.OpenConn("localhost", "root", "1541812541", "db_1"); string sql = "use db_1;"; c_apiconn.ExecuteSQL(sql.c_str()); printf("请输入查询的姓名:"); cin >> name; string sql1; printf("准证号\t 姓名\t 语文成绩\t 数学成绩\t 外语成绩\t 理综成绩\t 总成绩 "); char *SQL = (char *)malloc(sizeof(char)* 500); sprintf(SQL, "select * from db_1.students where name = '%s';", name); sql1 = SQL; vector<vector<string>> data; c_apiconn.QuerySQL(sql1.c_str(), data); printf("\n"); for (int i = 0; i < data.size(); i++) { for (int j = 0; j < data[i].size(); j++) { std::cout << data[i][j] << "\t\t"; } std::cout << std::endl; } delete SQL; SQL = NULL; getchar(); exit(1); } };
|