一.实验目的
1.巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二.实验内容
1.建立一个由n个学生成绩的顺序表,n的大小由自己确定,每一个学生的成绩信息由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
三.实验步骤
1.通过建立一个Student类来储存姓名与成绩信息。
2.建立一个Student类的友元类Manage来设置成员函数以达到功能的实现。
单链表实现:
代码:
#include<iostream>
#include<fstream>
#include<string>
#include<stdio.h>
#include<conio.h>
#include<Windows.h>
using namespace std;
class Student
{
protected:
char Name[20];
string Score;
Student *next;
public:
Student(char *Name, string Score)
{
strcpy(this->Name, Name);
this->Score = Score;
}
friend class Manage;
};
class Manage
{
private:
Student *student;
public:
Manage()
{
student = 0;
}
~Manage()
{
Student *s;
s = student;
while (s)
{
s = s->next;
delete student;
student = s;
}
student = 0;
}
void Find(char