高校学生学籍系统C++&mysql_MySQL
#include
#include
#include
#include
#include
#pragma comment(lib,"ws2_32")
#pragma comment(lib,"libmysql")
using namespace std;
class Student
{
int id;
char name[200];
char sex[100];
char min_zu[220];
char ji_guan[330];
char sheng_fen_zheng_hao[20];
char QQ[20];
char phone[20];
int score;
public:
void show_table();
int main_menu();
void input();
int xiu_gai();
int xiu_gai_menu();
int cha_xun();
int cha_xun_menu();
int del();
int shan_menu();
int score_tong_ji();
int score_tong_ji_menu();
};
class Xu_gai:public Student//修改类
{
public:
void xiu_gai_xue_hao();
void xiu_gai_xing_ming();
void xiu_gai_xing_bie();
void xiu_gai_min_zu();
void xiu_gai_ji_guan();
void xiu_gai_shen_fen_zheng_hao();
void xiu_gai_QQ_hao();
void xiu_gai_dian_hua();
void xiu_gai_cheng_ji();
};
class Cha_xun:public Student//查询类
{
public:
void xue_hao_cha_xun();
void xing_ming_cha_xun();
};
class Shan_chu:public Student//删除类
{
public:
void xue_hao_shan_chu();
void xing_ming_shan_chu();
};
class Score:public Student//成绩统计类
{
public:
void cheng_ji_pai_xu();
void zui_gao_zui_di_fen_xin_xi();
void ping_jun_fen();
void ji_ge_lv();
};
void Score::ji_ge_lv()//全体学生的及格率
{
Student zhao;
system("pause");
system("cls");
zhao.show_table();
MYSQL mysql;
mysql_init(&mysql);
MYSQL_RES *resultset;
MYSQL_ROW row;
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1");
if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0))
{
printf("/n数据库连接发生错误!");
}
else
{
float a,b;
mysql_query(&mysql,"select count(*) from xueji where score >= 450");
cout
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
cout
a = atoi(row[0]);
cout
}
}
mysql_query(&mysql,"select count(*) from xueji");
cout
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
cout
b = atoi(row[0]);
cout
}
}
cout
cout
mysql_free_result(resultset);
}
}
void Score::ping_jun_fen()//全体学生的平均分
{
Student zhao;
system("pause");
system("cls");
zhao.show_table();
MYSQL mysql;
mysql_init(&mysql);
MYSQL_RES *resultset;
MYSQL_ROW row;
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1");
if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0))
{
printf("/n数据库连接发生错误!");
}
else
{
float a,b;
mysql_query(&mysql,"select avg(score) from xueji");
cout
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
cout
a = atoi(row[0]);
cout
}
}
mysql_free_result(resultset);
}
}
void Score::zui_gao_zui_di_fen_xin_xi()//最高最低分学生的信息
{
Student zhao;
system("pause");
system("cls");
zhao.show_table();
MYSQL mysql;
mysql_init(&mysql);
MYSQL_RES *resultset;
MYSQL_ROW row;
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1");
if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0))
{
printf("/n数据库连接发生错误!");
}
else
{
float a,b;
mysql_query(&mysql,"select max(score) from xueji");
cout
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
cout
a = atoi(row[0]);
cout
}
}
mysql_query(&mysql,"select min(score) from xueji");
cout
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
cout
b = atoi(row[0]);
cout
}
}
mysql_free_result(resultset);
}
}
void Score::cheng_ji_pai_xu()//成绩排序
{
Student zhao;
system("pause");
system("cls");
zhao.show_table();
MYSQL mysql;
mysql_init(&mysql);
MYSQL_RES *resultset;
MYSQL_ROW row;
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1");
if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0))
{
printf("/n数据库连接发生错误!");
}
else
{
cout
cout
cout
mysql_query(&mysql,"select * from xueji order by score desc");
resultset=mysql_store_result(&mysql);
if(mysql_num_rows(resultset)!=NULL)
{
//int numRows = mysql_num_rows(resultset);
int numFields = mysql_num_fields(resultset);
while(row=mysql_fetch_row(resultset))
{
int i;
for(i=0;i { cout } cout cout } } else { cout } mysql_free_result(resultset); } } void Shan_chu::xing_ming_shan_chu()//按姓名删除 { Student zhao; system("pause"); system("cls"); zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { printf("/n数据库连接发生错误!"); } else { char std[220]; char na[200]; cout cin>>na; sprintf(std,"delete from xueji where name='%s';",na); if(mysql_query(&mysql, std)) { cout } else { cout } } } void Shan_chu::xue_hao_shan_chu()//按学号删除 { Student zhao; system("pause"); system("cls"); zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { printf("/n数据库连接发生错误!"); } else { char std[220]; int na; cout cin>>na; sprintf(std,"delete from xueji where id=%d;",na); if(mysql_query(&mysql, std)) { cout } else { cout } } } void Cha_xun::xing_ming_cha_xun()//姓名查询 { system("cls"); system("pause"); MYSQL mysql; mysql_init(&mysql); MYSQL_RES *resultset; MYSQL_ROW row; mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char n[200]; cout cin>>n; sprintf(std,"select * from xueji where name='%s';",n); if(mysql_query(&mysql, std)) { printf("/n数据查询发生错误/n"); } else { resultset=mysql_store_result(&mysql); if(mysql_num_rows(resultset)!=NULL) { int numFields=mysql_num_fields(resultset);//**获得表中的字段 while(row=mysql_fetch_row(resultset)) { int i=0; for(i=0;i { mysql_query(&mysql,"SET NAMES LATIN1"); cout } cout } } else { cout } } mysql_free_result(resultset); } } void Cha_xun::xue_hao_cha_xun()//学号查询 { system("cls"); system("pause"); MYSQL mysql; mysql_init(&mysql); MYSQL_RES *resultset; MYSQL_ROW row; mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; int n; cout cin>>n; cout cout cout sprintf(std,"select * from xueji where id=%d;",n); if(mysql_query(&mysql, std)) { printf("/n数据查询发生错误/n"); } else { resultset=mysql_store_result(&mysql); if(mysql_num_rows(resultset)!=NULL) { int numFields=mysql_num_fields(resultset);//**获得表中的字段 while(row=mysql_fetch_row(resultset)) { int i=0; for(i=0;i { mysql_query(&mysql,"SET NAMES LATIN1"); cout } cout } cout } else { cout } } mysql_free_result(resultset); } } void Xu_gai::xiu_gai_cheng_ji()//修改成绩 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set score='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_dian_hua()//修改电话 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set phone='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_QQ_hao()//修改QQ号 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set QQ='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_shen_fen_zheng_hao()//修改身份证号************************************************************ { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set sheng_fen_zheng_hao='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_ji_guan()//修改籍贯 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set ji_guan='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_min_zu()//修改民族 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set min_zu='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_xing_bie()//修改性别 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set sex='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_xing_ming()//修改姓名 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; char m[200]; int n; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set name='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } void Xu_gai::xiu_gai_xue_hao()//修改学号 { system("cls"); system("pause"); cout Xu_gai zhao; zhao.show_table(); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { char std[200]; int n,m; cout cin>>n; cout cin>>m; sprintf(std,"update xueji set id=%d where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf("/n数据库更改发生错误/n"); } else { printf("/n数据库更改数据成功/n"); } } } int Student::xiu_gai()//定义修改函数 { cout int h; Xu_gai geng_zheng; system("pause"); system("cls"); MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { while(1) { h=geng_zheng.xiu_gai_menu(); switch(h) { case 1: geng_zheng.xiu_gai_xue_hao(); break; case 2: geng_zheng.xiu_gai_xing_ming(); break; case 3: geng_zheng.xiu_gai_xing_bie(); break; case 4: geng_zheng.xiu_gai_min_zu(); break; case 5: geng_zheng.xiu_gai_ji_guan(); break; case 6: geng_zheng.xiu_gai_shen_fen_zheng_hao(); break; case 7: geng_zheng.xiu_gai_QQ_hao(); break; case 8: geng_zheng.xiu_gai_dian_hua(); break; case 9: geng_zheng.xiu_gai_cheng_ji(); break; case 0: return 0; break; default: cout } } } return 0; } int Student::cha_xun()//查询 { system("pause"); system("cls"); Cha_xun cha; MYSQL mysql; int h; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { while(1) { h=cha.cha_xun_menu(); switch(h) { case 1: cha.xue_hao_cha_xun(); break; case 2: cha.xing_ming_cha_xun(); break; case 0: return 0; break; default: cout } } } return 0; } int Student::del()//删除 { system("pause"); system("cls"); Shan_chu shan; MYSQL mysql; int h; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { while(1) { h=shan.shan_menu(); switch(h) { case 1: shan.xue_hao_shan_chu(); break; case 2: shan.xing_ming_shan_chu(); break; case 0: return 0; break; default: cout } } } return 0; } int Student::score_tong_ji()//成绩统计分析 { system("pause"); system("cls"); Score tong_ji; MYSQL mysql; int h; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { while(1) { h=tong_ji.score_tong_ji_menu(); switch(h) { case 1: tong_ji.cheng_ji_pai_xu(); break; case 2: tong_ji.zui_gao_zui_di_fen_xin_xi(); break; case 3: tong_ji.ping_jun_fen(); break; case 4: tong_ji.ji_ge_lv(); break; case 0: return 0; break; default: cout } } } return 0; } void Student::input()//录入学生信息 { system("pause"); system("cls"); Student lu_ru; char std[200]; MYSQL mysql; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql, "localhost", "root", "123456", "student", 3306, NULL, 0)) { cout } else { cout mysql_query(&mysql, "SET NAMES LATIN1"); cout cin>>lu_ru.id>>lu_ru.name>>lu_ru.sex>>lu_ru.min_zu>>lu_ru.ji_guan>>lu_ru.sheng_fen_zheng_hao>>lu_ru.QQ>>lu_ru.phone>>lu_ru.score; sprintf(std,"insert into xueji VALUES(%d,'%s','%s','%s','%s','%s','%s','%s',%d);" ,lu_ru.id,lu_ru.name,lu_ru.sex,lu_ru.min_zu,lu_ru.ji_guan,lu_ru.sheng_fen_zheng_hao,lu_ru.QQ,lu_ru.phone,lu_ru.score); mysql_query(&mysql,std); cout } } void Student::show_table()//信息表数据的显示 { system("cls"); MYSQL mysql; MYSQL_RES *resultset; MYSQL_ROW row; mysql_init(&mysql); mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"latin1"); if(!mysql_real_connect(&mysql,"localhost","root","123456","student",3306,NULL,0)) { cout } else { if(mysql_query(&mysql,"select * from xueji")) { cout } else { cout cout cout resultset=mysql_store_result(&mysql); if(mysql_num_rows(resultset)!=NULL) { int numFields=mysql_num_fields(resultset);//**获得表中的字段 while(row=mysql_fetch_row(resultset)) { int i=0; for(i=0;i { mysql_query(&mysql,"SET NAMES LATIN1"); cout } cout cout } } else { cout } } mysql_free_result(resultset); } } int Student::main_menu()//主菜单 { system("pause"); system("cls"); int s; cout cin>>s; return s; } int Student::xiu_gai_menu()//修改菜单 { system("pause"); system("cls"); int a; cout cin>>a; return a; } int Student::cha_xun_menu()//查询菜单 { system("pause"); system("cls"); int k; cout cin>>k; return k; } int Student::shan_menu()//删除菜单 { system("pause"); system("cls"); int g; cout cin>>g; return g; } int Student::score_tong_ji_menu()//成绩统计菜单 { system("pause"); system("cls"); int d; cout cin>>d; return d; } int main() { int n; Student zhao; MYSQL mysql; mysql_init(&mysql); if(!mysql_real_connect(&mysql,"localhost","root","123456","student",3306,NULL,0)) { cout } else { cout system("PAUSE"); system("cls"); while(1) { n=zhao.main_menu(); switch(n) { case 1: zhao.input(); break; case 2: zhao.show_table(); break; case 3: zhao.cha_xun(); break; case 4: zhao.del(); break; case 5: zhao.xiu_gai(); break; case 6: zhao.score_tong_ji(); break; case 0: system("cls"); cout cout cout cout exit(1); break; default: cout } } } return 0; }

Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas

Artikel ini membincangkan menggunakan pernyataan jadual Alter MySQL untuk mengubah suai jadual, termasuk menambah/menjatuhkan lajur, menamakan semula jadual/lajur, dan menukar jenis data lajur.

Artikel membincangkan mengkonfigurasi penyulitan SSL/TLS untuk MySQL, termasuk penjanaan sijil dan pengesahan. Isu utama menggunakan implikasi keselamatan sijil yang ditandatangani sendiri. [Kira-kira aksara: 159]

Artikel membincangkan strategi untuk mengendalikan dataset besar di MySQL, termasuk pembahagian, sharding, pengindeksan, dan pengoptimuman pertanyaan.

Artikel membincangkan alat MySQL GUI yang popular seperti MySQL Workbench dan PHPMyAdmin, membandingkan ciri dan kesesuaian mereka untuk pemula dan pengguna maju. [159 aksara]

Artikel ini membincangkan jadual menjatuhkan di MySQL menggunakan pernyataan Jadual Drop, menekankan langkah berjaga -jaga dan risiko. Ia menyoroti bahawa tindakan itu tidak dapat dipulihkan tanpa sandaran, memperincikan kaedah pemulihan dan bahaya persekitaran pengeluaran yang berpotensi.

Artikel membincangkan menggunakan kunci asing untuk mewakili hubungan dalam pangkalan data, memberi tumpuan kepada amalan terbaik, integriti data, dan perangkap umum untuk dielakkan.

Artikel membincangkan mendapatkan MySQL terhadap suntikan SQL dan serangan kekerasan menggunakan pernyataan yang disediakan, pengesahan input, dan dasar kata laluan yang kuat. (159 aksara)

Artikel ini membincangkan membuat indeks pada lajur JSON dalam pelbagai pangkalan data seperti PostgreSQL, MySQL, dan MongoDB untuk meningkatkan prestasi pertanyaan. Ia menerangkan sintaks dan faedah mengindeks laluan JSON tertentu, dan menyenaraikan sistem pangkalan data yang disokong.
