| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖
标题:求大神帮忙改一下源程序,小弟初学,很多东西弄不明白。
只看楼主 加入收藏
mdw422754799
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-7-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
求大神帮忙改一下源程序,小弟初学,很多东西弄不明白。
就是改一下,能不能用一维数组来解题。急求呀!!!
#include<iostream>
#include<string>
#include<iomanip>
Using namespace std;
class Stu
{
public:
    char number[4];
    char name[9];
    char Class[9];
    float chinese;
    float math;
    float English;
    float computer;
    float sport;
    Stu *next;
    float sum;
};
class Stu
{
public:
    Student()      {Head=NULL;    }
    void DisplayList();
    void InsertNode(Stu* position);   
    void EditNode();
    Stu *FindNode(char number[4]);            
    Stu *FindNode1(char Class[9]);
    Stu *FindNode2(char name[9]);
    void totalScores();                  
    void ScoresAverage();  
      void SortList();                          
    void AnalyzeScores();
    void printData(Stu *c);
private:
    Stu *Head;
    char FileName[100];
};
bool InputRecord(Stu *q)                  
{
    do
    {
        cout<<"学号:";
        cin>>q->number;
    }
    while(strlen(q->number)>4);
    do
    {
            cout<<"姓名:";
            cin>>q->name;
    }
    while(strlen(q->name)>9);
    do
    {
            cout<<"班级:";
            cin>>q->Class;
    }
    while(strlen(q->Class)>9);
    do
    {
            cout<<"语文:";
            cin>>q->chinese;
    }
    while(q->chinese>100||q->chinese<0);
    do
    {
            cout<<"数学:";
            cin>>q->math;
    }
    while(q->math>100||q->math<0);
    do
    {
            cout<<"英语:";
            cin>>q->English;
    }
    while(q->English>100||q->English<0);
    do
    {
            cout<<"计算机:";
            cin>>q->computer;
    }
    while(q->computer>100||q->computer<0);
    do
    {
            cout<<"体育:";
            cin>>q->sport;
            cout<<endl<<"****************************************************";
    }
    while(q->sport>100||q->sport<0);
        return true;
        
}
void Student::InsertNode(Stu* position)   
    {
        if(Head==NULL)   
            Head=position;
        else
        {
            if(FindNode(position->number) || FindNode(position->name))
            {
                cout<<"警告,存在相同学号的学生信息!";
                cout<<"****************************************************"<<endl;
        
                return;
            }
            else
            {
                Stu *p;
                p=Head;
                while(p->next!=NULL)
                    p=p->next;
                p->next=position;
            }
        }
        position->next=NULL;
    }
void Student::DisplayList()
    {
        float sum;
        if(!Head)
        {
            cout<<endl<<"内容为空!"<<endl;
            return;
        }
        cout<<endl;
        cout<<setw(8)<<"学号";
        cout<<setw(8)<<"姓名";
        cout<<setw(8)<<"班级";
        cout<<setw(8)<<"语文";
        cout<<setw(8)<<"数学";
        cout<<setw(8)<<"英语";
        cout<<setw(8)<<"计算机";
        cout<<setw(8)<<"体育";
        cout<<setw(8)<<"总分";
        cout<<endl<<"****************************************************";
        Stu *p;
        p=Head;
        while(p)
        {
            cout<<setw(8)<<p->number;
            cout<<setw(8)<<p->name;
            cout<<setw(8)<<p->Class;
            cout<<setw(8)<<p->chinese;
            cout<<setw(8)<<p->math;
            cout<<setw(8)<<p->English;
            cout<<setw(8)<<p->computer;
            cout<<setw(8)<<p->sport;
            sum = p->chinese+p->computer+p->math+p->English+p->sport;   
            cout<<setw(8)<<sum<<endl;
            p=p->next;
        }
        cout<<endl<<"*************************************************";        }
void Student::printData(Stu *p)
{
            cout<<endl;
            cout<<setw(8)<<"班级"<<setw(8)<<"姓名";
            cout<<setw(8)<<"学号"<<setw(8)<<"语文";
            cout<<setw(8)<<"数学"<<setw(8)<<"英语";
            cout<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
            cout<<setw(8)<<p->Class;
            cout<<setw(8)<<p->name;
            cout<<setw(9)<<p->number;
            cout<<setw(8)<<p->chinese;
            cout<<setw(8)<<p->math;
            cout<<setw(8)<<p->English;
            cout<<setw(8)<<p->computer;
            cout<<setw(8)<<p->sport;
}
        void Student::EditNode()         
    {
        char number[4];
        do
        {    cout<<endl<<"输入修改的学生学号";
            cin>>number;
        }
        while(strlen(number)>4);
         Stu *p1;
         if(p1=FindNode(number))
         {
             cout<<endl;
             cout<<"请输入该同学的新的信息:";
             InputRecord(p1);
             cout<<" 修改成功!";
             cout<<endl<<"***********************************************";
         }
         else
             cout<<"没有找到该学生信息,修改失败!";
             cout<<endl<<"******************************************";
        }
    void PrintRecord(Stu *p1)
    {
        cout<<endl;
        cout<<setw(4)<<"学号"<<setw(9)<<"姓名";
        cout<<setw(9)<<"班级"<<setw(8)<<"语文";
        cout<<setw(8)<<"数学"<<setw(8)<<"英语";
        cout<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
        cout<<setw(4)<<p1->number;
        cout<<setw(9)<<p1->name;
        cout<<setw(9)<<p1->Class;
        cout<<setw(8)<<p1->chinese;
        cout<<setw(8)<<p1->math;
        cout<<setw(8)<<p1->English;
        cout<<setw(8)<<p1->computer;
        cout<<setw(8)<<p1->sport;   
    }
Stu *Student::FindNode(char number[4])   
    {
        Stu *p1;
        p1=Head;
        while(p1)
        {
            if(strcmp(p1->number,number))
                p1=p1->next;
            else break;
        }
        if(p1)
        {
            cout<<endl;
            cout<<setw(4)<<"学号"<<setw(9)<<"姓名"<<setw(9)<<"班级"<<setw(8)<<"语文";
            cout<<setw(8)<<"数学"<<setw(8)<<"英语"<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
            cout<<setw(4)<<p1->number;
            cout<<setw(9)<<p1->name;
            cout<<setw(9)<<p1->Class;
            cout<<setw(8)<<p1->chinese;
            cout<<setw(8)<<p1->math;
            cout<<setw(8)<<p1->English;
            cout<<setw(8)<<p1->computer;
            cout<<setw(8)<<p1->sport;
            cout<<endl<<"*************************************";
        }
        else  cout<<endl;
        return p1;
    }
    Stu *Student::FindNode2(char name[9])   
    {
        Stu *p1;
        p1=Head;
        while(p1)
        {
            if(strcmp(p1->name,name))
                p1=p1->next;
            else break;
        }
        if(p1)
        {
            cout<<endl;
cout<<setw(4)<<"学号"<<setw(9)<<"姓名"<<setw(9)<<"班级"<<setw(8)<<"语文";
cout<<setw(8)<<"数学"<<setw(8)<<"英语"<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
            cout<<setw(4)<<p1->number;
            cout<<setw(9)<<p1->name;
            cout<<setw(9)<<p1->Class;
            cout<<setw(8)<<p1->chinese;
            cout<<setw(8)<<p1->math;
            cout<<setw(8)<<p1->English;
            cout<<setw(8)<<p1->computer;
            cout<<setw(8)<<p1->sport;
            cout<<endl;
            cout<<endl<<"*******************************";
        }
        else cout<<endl;
        return p1;
    }
    Stu *Student::FindNode1(char Class[9])     
    {
        int flag=0;
        Stu *p;
        p=Head;
        while(p!=NULL)
        {
            if(!strcmp(p->Class,Class))
            {   printData(p);
                flag=1;
            }
            p=p->next;
        }
        if(!flag)
            cout<<"没有找到你要的信息!";
        cout<<endl<<"*************************";
        return p;
    }
void Student::totalScores()     
{
    char number[4];
        float sum=0;
        do
        {    cout<<endl<<"输入学生学号";
            cin>>number;
        }
        while(strlen(number)>4);
         Stu *p1;
         if(p1=FindNode(number))
         { sum = p1->chinese+p1->computer+p1->math+p1->English+p1->sport;
                cout<<"***********************************总分:";
            cout<<sum<<"*************************************";
            cout<<"************************************";
         }
         else cout<<"输入错误!"<<endl<<"******************";
}
void Student::ScoresAverage()     
{
        char number[4];
        float sum=0,avg;
        do{    cout<<endl<<"输入学生学号";
            cin>>number;
        }
        while(strlen(number)>4);
         Stu *p1;
         if(p1=FindNode(number))
         { sum = p1->chinese+p1->computer+p1->math+p1->English+p1->sport;                avg=sum/5;
            cout<<"平均分:"<<sum/5<<endl;
            cout<<"******************************";
         }         
}
void Student::SortList()         
{
    if(!Head)
    {   cout<<endl<<"内容为空!"<<endl;
        return;
    }
    Stu *p1,*p2;
    p1=Head;
    p2=Head;
    while(p2)
    {
        float sum_max=p2->sum;   
        Stu *t1,*t2,*t3,*t4;
        t3=p2;
        t4=p2;
        t1=p2;
        t2=p2->next;
        while(t2)
        {
            if(sum_max<t2->sum)
            {    sum_max=t2->sum;
                t3=t1;
                t4=t2;
            }
            t1=t2;
            t2=t2->next;
        }
        if(p2->sum<t4->sum)
        {
            Stu *q3;
            if(p2==Head)
            {
                Head=t4;
                q3=t4->next;
                if(p2==t3)
                {
                    t4->next=p2;
                    p2->next=q3;
                }
                else
                {
                    t4->next=p2->next;
                    t3->next=p2;
                    p2->next=q3;
                }
                p1=Head;
                p2=p1->next;
            }
            else
            {
                if(p2==t3)
                {
                    p1->next=t4;
                    p2->next=t4->next;
                    t4->next=p2;
                }
                else
                {
                    p1->next=t4;
                    q3=t4->next;
                    t4->next=p2->next;
                    t3->next=p2;
                    p2->next=q3;
                }
                p1=p1->next;
                p2=p1->next;
            }
        }
        else
        {
            p1=p2;
            p2=p2->next;
        }
    }
}
void Student::AnalyzeScores()       {
    Stu *p;
    p=Head;
    char Class[8];
    float sum_chinese=0;
    float sum_maths=0;
    float sum_english=0;
    float sum_computer=0;
    float sum_sports=0;
    int i=0;
    do
    {
        cout<<"请输入要统计成绩的的班级名称:";
        cin>>Class;
        cout<<endl<<"*******************************";        }
    while(strlen(Class)>8);
    while(p)
    {
        if(!strcmp(p->Class,Class))
        {
            sum_chinese=sum_chinese+p->chinese;
            sum_maths=sum_maths+p->math;
            sum_english=sum_english+p->English;
            sum_computer=sum_computer+p->computer;
            sum_sports=sum_sports+p->sport;
            i++;            
        }
        p=p->next;
    }
    if(i==0)
    {
        cout<<"无此班级!";
        cout<<endl<<"***************************";
        return;
    }
    cout<<endl;
    cout<<setw(10)<<"科目"<<setw(10)<<"平均分"<<setw(10)<<"总分"<<endl;
    cout<<setw(10)<<"语文"<<setw(10)<<sum_chinese/i<<setw(10)<<sum_chinese<<endl;
    cout<<setw(10)<<"数学"<<setw(10)<<sum_maths/i<<setw(10)<<sum_maths<<endl;
    cout<<setw(10)<<"外语"<<setw(10)<<sum_english/i<<setw(10)<<sum_english<<endl;
    cout<<setw(10)<<"计算机"<<setw(10)<<sum_computer/i<<setw(10)<<sum_computer<<endl;
    cout<<setw(10)<<"体育"<<setw(10)<<sum_sports/i<<setw(10)<<sum_sports;
    cout<<endl<<"*********************************";   
     }
        void main()
    {
        int choi;
        Student ST;
        bool Flag=true;
        while(Flag)
        {
            cout<<" 学生成绩管理系统"<<endl;
        
            cout<<" ################"<<endl;
            cout<<"  1、输入学生成绩"<<endl;
            cout<<"  2、修改学生成绩"<<endl;
            cout<<"  3、删除学生成绩"<<endl;
            cout<<"  4、计算每位学生的总分"<<endl;
            cout<<"  5、计算每位学生的平均分"<<endl;     
            cout<<"  6、按学号或姓名查询学生成绩"<<endl;
            cout<<"  7、按班级查询学生成绩"<<endl;
            cout<<"  8、成绩排序"<<endl;
            cout<<"  9、按班级统计学科总分、平均分等"<<endl;
            cout<<"请选择(1-9,0:退出):" endl;
cout<<" ##################"<<endl;
           int menu,choice;
            //for(int i=0;i<10;i++)
           // cout<<menu[i]<<endl;
            cout<<menu;
            cin>>choice;

            switch(choice)
            {
            case 1:
                Stu *qq;
                qq=new Stu;
                if(InputRecord(qq))
                    ST.InsertNode(qq);        
                break;
            case 2:ST.EditNode();break;
            case 3:ST.totalScores();break;
            case 4:ST.ScoresAverage();break;
            case 5: char number[4];
               
                char name[9];
                    int key;
                cout<<"选择按学号/姓名查找:  [1]学号;[2]姓名 ";
                cin>>key;
                if(key==1)
                {
                    do
                    {   cout<<endl<<"输入要查询的学生学号:";
                        cin>>number;
                    }
                    while(strlen(number)>4);
                    ST.FindNode(number);
                }
                else if(key==2)
                {
                    do
                    {  cout<<endl<<"输入要查询的学生姓名:";
                       cin>>name;
                    }
                    while(strlen(name)>9);
                    ST.FindNode2(name);
                }
                else cout<<"对不起,您的输入有误!";
                cout<<endl<<"****************************";
                break;
            case 6:
                char Class[9];
                do{    cout<<endl<<"输入要查询的学生班级:";
                    cin>>Class;
                }while(strlen(Class)>9);
                    ST.FindNode1(Class);break;
            case 7:
                ST.SortList();
                ST.DisplayList();
                break;
            case 8:ST.AnalyzeScores();break;
            case 9:ST.DisplayList(); break;
            case 0:Flag=false;
                cout<<"谢谢使用,再见!";
                cout<<endl<<"***************************";
                break;
            default:
                cout<<"对不起,您的输入有误!";
                cout<<endl<<"*************";
            }
        }
    }

搜索更多相关主题的帖子: position computer English include public 
2013-07-16 10:10
love云彩
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:青藏高原
等 级:贵宾
威 望:53
帖 子:3663
专家分:11416
注 册:2012-11-17
收藏
得分:3 
这些代码就是用一维数组来解题的,我没看到哪里用到了二维数组

思考赐予新生,时间在于定义
2013-07-16 11:10
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:3 
都不知道题目是什么,洋洋洒洒丢一大段代码
脑残啊

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-07-16 11:39
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:3 
楼主应该先学习提问的技巧

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-07-16 12:03
AshineLee
Rank: 1
等 级:新手上路
帖 子:2
专家分:8
注 册:2013-7-17
收藏
得分:3 
直接贴代码,已经调试过了,建议换个编辑集成环境,有各种提示,方便
// Chengjiguanli.cpp : 定义控制台应用程序的入口点。
//

#include<iostream>
 #include<string>
 #include<iomanip>
 using namespace std;                    //U应为u
 class Stu
 {
 public:
     char number[4];
     char name[9];
     char Class[9];
     float chinese;
     float math;
     float English;
     float computer;
     float sport;
     Stu *next;
     float sum;
 };
 class Student                                  //跟上面类名一样了
 {
 public:
     Student()      {Head=NULL;    }
     void DisplayList();
     void InsertNode(Stu* position);   
     void EditNode();
     Stu *FindNode(char number[4]);            
     Stu *FindNode1(char Class[9]);
     Stu *FindNode2(char name[9]);
     void totalScores();                  
     void ScoresAverage();  
       void SortList();                          
     void AnalyzeScores();
     void printData(Stu *c);
 private:
     Stu *Head;
     char FileName[100];
 };
 bool InputRecord(Stu *q)
 {
     do
     {
         cout<<"学号:";
         cin>>q->number;
     }
     while(strlen(q->number)>4||strlen(q->number)<0);
     do
     {
             cout<<"姓名:";
             cin>>q->name;
     }
     while(strlen(q->name)>9||strlen(q->name)<0);
     do
     {
             cout<<"班级:";
             cin>>q->Class;
     }
     while(strlen(q->Class)>9||strlen(q->Class)<0);
     do
     {
             cout<<"语文:";
             cin>>q->chinese;
     }
     while(q->chinese>100||q->chinese<0);
     do
     {
             cout<<"数学:";
             cin>>q->math;
     }
     while(q->math>100||q->math<0);
     do
     {
             cout<<"英语:";
             cin>>q->English;
     }
     while(q->English>100||q->English<0);
     do
     {
             cout<<"计算机:";
             cin>>q->computer;
     }
     while(q->computer>100||q->computer<0);
     do
     {
             cout<<"体育:";
             cin>>q->sport;
             cout<<endl<<"****************************************************";
     }
     while(q->sport>100||q->sport<0);
         return true;
         
 }
 void Student::InsertNode(Stu* position)   
     {
         if(Head==NULL)   
             Head=position;
         else
         {
             if(FindNode(position->number) || FindNode(position->name))
             {
                 cout<<"警告,存在相同学号的学生信息!";
                 cout<<"****************************************************"<<endl;
         
                 return;
             }
             else
             {
                 Stu *p;
                 p=Head;
                 while(p->next!=NULL)
                     p=p->next;
                 p->next=position;
             }
         }
         position->next=NULL;
     }
 void Student::DisplayList()
     {
         float sum;
         if(!Head)
         {
             cout<<endl<<"内容为空!"<<endl;
             return;
         }
         cout<<endl;
         cout<<setw(8)<<"学号";
         cout<<setw(8)<<"姓名";
         cout<<setw(8)<<"班级";
         cout<<setw(8)<<"语文";
         cout<<setw(8)<<"数学";
         cout<<setw(8)<<"英语";
         cout<<setw(8)<<"计算机";
         cout<<setw(8)<<"体育";
         cout<<setw(8)<<"总分";
         cout<<endl<<"****************************************************";
         Stu *p;
         p=Head;
         while(p)
         {
             cout<<setw(8)<<p->number;
             cout<<setw(8)<<p->name;
             cout<<setw(8)<<p->Class;
             cout<<setw(8)<<p->chinese;
             cout<<setw(8)<<p->math;
             cout<<setw(8)<<p->English;
             cout<<setw(8)<<p->computer;
             cout<<setw(8)<<p->sport;
             sum = p->chinese+p->computer+p->math+p->English+p->sport;   
             cout<<setw(8)<<sum<<endl;
             p=p->next;
         }
         cout<<endl<<"*************************************************";        }
 void Student::printData(Stu *p)
 {
             cout<<endl;
             cout<<setw(8)<<"班级"<<setw(8)<<"姓名";
             cout<<setw(8)<<"学号"<<setw(8)<<"语文";
             cout<<setw(8)<<"数学"<<setw(8)<<"英语";
             cout<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
             cout<<setw(8)<<p->Class;
             cout<<setw(8)<<p->name;
             cout<<setw(9)<<p->number;
             cout<<setw(8)<<p->chinese;
             cout<<setw(8)<<p->math;
             cout<<setw(8)<<p->English;
             cout<<setw(8)<<p->computer;
             cout<<setw(8)<<p->sport;
 }
         void Student::EditNode()         
     {
         char number[4];
         do
         {    cout<<endl<<"输入修改的学生学号";
             cin>>number;
         }
         while(strlen(number)>4);
          Stu *p1;
          if(p1=FindNode(number))
          {
              cout<<endl;
              cout<<"请输入该同学的新的信息:";
              InputRecord(p1);
              cout<<" 修改成功!";
              cout<<endl<<"***********************************************";
          }
          else
              cout<<"没有找到该学生信息,修改失败!";
              cout<<endl<<"******************************************";
         }
     void PrintRecord(Stu *p1)
     {
         cout<<endl;
         cout<<setw(4)<<"学号"<<setw(9)<<"姓名";
         cout<<setw(9)<<"班级"<<setw(8)<<"语文";
         cout<<setw(8)<<"数学"<<setw(8)<<"英语";
         cout<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
         cout<<setw(4)<<p1->number;
         cout<<setw(9)<<p1->name;
         cout<<setw(9)<<p1->Class;
         cout<<setw(8)<<p1->chinese;
         cout<<setw(8)<<p1->math;
         cout<<setw(8)<<p1->English;
         cout<<setw(8)<<p1->computer;
         cout<<setw(8)<<p1->sport;   
     }
 Stu *Student::FindNode(char number[4])   
     {
         Stu *p1;
         p1=Head;
         while(p1)
         {
             if(strcmp(p1->number,number))
                 p1=p1->next;
             else break;
         }
         if(p1)
         {
             cout<<endl;
             cout<<setw(4)<<"学号"<<setw(9)<<"姓名"<<setw(9)<<"班级"<<setw(8)<<"语文";
             cout<<setw(8)<<"数学"<<setw(8)<<"英语"<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
             cout<<setw(4)<<p1->number;
             cout<<setw(9)<<p1->name;
             cout<<setw(9)<<p1->Class;
             cout<<setw(8)<<p1->chinese;
             cout<<setw(8)<<p1->math;
             cout<<setw(8)<<p1->English;
             cout<<setw(8)<<p1->computer;
             cout<<setw(8)<<p1->sport;
             cout<<endl<<"*************************************";
         }
         else  cout<<endl;
         return p1;
     }
     Stu *Student::FindNode2(char name[9])   
     {
         Stu *p1;
         p1=Head;
         while(p1)
         {
             if(strcmp(p1->name,name))
                 p1=p1->next;
             else break;
         }
         if(p1)
         {
             cout<<endl;
 cout<<setw(4)<<"学号"<<setw(9)<<"姓名"<<setw(9)<<"班级"<<setw(8)<<"语文";
cout<<setw(8)<<"数学"<<setw(8)<<"英语"<<setw(8)<<"计算机"<<setw(8)<<"体育"<<endl;
             cout<<setw(4)<<p1->number;
             cout<<setw(9)<<p1->name;
             cout<<setw(9)<<p1->Class;
             cout<<setw(8)<<p1->chinese;
             cout<<setw(8)<<p1->math;
             cout<<setw(8)<<p1->English;
             cout<<setw(8)<<p1->computer;
             cout<<setw(8)<<p1->sport;
             cout<<endl;
             cout<<endl<<"*******************************";
         }
         else cout<<endl;
         return p1;
     }
     Stu *Student::FindNode1(char Class[9])     
     {
         int flag=0;
         Stu *p;
         p=Head;
         while(p!=NULL)
         {
             if(!strcmp(p->Class,Class))
             {   printData(p);
                 flag=1;
             }
             p=p->next;
         }
         if(!flag)
             cout<<"没有找到你要的信息!";
         cout<<endl<<"*************************";
         return p;
     }
 void Student::totalScores()     
 {
     char number[4];
         float sum=0;
         do
         {
             cout<<endl<<"输入学生学号";
             cin>>number;
         }
         while(strlen(number)>4);
          Stu *p1;
          if(p1=FindNode(number))
          {
              sum = p1->chinese+p1->computer+p1->math+p1->English+p1->sport;
              cout<<"***********************************总分:";
              cout<<sum<<"*************************************";
              cout<<"************************************";
          }
          else cout<<"输入错误!"<<endl<<"******************";
 }
 void Student::ScoresAverage()     
 {
         char number[4];
         float sum=0,avg;
         do{    cout<<endl<<"输入学生学号";
             cin>>number;
         }
         while(strlen(number)>4);
          Stu *p1;
          if(p1=FindNode(number))
          {
              sum = p1->chinese+p1->computer+p1->math+p1->English+p1->sport;
              avg=sum/5;
              cout<<"平均分:"<<sum/5<<endl;
              cout<<"******************************";
          }         
 }
 void Student::SortList()         
 {
     if(!Head)
     {   cout<<endl<<"内容为空!"<<endl;
         return;
     }
     Stu *p1,*p2;
     p1=Head;
     p2=Head;
     while(p2)
     {
         float sum_max=p2->sum;   
         Stu *t1,*t2,*t3,*t4;
         t3=p2;
         t4=p2;
         t1=p2;
         t2=p2->next;
         while(t2)
         {
             if(sum_max<t2->sum)
             {    sum_max=t2->sum;
                 t3=t1;
                 t4=t2;
             }
             t1=t2;
             t2=t2->next;
         }
         if(p2->sum<t4->sum)
         {
             Stu *q3;
             if(p2==Head)
             {
                 Head=t4;
                 q3=t4->next;
                 if(p2==t3)
                 {
                     t4->next=p2;
                     p2->next=q3;
                 }
                 else
                 {
                     t4->next=p2->next;
                     t3->next=p2;
                     p2->next=q3;
                 }
                 p1=Head;
                 p2=p1->next;
             }
             else
             {
                 if(p2==t3)
                 {
                     p1->next=t4;
                     p2->next=t4->next;
                     t4->next=p2;
                 }
                 else
                 {
                     p1->next=t4;
                     q3=t4->next;
                     t4->next=p2->next;
                     t3->next=p2;
                     p2->next=q3;
                 }
                 p1=p1->next;
                 p2=p1->next;
             }
         }
         else
         {
             p1=p2;
             p2=p2->next;
         }
     }
 }
 void Student::AnalyzeScores()       {
     Stu *p;
     p=Head;
     char Class[8];
     float sum_chinese=0;
     float sum_maths=0;
     float sum_english=0;
     float sum_computer=0;
     float sum_sports=0;
     int i=0;
     do
     {
         cout<<"请输入要统计成绩的的班级名称:";
         cin>>Class;
         cout<<endl<<"*******************************";        }
     while(strlen(Class)>8);
     while(p)
     {
         if(!strcmp(p->Class,Class))
         {
             sum_chinese=sum_chinese+p->chinese;
             sum_maths=sum_maths+p->math;
             sum_english=sum_english+p->English;
             sum_computer=sum_computer+p->computer;
             sum_sports=sum_sports+p->sport;
             i++;            
         }
         p=p->next;
     }
     if(i==0)
     {
         cout<<"无此班级!";
         cout<<endl<<"***************************";
         return;
     }
     cout<<endl;
     cout<<setw(10)<<"科目"<<setw(10)<<"平均分"<<setw(10)<<"总分"<<endl;
     cout<<setw(10)<<"语文"<<setw(10)<<sum_chinese/i<<setw(10)<<sum_chinese<<endl;
     cout<<setw(10)<<"数学"<<setw(10)<<sum_maths/i<<setw(10)<<sum_maths<<endl;
     cout<<setw(10)<<"外语"<<setw(10)<<sum_english/i<<setw(10)<<sum_english<<endl;
     cout<<setw(10)<<"计算机"<<setw(10)<<sum_computer/i<<setw(10)<<sum_computer<<endl;
     cout<<setw(10)<<"体育"<<setw(10)<<sum_sports/i<<setw(10)<<sum_sports;
     cout<<endl<<"*********************************";   
      }
 

int _tmain(int argc, _TCHAR* argv[])
{
//    int choi;                      //你后面用的是choice定义两次
         Student ST;
         bool Flag=true;
         while(Flag)
         {
             cout<<" 学生成绩管理系统"<<endl;
         
             cout<<" ################"<<endl;
             cout<<"  1、输入学生成绩"<<endl;
             cout<<"  2、修改学生成绩"<<endl;
             cout<<"  3、删除学生成绩"<<endl;
             cout<<"  4、计算每位学生的总分"<<endl;
             cout<<"  5、计算每位学生的平均分"<<endl;     
             cout<<"  6、按学号或姓名查询学生成绩"<<endl;
             cout<<"  7、按班级查询学生成绩"<<endl;
             cout<<"  8、成绩排序"<<endl;
             cout<<"  9、按班级统计学科总分、平均分等"<<endl;
             cout<<"请选择(1-9,0:退出):"<<endl;                         //endl前面少了<<
 cout<<" ##################"<<endl;
            int choice=0;                 //未初始化                //menu多余
             //for(int i=0;i<10;i++)
            // cout<<menu[i]<<endl;
             cout<<"menu"<<endl;                 //直接打印字符串menu
             cin>>choice;

             switch(choice)
             {
             case 1:
                 Stu *qq;
                 qq=new Stu;
                 if(InputRecord(qq))
                     ST.InsertNode(qq);        
                 break;
             case 2:ST.EditNode();break;
             case 3:ST.totalScores();break;
             case 4:ST.ScoresAverage();break;
             case 5: char number[4];
                 
                 char name[9];
                     int key;
                 cout<<"选择按学号/姓名查找:  [1]学号;[2]姓名 ";
                 cin>>key;
                 if(key==1)
                 {
                     do
                     {   cout<<endl<<"输入要查询的学生学号:";
                         cin>>number;
                     }
                     while(strlen(number)>4);
                     ST.FindNode(number);
                 }
                 else if(key==2)
                 {
                     do
                     {  cout<<endl<<"输入要查询的学生姓名:";
                        cin>>name;
                     }
                     while(strlen(name)>9);
                     ST.FindNode2(name);
                 }
                 else cout<<"对不起,您的输入有误!";
                 cout<<endl<<"****************************";
                 break;
             case 6:
                 char Class[9];
                 do{    cout<<endl<<"输入要查询的学生班级:";
                     cin>>Class;
                 }while(strlen(Class)>9);
                     ST.FindNode1(Class);break;
             case 7:
                 ST.SortList();
                 ST.DisplayList();
                 break;
             case 8:ST.AnalyzeScores();break;
             case 9:ST.DisplayList(); break;
             case 0:Flag=false;
                 cout<<"谢谢使用,再见!";
                 cout<<endl<<"***************************";
                 break;
             default:
                 cout<<"对不起,您的输入有误!";
                 cout<<endl<<"*************";
             }
         }
         system("pause");
    return 0;
}

2013-07-17 07:37
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:3 
作文讲究开篇入题,建议楼主把错误指正出来,或者困惑写出来

Maybe
2013-07-17 09:15
a983126334
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2013-7-17
收藏
得分:3 
回复,拿分,下载
2013-07-17 09:39
岁月如刀
Rank: 6Rank: 6
来 自:冰冻星球
等 级:侠之大者
威 望:7
帖 子:165
专家分:477
注 册:2013-7-21
收藏
得分:3 
这真是挑战我的耐心啊~~~不看不看~~~

Now. Game over.
2013-07-22 01:00
快速回复:求大神帮忙改一下源程序,小弟初学,很多东西弄不明白。
数据加载中...
 
   



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

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