对于最多由100名学生的姓名和成绩信息(如王洪、90)构成的线性表,采用顺序存储结构完成下面的问题
①统计成绩大于等于95分的人数,并输出这些学生的姓名
②删除成绩小于20分的成绩
③以60分为分界线,将表中所有小于60分的元素放在表的前半部分,大于和等于60分的元素放在表的后半部分。
#include "stdafx.h"
#include<iostream>
using namespace std;
int MAX=100; //人数上限
typedef void S;
typedef struct Student
{ int Grade[100000];
int top;
char a[100000];
int length;}*student;
void judge(student s);
student Init_SeqList(student &s);
student excellent(student &s);
student deletebad(student &s);
student arrange(student &s);
student inti_Sq()
{ student s;
s=NULL;
s->length=0;
s->top=-1;
return s;}
void judge(student s)
{ if(s->length<0||s->length>100)
cout<<"该表创建失败!"<<endl;
return;
if(s->length>0&&s->length<=100)
cout<<"该表创建成功!"<<endl;}
student Init_SeqList(student&s)
{
cout<<"请输入学生的人数:"<<endl;
cin>>s->length;
cout<<"请输入学生的姓名:"<<endl;
for(int i=0;i<s->length-1;i++)
{cin>>s->a[i];}
cout<<"请依次输入学生的成绩:"<<endl;
for(int i=0;i<s->length-1;i++)
{ cin>>s->Grade[i];}
return s;}
student excellent(student& s)
{
int j=0; //j代表成绩大于等于95的人数
for(int i=0;i<s->length-1;i++)
if(s->Grade[i]>=95)
{ j++;
cout<<j<<s->a[i];}
cout<<"以上是成绩大于等于95分的人数与学生姓名"<<endl;
return s;}
student deletebad(student& s)
{
for(int i=0;i<s->length;i++)
if(s->Grade[i]<20)
{ s->a[i]=s->a[i+1];
s->length--;
for(int i=0;i<s->length-1;i++)
{ cout<<s->a[i];}}
cout<<"以上是删除成绩小于20分后的信息表:"<<endl;
return s;}
student arrange(student& s)
{ int a=60,i=0,j=s->length-1;
int temp=0;
while(i<j)
{if(s->Grade[i]<a)
i++;
if(s->Grade[j]>=a)
j--;
if(s->Grade[i]>=60&&s->Grade[j]<60)
{temp=s->Grade[i];
s->Grade[i]=s->Grade[j];
s->Grade[j]=temp;}
}
for(int i=0;i<s->length;i++)
cout<<s->Grade[i];
cout<<"以上是经过调整后的数组"<<endl;
return s;}
int main()
{ student S=inti_Sq();
Init_SeqList(S);
judge(S);
excellent(S);
deletebad(S);
arrange(S);
return 0;
}