实验二 线性表综合实验之顺序表
2017-09-28 23:35
471 查看
一、实验目的
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二、实验内容
建立一个有n个学生成绩的顺序表,n的大小由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
三、算法实现
if(a[i]<0||a[i]>100){
cout<<"\t\t(输入有误,此成绩请重输!)\n";
i--;
}else continue;
}
try{
Score_seqList s(a,n);
system("cls");
menu(s);
}catch(char *p){
cout<
四、运行结果
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二、实验内容
建立一个有n个学生成绩的顺序表,n的大小由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
三、算法实现
#include using namespace std; const int MaxSize=100; class Score_seqList{ private: float score[MaxSize]; int length; public: Score_seqList(){length=0;} Score_seqList(float a[],int n); int getLength(){return length;} void insert(int i,float score); float getValue(int index); void locate(float x); void modify(int i,float x); float _delete(int index); void print(); }; Score_seqList::Score_seqList(float a[],int n){ if(n>MaxSize) throw"\t\t\t参数非法!\n"; for(int i=0;ilength) throw"\t\t\t插入位置非法!\n"; for(int j=length;j>i-1;j--){ score[j]=score[j-1]; } score[i-1]=x; length++; } float Score_seqList::getValue(int index){ if(index<1||index>length) throw"\t\t\t查找位置非法!\n"; return score[index-1]; } void Score_seqList::locate(float x){ bool boo=false; for(int i=0;ilength) throw"\t\t\t修改位置错误!\n"; score[i-1]=x; cout<<"\t\t\t修改成功!\n"; } float Score_seqList::_delete(int index){ if(length==0) throw"\t\t\t成绩为空!"; if(index<1||index>length) throw"\t\t\t删除位置非法!\n"; float x=score[index-1]; for(int i=index-1;i>a; system("cls"); try{ switch(a){ case 1: cout<<"\t\t\t成绩表长度为:"<>index; cout<<"\t\t\t请输入插入的成绩:"; cin>>x; s.insert(index,x); cout<<"\t\t\t插入成功!\n"; break; case 3: cout<<"\t\t\t请输入查找序号:"; cin>>index; cout<<"\t\t\t序号为"<>x; cout<<"\t\t\t序号有:"; s.locate(x); cout<>index; cout<<"\t\t\t成绩修改为:"; cin>>x; s.modify(index,x); break; case 6: cout<<"\t\t\t请输入删除位置:"; cin>>index; cout<<"\t\t\t删除成绩为 "<>c; if(c=='n'||c=='N'){ system("cls"); return 0; }else{ system("cls"); menu(s); } return 0; } int main(){ int n; float a[100]; cout<<"\n\t\t================新建成绩表(100分制)================\n\n"; cout<<"\t\t\t请输入成绩个数:"; cin>>n; try{ if(n<0) throw"\t\t\t输入有误!\n"; if(n>100) throw"\t\t\t溢出!\n"; }catch(char *p){ cout<>a[i];
if(a[i]<0||a[i]>100){
cout<<"\t\t(输入有误,此成绩请重输!)\n";
i--;
}else continue;
}
try{
Score_seqList s(a,n);
system("cls");
menu(s);
}catch(char *p){
cout<
四、运行结果
相关文章推荐
- 《数据结构》实验二: 线性表综合实验——(1)顺序表
- 线性表综合实验之顺序表
- 实验二 线性表综合实验之双链表
- 《数据结构》实验二:线性表综合实验——(4)静态链表
- 实验二线性表综合实验-顺序表
- 《数据结构》实验二:线性表综合实验——(3)双链表
- 数据结构实验一:基于线性表的学生信息管理(顺序结构)
- 《数据结构》实验二:线性表的实验(顺序表)
- 《数据结构》实验二: 线性表综合实验——总结线性表的几种主要存储结果
- 《数据结构》实验二:线性表的实验(顺序表)
- 实验二线性表综合实验-单链表
- 实验二 线性表综合实验之单链表
- 《数据结构》实验二:线性表实验(顺序表)
- 信管16数据结构:实验二 线性表综合实验
- 实验二 线性表综合实验之《单链表》
- 《数据结构》实验二: 线性表综合实验——总结线性表的几种主要存储结果
- 实验二线性表综合实验-双链表
- [SDUT](2116)数据结构实验之链表一:顺序建立链表 ---链式存储(线性表)
- 终于完成~《数据结构》实验二:线性表的实验(实现一个N个学生成绩的顺序表)
- 实验报告1—线性表的顺序结构