Maison > base de données > tutoriel mysql > 高校学生学籍系统C++&mysql_MySQL

高校学生学籍系统C++&mysql_MySQL

WBOY
Libérer: 2016-06-01 13:08:13
original
1216 Les gens l'ont consulté

#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;

}

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal