khi nhập sinh viên vào thì được nhưng xuất ra danh sách sinh viên chỉ xuất ra danh sách ban đầu
và em không hiểu tại sao khi truyền tham chiếu vào themmotsinhvien(int soluong,danhsach &ds) thì báo lỗi
đây là code của em
#include<iostream>
#include<string.h>
using namespace std;
typedef struct sinhvien
{
string ten;
float diem;
int mssv;
};
void nhapsinhvien(sinhvien &x)
{
fflush(stdin);
cout<<"\nnhap ten sinh vien:";
getline(cin,x.ten);
fflush(stdin);
cout<<"\nnhap diem:";cin>>x.diem;
fflush(stdin);
cout<<"\nnhap ma sinh vien:";cin>>x.mssv;
}
void xuatmotsinhvien(sinhvien x)
{
cout<<"\nten:"<<x.ten;
cout<<"\ndiem:"<<x.diem;
cout<<"\nmssv:"<<x.mssv;
}
typedef struct danhsach
{
int n;
sinhvien *arr;
};
void nhapnhieusinhvien(danhsach ds)
{
int i;
for(i=0;i<ds.n;i++)
{
nhapsinhvien(ds.arr[i]);
}
}
void xuatnhieusinhvien(danhsach ds)
{
int i;
for(i=0;i<ds.n;i++)
{
xuatmotsinhvien(ds.arr[i]);
}
}
void themmotsinhvien(int soluong,danhsach ds)
{
sinhvien t;
int i,z;
z=(ds.n)+soluong;
for(i=ds.n;i<z;i++)
{
ds.arr=new sinhvien[(ds.n)++];
nhapsinhvien(t);
}
}
int main()
{
int soluong;
sinhvien x;
danhsach ds;
cout<<"nhap so luong sinh vien:";cin>>ds.n;
ds.arr=new sinhvien[ds.n];
nhapnhieusinhvien(ds);
cout<<"\nmang sau khi them sinh vien:";
cout<<"\nnhap so luong sinh vien can them:";cin>>soluong;
themmotsinhvien(soluong,ds);
xuatnhieusinhvien(ds);
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?