顺序表学生成绩系统

#include<iostream>
using namespace std;
class Student
{
private:
char *name[5];
int length;
float grade[5];
public:
Student(){length=0;}
Student(char *n[],float g[],int l);
~Student(){}
void insert(char *a,int b,float c);   //a=name,b=location,c=grade
void Delete(int b);
void locate(int b);
void print();
};


Student::Student(char *n[],float g[],int l)
{
for(int i=0;i<=3;i++)
{
name[i]=n[i];
grade[i]=g[i];
}
length=l;
}


void Student::insert(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 Student::Delete(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 Student::locate(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 Student::print()
{
if(length==0)cout<<"无数据"<<endl;
else
{
for(int i=0;i<length;i++)
cout<<name[i]<<" "<<grade[i]<<endl;
cout<<endl;
}
}


int main()
 {
cout<<"******************************"<<endl;
cout<<"        学生成绩系统"<<endl;
cout<<"******************************"<<endl;
char *n[2]={"ke","rou"};
float g[2]={78,87};
Student a(n,g,2);
int y;
float z;
char x[5];
for(int i=0;i<3;i++)
{
cout<<"@@@输入学生的名字:";
cin>>x;
cout<<endl<<"@@@输入学生的分数:";
cin>>z;
cout<<endl<<"@@@输入学生的学号:";
cin>>y;
cout<<endl;
}
a.insert(x,y,z);
cout<<endl<<"@@@输入要删除的学号:";
cin>>y;
a.Delete(y);
cout<<endl<<"@@@输入要查找的学生信息的学号:";
cin>>y; 
a.locate(y);
cout<<endl<<endl<<endl<<"*****************显示所有学生信息:"<<endl;
a.print();
return 0;
}

 
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页