/*
C++程序设计实践教学环节任务书 一、题目:高校学籍管理系统 二、目的与要求 1. 目的: 1.掌握C++语言基本知识及其编程方法 2.掌握类和对象的基本概念与用法 3.掌握面向对象中的继承与多态等面象对象特性 4.掌握文件流的基本操作 2. 要求 基本要求: (1)要求利用面向对象的方法以及C++的编程思想来完毕系统的设计; (2)要求在设计的过程中,建立清晰的类层次。 (3)在系统中至少要定义8个类,每一个类中要有各自的属性和方法。 (4)在系统的设计中,要求使用面向对象的继承与多态
*/
#include <iostream> #include <stdlib.h> #include <string> #include <winsock2.h> #include <mysql.h> #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(" 数据库连接错误发生!"); } 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<<row[0]; a = atoi(row[0]); cout<<endl; } } 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<<row[0]; b = atoi(row[0]); cout<<endl; } } cout<<"及格率:"; cout << ((a/b)*100)<<"%" << endl<<endl; 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(" 数据库连接错误发生!"); } 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<<row[0]; a = atoi(row[0]); cout<<endl; } } 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(" 数据库连接错误发生!"); } 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<<row[0]; a = atoi(row[0]); cout<<endl; } } 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<<row[0]; b = atoi(row[0]); cout<<endl; } } 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(" 数据库连接错误发生!"); } else { cout<<"**************************************開始成绩排名**************************************"<<endl; cout<<" 学号 "<<" 姓名 "<<"性别 "<<"民族 "<<"籍贯 "<<" 身份证 "<<" QQ "<<" 电话 "<<" 成绩 "<<endl; cout<<"--------------------------------------------------------------------------------------"<<endl; 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<numFields;i++) { cout<<" "<<row[i]<<" "; } cout<<endl; cout<<"--------------------------------------------------------------------------------------"<<endl; } } 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(" 数据库连接错误发生!"); } else { char std[220]; char na[200]; cout<<"请输入要删除学籍信息的学生姓名: "<<endl; cin>>na; sprintf(std,"delete from xueji where name='%s';",na); if(mysql_query(&mysql, std)) { cout<<"数据查询错误发生"<<endl; } else { cout<<"删除成功!"<<endl; } } } 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(" 数据库连接错误发生!"); } else { char std[220]; int na; cout<<"请输入要删除学籍信息的学生学号: "<<endl; cin>>na; sprintf(std,"delete from xueji where id=%d;",na); if(mysql_query(&mysql, std)) { cout<<"数据查询错误发生"<<endl; } else { cout<<"删除成功!"<<endl; } } } 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<<"数据库连接错误!"<<endl; } else { char std[200]; char n[200]; cout<<"请输入要查的姓名:"<<endl; cin>>n; sprintf(std,"select * from xueji where name='%s';",n); if(mysql_query(&mysql, std)) { printf(" 数据查询错误发生 "); } 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<numFields;i++) { mysql_query(&mysql,"SET NAMES LATIN1"); cout<<" "<<row[i]<<" "; } cout<<endl; } } 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<<"数据库连接错误!"<<endl; } else { char std[200]; int n; cout<<"请输入要查的学号:"<<endl; cin>>n; cout<<"--------------------------------------显示查询----------------------------------------"<<endl; cout<<" 学号 "<<" 姓名 "<<"性别 "<<"民族 "<<"籍贯 "<<" 身份证 "<<" QQ "<<" 电话 "<<" 成绩 "<<endl; cout<<"--------------------------------------------------------------------------------------"<<endl; sprintf(std,"select * from xueji where id=%d;",n); if(mysql_query(&mysql, std)) { printf(" 数据查询错误发生 "); } 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<numFields;i++) { mysql_query(&mysql,"SET NAMES LATIN1"); cout<<" "<<row[i]<<" "; } cout<<endl; } cout<<"--------------------------------------------------------------------------------------"<<endl; } else { cout<<"显示无果。"; } } mysql_free_result(resultset); } } void Xu_gai::xiu_gai_cheng_ji()//改动成绩 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的成绩:"<<endl; cin>>m; sprintf(std,"update xueji set score='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_dian_hua()//改动电话 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的电话:"<<endl; cin>>m; sprintf(std,"update xueji set phone='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_QQ_hao()//改动QQ号 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!
"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的QQ号:"<<endl; cin>>m; sprintf(std,"update xueji set QQ='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_shen_fen_zheng_hao()//改动身份证号************************************************************ { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误。"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的身份证号:"<<endl; cin>>m; sprintf(std,"update xueji set sheng_fen_zheng_hao='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_ji_guan()//改动籍贯 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的籍贯:"<<endl; cin>>m; sprintf(std,"update xueji set ji_guan='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_min_zu()//改动民族 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的民族:"<<endl; cin>>m; sprintf(std,"update xueji set min_zu='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_xing_bie()//改动性别 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的性别:"<<endl; cin>>m; sprintf(std,"update xueji set sex='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_xing_ming()//改动姓名 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; char m[200]; int n; cout<<"对目标学号信息进行改动:"<<endl; cin>>n; cout<<"请输入要新的姓名:"<<endl; cin>>m; sprintf(std,"update xueji set name='%s' where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } void Xu_gai::xiu_gai_xue_hao()//改动学号 { system("cls"); system("pause"); cout<<"显示学生数据"<<endl; 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<<"数据库连接错误!"<<endl; } else { char std[200]; int n,m; cout<<"请输入要改动的学号:"<<endl; cin>>n; cout<<"请输入要新的学号:"<<endl; cin>>m; sprintf(std,"update xueji set id=%d where id=%d;",m,n); if(mysql_query(&mysql, std)) { printf(" 数据库更改错误发生 "); } else { printf(" 数据库更改数据成功 "); } } } int Student::xiu_gai()//定义改动函数 { cout<<"进入改动系统..."<<endl; 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<<"数据库连接错误!
"<<endl; } 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<<"请选择正确的菜单项进行操作。多谢合作!"<<endl; } } } 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<<"数据库连接错误!
"<<endl; } 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<<"请选择正确的菜单项进行操作。多谢合作!"<<endl; } } } 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<<"数据库连接错误!
"<<endl; } 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<<"请选择正确的菜单项进行操作。多谢合作!"<<endl; } } } 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<<"数据库连接错误!"<<endl; } 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<<"请选择正确的菜单项进行操作。
多谢合作!"<<endl; } } } 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<<"数据库连接错误!
"<<endl; } else { cout<<"请录入学生信息数据"<<endl<<endl<<"录入格式说明:输入一项按Enter键进行下一项的输入"<<endl<<endl; mysql_query(&mysql, "SET NAMES LATIN1"); cout<<"学号 "<<"姓名 "<<"性别 "<<"民族 "<<"籍贯 "<<"身份证 "<<"QQ "<<"电话 "<<"成绩 "<<endl; 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<<"加入成功"<<endl; } } 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<<"--------------------------------------显示信息----------------------------------------"<<endl; cout<<" 学号 "<<" 姓名 "<<"性别 "<<"民族 "<<"籍贯 "<<" 身份证 "<<" QQ "<<" 电话 "<<" 成绩 "<<endl; cout<<"--------------------------------------------------------------------------------------"<<endl; 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<numFields;i++) { mysql_query(&mysql,"SET NAMES LATIN1"); cout<<" "<<row[i]<<" "; } cout<<endl; cout<<"--------------------------------------------------------------------------------------"<<endl; } } else { cout<<"显示无果!"; } } mysql_free_result(resultset); } } int Student::main_menu()//主菜单 { system("pause"); system("cls"); int s; cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl <<" 1: 录入学生信息 "<<endl <<" 2: 显示学生信息 "<<endl <<" 3: 查找学生信息 "<<endl <<" 4: 删除学生信息 "<<endl <<" 5: 改动学生信息 "<<endl <<" 6: 统计学生成绩 "<<endl <<" 0: 退出系统 "<<endl <<" 请选择:"; cin>>s; return s; } int Student::xiu_gai_menu()//改动菜单 { system("pause"); system("cls"); int a; cout<<endl<<endl<<endl<<endl<<endl <<" 1: 改动学号 "<<endl <<" 2: 改动姓名 "<<endl <<" 3: 改动性别 "<<endl <<" 4: 改动民族 "<<endl <<" 5: 改动籍贯 "<<endl <<" 6: 改动身份证 "<<endl <<" 7: 改动QQ号 "<<endl <<" 8: 改动手机号 "<<endl <<" 9: 改动成绩 "<<endl <<" 0: 返回上一层 "<<endl <<" 请选择:"; cin>>a; return a; } int Student::cha_xun_menu()//查询菜单 { system("pause"); system("cls"); int k; cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl <<" 1: 按学号查找 "<<endl <<" 2: 按姓名查找 "<<endl <<" 0: 返回上一层 "<<endl <<" 请选择:"; cin>>k; return k; } int Student::shan_menu()//删除菜单 { system("pause"); system("cls"); int g; cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl <<" 1: 按学号删除 "<<endl <<" 2: 按姓名删除 "<<endl <<" 0: 返回上一层 "<<endl <<" 请选择:"; cin>>g; return g; } int Student::score_tong_ji_menu()//成绩统计菜单 { system("pause"); system("cls"); int d; cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl <<" 1: 对成绩进行排序 "<<endl <<" 2: 最高和最低成绩的学生信息 "<<endl <<" 3: 全体学生的平均分 "<<endl <<" 4: 及格率 "<<endl <<" 0: 返回上一层 "<<endl <<" 请选择:"; 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<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl; cout<<" ··········"<<endl; cout<<" ***···谢谢使用···***"<<endl; cout<<" ··········"<<endl<<endl<<endl<<endl<<endl<<endl; exit(1); break; default: cout<<"请选择正确的菜单项进行操作。多谢合作!"<<endl; } } } return 0; }