⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实习1.1.cpp

📁 实现运动会分数统计,包括学校编号,男女子项目等
💻 CPP
字号:
#include<iostream.h>
#define  n 5
typedef struct Student
{
    int schoolNum;
    char name[20];
    int sex;
    int sportNum;
    int score;
    struct Student *next;
}Student,*List;

void Init(List &L)
{
    L=new Student;
    L->next=NULL;
}

    
void Insert(List &L,int i)//插入某学生记录 
{
    Student *newNode=new Student;
    cout<<"请输入第"<<i<<"个学生姓名:";
    cin>>newNode->name;
    cout<<"请输入第"<<i<<"学生所属的学校编号:";
   cin>>newNode->schoolNum;
    cout<<"请输入第"<<i<<"学生的性别(男的输入1,女的输入0):";
    cin>>newNode->sex;
    cout<<"请输入第"<<i<<"学生参加的项目号:";
    cin>>newNode->sportNum;
    cout<<"请输入第"<<i<<"学生的得分: ";
    cin>>newNode->score;
    newNode->next=NULL;
    Student *p=L;
    while(p->next!=NULL)
      p=p->next;
     p->next=newNode;
}
void Print(List L)
{
    Student *p=L->next;
    while(p!=NULL)
    {
        cout<<"score="<<p->score<<endl;
        p=p->next;
    }
}        
void printForSchool(List L )
{
    Student *p;
    int arr[100];
    int i,m=1;
    for(i=1;i<=n;i++)
      arr[i]=0;
    while(m<=n)
    {
        p=L->next;
        while(p!=NULL)
        {
            if(m==p->schoolNum)
              arr[m]+=p->score;
              p=p->next;
        }    
        m++;
    }
    cout<<"各学校团体总分:"<<endl;
    for(i=1;i<=n;i++)
      {cout<<"学校"<<i<<"的总成绩是:";
      cout<<arr[i]<<"."<<endl; }
     
}
int getStatus(List L,Student *m,int x)
{//取得某学生的名次 
    int s=1;
    Student *p=L->next;
    while(p)
    {
        if(p->score>m->score&&p->sportNum==x)
          s++;
        p=p->next;
    }
    return s;
}      
void printForSchoolSituation(List L, int m,int w)
{
    int s=1,t;
    int ss=1;
    Student *p=NULL;
    while(s<=n)
    { ss=1;
        cout<<"学校"<<s<<"的情况:"<<endl;
        cout<<"项目号\t"<<"成绩\t"<<"姓名\t"<<"名次\n"; 
        while(ss<=m+w)
        {
        p=L->next;
        while(p)
        {
            if(p->sportNum==ss&&p->schoolNum==s)
            {
                cout<<ss<<"\t"<<p->score<<"\t"<<p->name<<"\t";
                t=getStatus(L,p,ss);
                 if(ss%2!=0&&t<=5||ss%2==0&&t<=3)
                cout<<t<<endl;
                else
                 cout<<"-"<<endl;
            }
            p=p->next;
        }
        ss++;
        }    
        s++;
    }            
    cout<<endl;
}    
                
    
    
void printForMaleAndFemale(List L)
{
    Student *p=L->next;
    int male=0,female=0,t=1; 
    while(p!=NULL)
    {
        t=1;
        while(t)
        {
          if(p->sex==1)
          {
            male+=p->score;t=0;
          }
          else if(p->sex==0)
          {
            female+=p->score;t=0;
          }
          else 
          {p->sex=1;t=1;}
        }     
        p=p->next;
    }
    cout<<"男生团体总成绩:"<<male<<endl;
    cout<<"女生团体总成绩:"<<female<<endl; 
    cout<<"团体总成绩:"<<male+female<<endl; 
}        
 
   
int main()
{
    List L;
    Init(L);
    int  m,w,male=0,female=0;
    cout<<"请输入参加比赛的男生人数:"<<endl; 
    cin>>male;
    cout<<"请输入参加比赛的女生人数:"<<endl;
    cin>>female; 
    cout<<"请输入男子项目的个数:";
    cin>>m;
    cout<<"请输入有女子项目的个数:";
    cin>>w;
    cout<<endl;
    cout<<"奇数项目取前5名(7,5,3,2,1),偶数项目取前3名          (5,3,2)"<<endl; 
    cout<<"************************************"<<endl;
    if(male!=0)
    cout<<"请输入男子资料"<<endl; 
    for(int i=0;i<male;i++)
    Insert(L,i);
    if(female!=0)
    cout<<"请输入女子资料:"<<endl; 
    for(int j=0;j<female;j++)
    Insert(L,j); 
    printForSchool(L);
    cout<<endl<<"***********************************"<<endl;
    printForMaleAndFemale(L);
    cout<<endl<<"***********************************"<<endl;
    printForSchoolSituation(L,m,w);
    return 1;
}    
    
         
            
  
            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -