| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 973 人关注过本帖
标题:大神们帮忙改成C程序(学生管理系统)
只看楼主 加入收藏
myckkk
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-10-31
结帖率:0
收藏
已结贴  问题点数:20 回复次数:12 
大神们帮忙改成C程序(学生管理系统)
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<fstream>         //主要包含文件操作的类和方法
#include<time.h>        /*文件里面有对某些时间函数的原型。原型的函数定义放在库文件里*/
using namespace std;
class student
{     
private:
    char xh[20];
    char name[50];
    double math;
    double history;
    double english;
    double average;
    double sum;
   
public:
    student()
    {
    }
    student(char xh1[20],char name1[50],double ma,double his,double eng)
    {
        strcpy(name,name1);
        strcpy(xh,xh1);
        math=ma;
        history=his;
        english=eng;
    }
    double getsum()
    {
        sum=history+english+math;
        return sum;
    }
    double getaver()
    {
        average=getsum()/3.0;
        return average;
    }
    friend void main();
};
void main()

{  char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

time_t timep;
time(&timep);
struct tm *p;
p=localtime(&timep);       /* 获取当前时间*/      

{         cout<<"                  ";
cout<<"**************欢迎进入******************"<<endl;
printf("                      【%d年%02d月%02d日 ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);      
printf("%s %02d:%02d:%02d】\n",week[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);
cout<<"                  ";
cout<<"************学生管理系统****************"<<endl<<endl;


cout<<"                                 *控制台*                           "<<endl;
cout<<"          *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<"          *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<"          * * * * * * ** 输入你的选择,并按回车结束 * * * * * * * * *"<<endl;
cout<<"          * * 请选择你所需要的操作:                               * *"<<endl;
cout<<"          * * (0)信息输入            *  (5)按历史排名             * *"<<endl;
cout<<"          * * (1)增加人员            *  (6)输出所有学生的信息     * *"<<endl;
cout<<"          * * (2)删除人员            *  (7)按总分查询排名         * *"<<endl;
cout<<"          * * (3)修改信息            *  (8)退出                   * *"<<endl;
cout<<"          * * (4)按数学排名          *  (9)按英语排名             * *"<<endl;
cout<<"          * *  退出按8               *  (a)按平均分排名           * *"<<endl;
cout<<"          * * *-*-*-*-*-* * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * *"<<endl;
cout<<"          * * * * * * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *"<<endl;
cout<<"             ***选择相关操作请输入相对的括号里的阿拉伯数字!"<<"***"<<endl;
}
char a;
char b;
student *stu[80];
ofstream *file[80];
int i=0;
int j=0;
bool flag2=0;
do
{    cin>>a;

if((a>='0'&&a<='10'))
flag2=1;
else
cout<<"输入错误!请重新输入:"<<endl;
}
while(flag2==0);
do{
    switch(a)
    {
    case '0':
        {
            char c;
            char xh[20];
            char name[50];
            double math;
            double history;
            double english;
            
            do{   
                cout<<"请输入学号"<<endl;
                cin>>xh;
                cout<<"请输入姓名"<<endl;
                cin>>name;
                cout<<"请输入数学成绩:"<<endl;
                cin>>math;
                cout<<"请输入历史成绩:"<<endl;
                cin>>history;
                cout<<"请输入英语成绩:"<<endl;
                cin>>english;
                file[j]=new ofstream("d:\\document",ios::ate);
                *file[j]<<"学号"<<xh<<"姓名"<<name<<"数学成绩"<<math<<"历史成绩"<<history<<"英语成绩"<<english<<endl;
                j++;
                stu[i]=new student(xh,name, math, history, english);
                i++;
                cout<<"信息录入成功,想继续录入吗(y/n)"<<endl;
                cin>>c;
                flag2=0;
                do
                {
                    if(c!='y'&&c!='n')
                    {
                        cout<<"输入错误!请重新输入!"<<endl;
                        cin>>c;
                    }
                    else
                        flag2=1;
                }
                while(flag2==0);
            }while(c=='y');
            break;
        }
        
                case '1':
                    {    char xh[20];
                    char name[50];
                    double math;
                    double history;
                    double english;
                    char c;
                    do
                    {   
                        cout<<"请输入您要增加的学生的学号:"<<endl;
                        cin>>xh;
                        cout<<"请输入您要增加的学生的姓名:"<<endl;
                        cin>>name;
                        cout<<"请输入数学成绩:"<<endl;
                        cin>>math;
                        cout<<"请输入历史成绩:"<<endl;
                        cin>>history;
                        cout<<"请输入英语成绩:"<<endl;
                        cin>>english;
                        file[j]=new ofstream("d:\\document",ios::ate);
                        *file[j]<<"学号"<<xh<<"姓名"<<name<<"数学成绩"<<math<<"历史成绩"<<history<<"英语成绩"<<english<<endl;
                        
                        
                        j++;
                        stu[i]=new student(xh,name,math,history,english);
                        i++;
                        cout<<"信息录入成功,想继续录入吗(y/n)"<<endl;
                        cin>>c;
                        if(c!='y'&&c!='n')
                        {
                            cout<<"输入错误!请重新输入!"<<endl;
                            cin>>c;
                        }
                    }
                    while(c=='y');
                    break;
                    }
                case '2':
                    {
                        char name[50];
                        bool flag3=0;
                        char c;
                        do{
                            cout<<"请输入您要删除的学生姓名:"<<endl;
                            cin>>name;
                            for(int h=0;h<i;h++)
                            {
                                if(strcmp(name,stu[h]->name)==0)
                                {
                                    flag3=1;
                                    i--;
                                    do{
                                        stu[h]=stu[h+1];
                                        h++;
                                    }
                                    while(h<=i);
                                }
                            }
                            if(flag3==0)
                                cout<<"您要求删除的学生本来就不存在!请检查输入的正 确性!";
                            cout<<"要继续删除吗?(y/n)"<<endl;
                            cin>>c;
                            if(c!='y'&&c!='n')
                            {
                                cout<<"输入错误!请重新输入!"<<endl;
                                cin>>c;
                            }
                        }while(c=='y');
                        break;
                    }
                case '3':
                    {   
                        char name[50];
                        double mat;
                        double his;
                        double eng;
                        flag2=0;
                        char c;
                        do
                        {   
                            cout<<"请输入您要修改的学生的姓名:"<<endl;
                            cin>>name;
                           
                            for(int h=0;h<i;h++)
                            {
                                if(strcmp(name,stu[h]->name)==0)
                                {
                                    flag2=1;
                                    cout<<"请输入新的数学成绩:"<<endl;
                                    cin>>mat;
                                    cout<<"请输入新的历史成绩:"<<endl;
                                    cin>>his;
                                    cout<<"请输入新的英语成绩:"<<endl;
                                    cin>>eng;
                                    stu[h]->history=his;
                                    stu[h]->math=mat;
                                    stu[h]->english=eng;
                                    cout<<"信息修改成功!";
                                }
                            }
                            if(flag2==0)
                            {
                                cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
                            }
                            cout<<"想继续修改吗(y/n)"<<endl;
                            cin>>c;
                            if(c!='y'&&c!='n')
                            {
                                cout<<"输入错误!请重新输入!"<<endl;
                                cin>>c;
                            }
                        }while(c=='y');
                        break;
                    }
                    
                case '4':
                    {
                        student e;
                        
                        cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if((stu[x]->math)>(stu[y]->math))
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        if(i==0)
                            cout<<"管理系统中没有录入数据或者数据已经被删除!";
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                case '5':
                    {
                        student e;
                        
                        cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if((stu[x]->history)>(stu[y]->history))
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        if(i==0)
                            cout<<"管理系统中没有录入数据或者数据已经被删除!";
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                    
                case '6':
                    {   
                        student e;
                        
                        cout<<"本系统所有学生排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if(strcmp((stu[x]->xh),(stu[y]->xh))<0)
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        if(i==0)
                            cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                    
                case '7':
                    {
                        student e;
                        
                        cout<<"本系统所有学生排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if((stu[x]->getsum())>(stu[y]->getsum()))
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        if(i==0)
                            cout<<"管理系统中没有录入数据或者数据已经被删除!";
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                case '8':
                    {char ch;
                    fflush(stdin);           /*刷新标准输入缓冲区,把输入缓冲区里的东西丢弃*/
                    cout<<"是否退出?(y/n)";
                    cin>>ch;
                    if(ch=='y')
                        exit(0);
                        }/*这个是stdlib的标准库函数,作用是调用操作系统功能结束程序并将参数0作为程序的返回值。
                         会释放掉程序运行中分配的各种资源,例如会释放掉分配的内存块、安全关闭打开的文件等。
                    exit(0)  用于程序正常结束*/
                    break;
                    
                case '9':
                    {
                        student e;
                        
                        cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if((stu[x]->english)>(stu[y]->english))
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        if(i==0)
                            cout<<"管理系统中没有录入数据或者数据已经被删除!";
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                    
                    
                case 'a':
                    {
                        student e;
                        
                        cout<<"本系统所有学生数学排名如下:"<<endl<<endl;
                        for(int x=0;x<i;x++)
                        {
                           
                            for(int y=0;y<i;y++)
                            {
                                if((stu[x]->getaver())>(stu[y]->getaver()))
                                    
                                    
                                {
                                    e=*stu[x];
                                    *stu[x]=*stu[y];
                                    *stu[y]=e;
                                }
                            }
                        }
                        if(i==0)
                            cout<<"管理系统中没有录入数据或者数据已经被删除!";
                        cout<<"名次"<<"     "<<"学号"<<"     "<<"姓名"<<"     "<<"历史"<<"     "<<"数学"<<"      "<<"英语"<<"     "<<"总分"<<"    "<<"平均分"<<endl;
                        for(int k=0;k<i;k++)
                        {   
                           
                            cout<<"   "<<k+1<<"      "<<stu[k]->xh<<"       "<<stu[k]->name<<"       "<<stu[k]->history<<"        "<<stu[k]->math<<"       "<<stu[k]->english<<"        "<<stu[k]->getsum()
                                <<"      "<<stu[k]->getaver()<<endl<<endl;
                        }
                        break;
                    }
                }
            cout<<endl;
            cout<<"您想继续进行其他操作(y)"<<endl;
            bool flag4=0;   
            do
            {
                cin>>b;
                if(b!='y'&&b!='n')
                    cout<<"输入错误!请重新输入!"<<endl;
                else
                    flag4=1;
            }
            
            while(flag4==0);
            if(b=='y')
               
               
               
                cout<<"                                 *控制台*                           "<<endl;
            cout<<"          *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
            cout<<"          *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
            cout<<"          * * * * * * ** 输入你的选择,并按回车结束 * * * * * * * * *"<<endl;
            cout<<"          * * 请选择你所需要的操作:                               * *"<<endl;
            cout<<"          * * (0)信息输入            *  (5)按历史排名             * *"<<endl;
            cout<<"          * * (1)增加人员            *  (6)输出所有学生的信息     * *"<<endl;
            cout<<"          * * (2)删除人员            *  (7)按总分查询排名         * *"<<endl;
            cout<<"          * * (3)修改信息            *  (8)退出                   * *"<<endl;
            cout<<"          * * (4)按数学排名          *  (9)按英语排名             * *"<<endl;
            cout<<"          * *  退出按8               *  (a)按平均分排名          * *"<<endl;
            cout<<"          * * *-*-*-*-*-* * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * *"<<endl;
            cout<<"          * * * * * * *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *"<<endl;
            cout<<"             ***选择相关操作请输入相对的括号里的阿拉伯数字!"<<"***"<<endl;
            
            cin>>a;
    }
    while(b=='y');
    cout<<"已退出程序"<<endl;
    for(int x=0;x<i;x++)
    {   
        delete stu[x];
        
        
    }
   
 }
 
 
搜索更多相关主题的帖子: history 管理系统 english private average 
2013-10-31 17:42
blueskiner
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:227
专家分:707
注 册:2008-9-22
收藏
得分:3 
修改这个有钱吗?
2013-10-31 19:04
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:3 
这本来就是个C语言的程序...

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-11-01 08:09
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:3 
楼主的意思,是把c++的改成c语言的?

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-11-01 08:21
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
我的意思是这本来就是一套C逻辑的语言,伪装了C++的外衣,有什么好改的...

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-11-01 13:01
myckkk
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-10-31
收藏
得分:0 
回复 4楼 yuccn
恩 是的
2013-11-02 18:02
myckkk
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-10-31
收藏
得分:0 
回复 5楼 peach5460
关键不会去那个外衣呀
2013-11-02 18:03
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:3 
这么长谁给你改 这是个作业罢
2013-11-02 23:13
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
回复 8楼 zklhp
估计是的

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-11-03 09:33
zhu404424118
Rank: 2
来 自:四川
等 级:论坛游民
威 望:1
帖 子:37
专家分:33
注 册:2013-10-31
收藏
得分:3 
改了有没有回报啊

自学c++求指导
2013-11-03 22:17
快速回复:大神们帮忙改成C程序(学生管理系统)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057282 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved