-Em chào mọi người em đang làm 1 bài quản lý bằng vector . Hiện em đang mắc ở việc xóa và thêm vào vector, 2 hàm em lập nó chạy không như ý em mọi người có thể gợi ý ,góp ý cho em hoặc cho em bài code tham khảo được không ạ.
-Đây là đề bài ạ(bài 2):
Còn đây là code em gõ thử trước ạ:
http://codepad.org/NhAhXeMs
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class thisinh{
private:
string sbd;
string hoten;
string gioitinh;
float dtoan;
float dly;
float dhoa;
public:
void nhap();
void xuat();
string getsbd();
};
void thisinh::nhap(){
string _sbd,_hoten,_gioitinh;
float _dtoan,_dly,_dhoa;
cout<<"\nVao so bao danh sinh vien:";
cin.ignore();getline(cin,_sbd);sbd=_sbd;
cout<<"Vao ho ten sinh vien:";
cin.ignore();getline(cin,_hoten);hoten=_hoten;
cout<<"Vao gioi tinh sinh vien:";
cin.ignore();getline(cin,_gioitinh);gioitinh=_gioitinh;
cout<<"Vao diem toan:";
cin>>_dtoan;dtoan=_dtoan;
cout<<"Vao diem ly:";
cin>>_dly;dly=_dly;
cout<<"Vao diem hoa:";
cin>>_dhoa;dhoa=_dhoa;
}
void thisinh::xuat(){
cout<<"\nSo bao danh :"<<sbd;
cout<<"\nHo ten:"<<hoten;
cout<<"\nGioi tinh:"<<gioitinh;
cout<<"\nDiem toan:"<<dtoan;
cout<<"\nDiem ly:"<<dly;
cout<<"\nDiem hoa:"<<dhoa;
}
string thisinh::getsbd(){
return sbd;
}
class quanly{
private:
vector<thisinh*> danhsach;
public:
void vao();
void ra();
//void thembk();
void xoa();
void thaythe();
};
void quanly::vao(){
int n;
thisinh *p=new thisinh;
cout<<"Nhap so thi sinh muon vao :";
cin>>n;
for(int i=0;i<n;i++){
p->nhap();
danhsach.push_back(p);
}
}
void quanly::ra(){
for(int i=0;i<danhsach.size();i++){
danhsach[i]->xuat();
}
}
//void quanly::thembk() {
// int x;
// cout << "Vao vi tri muon them"; cin >> x;
// x = x - 1;
// thisinh* p = new thisinh;
// p->nhap;
// danhsach.insert(danhsach.begin() + x,p);
//}
void quanly::xoa(){
string _sbd;
cout<<"\nNhap so bao danh thi sinh muon xoa:";
cin.ignore();getline(cin,_sbd);
for(int i=0;i<danhsach.size();i++){
if(danhsach[i]->getsbd()==_sbd){
danhsach.erase(danhsach.begin()+(i-1));
}
}
}
void quanly::thaythe(){
xoa();
//thembk();
}
int main(){
quanly khoa;
khoa.vao();
khoa.xoa();
khoa.ra();
return 0;
}





83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?