void print();
private:
char* name[5];
int length;
float grade[5];
};
stu::stu(char*a[],float g[],int l)
{for(int i=0;i<4;i++)
{name[i]=a[i];
grade[i]=g[i];
}length=l;
}
void stu::in(char*a,int b,float c)
{if(length==5) cout<<"满数据."<<endl;
else{length++;
for(int i=length;i>b;i--)
{name[i-1]=name[i-2];grade[i-1]=grade[i-2];}
name[b-1]=a;grade[b-1]=c;cout<<" 列入成功."<<endl;}}
void stu::de(int b)
{if(length==0) cout<<"无数据."<<endl;
else if(b<1||b>length) cout<<"位置错误."<<endl;
else{cout<<name[b-1]<<"的数据已被删除."<<endl;
for(int i=b;i<length;i++)
{name[i-1]=name[i];
grade[i-1]=grade[i];
} length--;}
}
void stu::search(int b)
{if(length==0) cout<<"无数据."<<endl;
else if(b<1||b>length) cout<<"位置错误."<<endl;
else{cout<<"第"<<b<<"位的数据为:"<<name[b-1]<<" "<<grade[b-1]<<endl<<endl;
}}
void stu::print()
{if(length==0) cout<<"无数据."<<endl;
else{for(int i=0;i<length;i++)
cout<<name[i]<<" "<<grade[i]<<endl;}}
int main()
{char*n[4]={"里","放","暗","分"};
float g[4]={80,79,81,86};
stu a(n,g,4);
int y;
float z;
char x[5];
a.print();
cout<<"输入你要列入的名字:";
cin>>x;
cout<<endl<<"分数:";
cin>>z;
cout<<endl<<"位置:";
cin>>y;
a.in(x,y,z);
a.print();
cout<<endl<<"要删除的位置:";
cin>>y;
a.de(y);
cout<<endl<<"要查找的数据的位置:";
cin>>y;
a.search(y);
cout<<"各成员数据如下:"<<endl;
a.print();
return 0;}
private:
char* name[5];
int length;
float grade[5];
};
stu::stu(char*a[],float g[],int l)
{for(int i=0;i<4;i++)
{name[i]=a[i];
grade[i]=g[i];
}length=l;
}
void stu::in(char*a,int b,float c)
{if(length==5) cout<<"满数据."<<endl;
else{length++;
for(int i=length;i>b;i--)
{name[i-1]=name[i-2];grade[i-1]=grade[i-2];}
name[b-1]=a;grade[b-1]=c;cout<<" 列入成功."<<endl;}}
void stu::de(int b)
{if(length==0) cout<<"无数据."<<endl;
else if(b<1||b>length) cout<<"位置错误."<<endl;
else{cout<<name[b-1]<<"的数据已被删除."<<endl;
for(int i=b;i<length;i++)
{name[i-1]=name[i];
grade[i-1]=grade[i];
} length--;}
}
void stu::search(int b)
{if(length==0) cout<<"无数据."<<endl;
else if(b<1||b>length) cout<<"位置错误."<<endl;
else{cout<<"第"<<b<<"位的数据为:"<<name[b-1]<<" "<<grade[b-1]<<endl<<endl;
}}
void stu::print()
{if(length==0) cout<<"无数据."<<endl;
else{for(int i=0;i<length;i++)
cout<<name[i]<<" "<<grade[i]<<endl;}}
int main()
{char*n[4]={"里","放","暗","分"};
float g[4]={80,79,81,86};
stu a(n,g,4);
int y;
float z;
char x[5];
a.print();
cout<<"输入你要列入的名字:";
cin>>x;
cout<<endl<<"分数:";
cin>>z;
cout<<endl<<"位置:";
cin>>y;
a.in(x,y,z);
a.print();
cout<<endl<<"要删除的位置:";
cin>>y;
a.de(y);
cout<<endl<<"要查找的数据的位置:";
cin>>y;
a.search(y);
cout<<"各成员数据如下:"<<endl;
a.print();
return 0;}