#include<iostream>
#include<string>
using namespace std;
struct sinhvien
{
int SBD;
string hoten;
sinhvien()
{
SBD=0;
hoten="";
}
void _input()
{
cout << "nhap SBD: ";
cin >> SBD;
cout << "nhap hoten: ";
getline(cin, hoten);
string temp;
getline(cin, temp);
}
void _output()
{
cout << hoten;
cout << " " << SBD <<endl;
}
};
class danhsach
{
private:
int size;
sinhvien arr[100];
public:
danhsach()
{
size=0;
}
~danhsach()
{
size=0;
}
void input()
{
cout<<"nhap so luong sinh vien: ";
cin >> size;
for(int i=0; i<size; i++)
{
arr[i]._input();
}
}
void output()
{
for(int i=0; i<size; i++)
{
arr[i]._output();
}
}
void insert(int pos, sinhvien value)
{
for(int i=size; i>pos-1; i--)
{
arr[i].hoten=arr[i-1].hoten;
arr[i].SBD=arr[i-1].SBD;
}
arr[pos-1].SBD=value.SBD;
arr[pos-1].hoten=value.hoten;
size++;
}
void del(int pos)
{
for(int i=pos-1; i<size-1; i--)
{
arr[i].hoten=arr[i+1].hoten;
arr[i].SBD=arr[i+1].SBD;
}
size--;
}
};
int main()
{
danhsach ds1;
ds1.input();
int pos, pos_del;
sinhvien value;
cout<<"du lieu them:"<<endl;
value._input();
cout << "nhap vi tri them: ";
cin >> pos;
ds1.insert(pos, value);
ds1.output();
cout<<"nhap vi tri xoa: ";
cin >> pos_del;
ds1.del(pos_del);
ds1.output();
system("pause");
}
yêu cầu đề bài: hàm insert() để thêm sinh viên;
del() để xóa sinh viên;
khi em chạy hàm insert(), del() thì chỉ in ra SBD. Các bác xem giúp em với:((