顺序表学生成绩实验

顺序表实验

#include<iostream>

#include<string>

using namespace std;

const int MaxSize=10;

class Student

{

private:

       intGrade[MaxSize];

      

       char*name[MaxSize];

       intlenght;

public:

       Student(){lenght=0;}

       Student(char*a[],int b[],int x);

       ~Student(){};

       voidInsert(int i,char*n,int m);

       intDelete(int i);

       charLocate(char *k);

       voidPrint();

};

 

#include<iostream>

using namespace std;

#include "SeqList.h"

 

Student::Student(char *a[],int b[],int x)

{

       if(x>MaxSize)throw"上溢";

       for(inti=0;i<x;i++)

       {

              name[i]=a[i];

              Grade[i]=b[i];

             

       }

       lenght=x;

}

 

void Student::Insert(int i,char *n,int m)

{

       if(lenght>=MaxSize)throw"上溢";

       if(i<1||i>lenght+1)throw"位置非法";

       for(intj=lenght;j>=i;j--)

       {

              name[j]=name[j-1];

              Grade[j]=Grade[j-1];

             

 

       }

       name[i-1]=n;

       Grade[i-1]=m;

      

       lenght++;

}

 

int Student::Delete(int i)

{

       if(lenght==0)throw"下溢";

       if(i<1||i>lenght+1)throw"位置非法";

       charg=*name[i-1];

       for(intj=i;j<lenght;j++)

       {

              name[j-1]=name[j];

       }

       lenght--;

       returng;

}

 

char Student::Locate(char *k)

 

{

       for(inti=0;i<lenght;i++)

              if(name[i]==k)cout<<i+1<<endl;

       return0;

}

 

void Student::Print()

{

       for(inti=0;i<lenght;i++)

              cout<<name[i]<<""<<Grade[i]<<endl;

}

 

 

 

#include<iostream>

using namespace std;

#include "SeqList.h"

void main()

{

       char*r[5]={"A","B","C","D","E"};

       intg[5]={100,85,90,67,95};

       cout<<"执行插入操作前的数据为:"<<endl;

       StudentL(r,g,5);

       L.Print();

       try

       {

              L.Insert(2,"F",60);

       }

       catch(char*w)

       {

              cout<<w<<endl;

       }

       cout<<"执行插入操作后数据为:"<<endl;

       L.Print();

       cout<<"姓名为A的学生的序号为:"<<endl;

       cout<<L.Locate("A")<<endl;

       cout<<"执行删除第一个学生数据的操作,删除前数据为:"<<endl;

       L.Print();

       try

       {

              L.Delete(1);

       }

       catch(char*w)

       {

              cout<<w<<endl;

       }

       cout<<"删除后数据为:"<<endl;

       L.Print();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值