#include<iostream>
#include"head.h"
using namespace std;
int main()
{
Indirection Student;
cout << "MENU";
int use = 0;
while (use != 6)
{
cout << "\n1.SET\n2.Delete\n3.Seek\n4.Print\n5.Insert\n6.Exit\nNow input a number to use function:";
cin >> use;
switch (use)
{
case 1:Student.Set(); break;
case 2:Student.Delete(); break;
case 3:Student.Seek(); break;
case 4:Student.Print(); break;
case 5:Student.Insert(); break;
default:
break;
}
}
return 0;
}
//function.cpp
#include<iostream>
#include"head.h"
using namespace std;
void Indirection::Set()
{
if (count == Maxsize) throw "overflow";
cout << "enter a score:";
double *s = new double;
cin >> *s;
score[count++] = s;
}
void Indirection::Delete()
{
if (count == 0) throw "no data";
cout << "enter the location you want to delete";
int location;
cin >> location;
if (location > Maxsize || location < 0) throw "wrong location";
if (score[location - 1] != NULL)
{
cout << "the score:" << *score[location - 1] << "is destroied";
score[location - 1] = NULL;
count--;
}
else cout << "no score you can delete";
}
void Indirection::Seek()
{
if (count == 0) throw "no data";
cout << "enter the location you want to find";
int location;
cin >> location;
if (location > Maxsize || location < 0) throw "wrong location";
if (score[location - 1] != NULL)
cout << "the score:" << *score[location - 1];
}
void Indirection::Print()
{
if (count == 0) throw "no data";
cout << "all score:";
for (int i = 0; i<count;)
{
if (score[i] != NULL)
{
cout << *score[i] << " ";
i++;
}
}
}
void Indirection::Insert()
{
if (count == Maxsize) throw "overflow";
cout << "enter the location you want to insert";
int location;
cin >> location;
if (location > Maxsize || location < 0) throw "wrong location";
double *s = new double;
cout << "the insert score are:";
cin >> *s;
if (score[location - 1] == NULL)
{
score[location - 1] = s;
count++;
}
else
{
for (int i = Maxsize - 1; i >= location - 1; i--)
{
score[i] = score[i - 1];
}
score[location-1] = s;
count++;
}
}