Nhập Xuất Danh sách Liên Kết Đơn Về quản Lý HSSV
- Code:
-
#include<iostream>
using namespace std;
#define max 100
#pragma once
struct SINHVIEN
{
char mssv[10];
char tensv[30];
int gioitinh;
char diachi[30];
float diemtb;
};
struct NODE
{
NODE*next;
SINHVIEN key;
};
struct LIST
{
NODE*Head,*Tail;
};
void NhapSV(SINHVIEN &SV);
void XuatSV(SINHVIEN SV);
void KhoiTao(LIST &l);
NODE*TaoNode(SINHVIEN x);
void ThemDau(LIST &l,NODE *p);
void Nhap(LIST &l);
void XuatDS(LIST l);
void sapxep(SINHVIEN &SV);
- Code:
-
#include"khaibao.h"
void NhapSV(SINHVIEN &SV)
{
fflush(stdin);
cout<<"\nNhap ma SV: ";
cin.getline(SV.mssv,10);
fflush(stdin);
cout<<"Nhap ten SV: ";
cin.getline(SV.tensv,30);
fflush(stdin);
cout<<"Nhap gioitinh SV:0: nam, 1:nu ";
cin>>SV.gioitinh;
do{
if(SV.gioitinh<0||SV.gioitinh>1)
cout<<"Nhap sai ,nhap lai:";
}while (SV.gioitinh<0||SV.gioitinh>1);
cin.ignore();
cout<<"Nhap dia chi :";
cin.getline(SV.diachi,30);
cout<<"Nhap diem TB: ";
cin>>SV.diemtb;
}
void XuatSV(SINHVIEN SV)
{
cout<<"\nMa SV: "<<SV.mssv<<endl;
cout<<"\nTen SV: "<<SV.tensv<<endl;
if(SV.gioitinh==0)
cout<<"SV la Nam:";
else
cout<<"SV la NU:";
cout<<"\nDia chi: "<<SV.diachi<<endl;
cout<<"\nDiem Tb"<<SV.diemtb<<endl;
}
void KhoiTao(LIST &l)
{
l.Head=l.Tail=NULL;
}
NODE*TaoNode(SINHVIEN x)
{
NODE*p;
p=new NODE;
if(p==NULL)
{
cout<<"Khong cap phat dc vung nho,kt:";
exit(0);
}
p->key=x;
p->next=NULL;
return p;
}
void ThemDau(LIST &l,NODE *p)
{
if (l.Head==NULL)
l.Head=l.Tail=p;
else
{
p->next=l.Head;
l.Head=p;
}
}
void Nhap(LIST &l)
{
NODE *p;
KhoiTao(l);
int i=1;
char tiep;
SINHVIEN x;
do{
cout<<"Nhap SV thu "<<i<<endl;
NhapSV(x);
p=TaoNode( x);
ThemDau(l,p);
cout<<"Ban co tiep tuc Y/N ?";
cin >>tiep;
}while (tiep=='Y'||tiep=='y');
}
void XuatDS(LIST l)
{
NODE *p=l.Head;
while(p)
{
XuatSV(p->key);
p=p->next;
}
}
void HoanVi(SINHVIEN &a,SINHVIEN &b)
{
SINHVIEN tam=a;
a=b;
b=tam;
}