dddddddddddd
//Tao class dslk
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<math.h>
#include<iomanip.h>
//----------
class sglt
{
protected:
int count;
struct node
{
void *dataptr;
node*next;
};
node*head;
node*tail;
private:
void copy(const sglt >);
public:
void ErrorHandler();
sglt();
sglt(const sglt <);
void operator=(const sglt <);
virtual int Store(void *item);
virtual void*Examine();
virtual void*Retrieve();
int GetCount();
virtual void clear();
};
//-----------
void sglt::ErrorHandler()
{
cout<<"
Loi: cap phat bo nho that bai";
}
//----------
void sglt::copy(const sglt <)
{
node *item;//khai bao 1 con tro
head=NULL;tail=NULL;
item=lt.head;
while(item!=NULL)
{
if(head==NULL)
{
head=new node;
if(head==NULL)ErrorHandler();
tail=head;
}
else
{
tail->next=new node;
if(tail->next==NULL)ErrorHandler();
tail=tail->next;
}
tail->dataptr=item->dataptr;
tail->next=NULL;
item=item->next;
}
}
//----------
sglt::sglt()
{
head=NULL;tail=NULL;count=0;
}
//-------
sglt::sglt(const sglt <)
{
copy(lt);
}
//--------
void sglt::operator=(const sglt <)
{
count =lt.count;
copy(lt);
}
//----------
int sglt::Store(void *item)
{
node *p;
p=new node;
if(p==NULL)return 1;
p->dataptr=item;
p->next=head;
head=p;count++;
return 0;
}
//------------
void *sglt::Examine()
{
if(count==0)return NULL;
else{return head->dataptr;}
}
//---------
void *sglt::Retrieve()
{
if(count==0)return NULL;
else
{
node *p;
void *value;
value=head->dataptr;
p=head;
head=p->next;
count--;
return value;
}
}
//----------
int sglt::GetCount()
{return count;}
//----------
void sglt::clear()
{
count=0;
node*p,*q;
p=head;head=NULL;tail=NULL;
while(p!=NULL)
{q=p;p=q->next;
delete q;}
}
//----------
struct sinhvien
{
char msv[30];
char ht[30];
int ns;
float dtb;
};
//----------
int main()
{
sglt mlt=sglt();
sinhvien sv,ds[30];
int n;
cout<<"
Nhap so luong sinh vien: ";cin>>n;
for(int i=0;i<n;i++)
{
cout<<"
Nhap thong tin SV "<<i+1<<"
";
cin.ignore();
cout<<"
MSV: ";gets(ds[i].msv);
cout<<"
HTSV: ";gets(ds[i].ht);
cout<<"
NS: ";cin>>ds[i].ns;;
cout<<"
DTB: ";cin>>ds[i].dtb;
mlt.Store(&ds[i]);
}
//----------
cout<<setw(45)<<"DANH SACH SINH VIEN
";
cout<<"
Ma Sinh Vien"<<setw(15)<<"Ho Va Ten"<<setw(20)<<"Nam Sinh"<<setw(25)<<"Diem Trung Binh
";
for(int i=0;i<n;i++)
{
cout<<ds[i].msv<<setw(24)<<ds[i].ht<<setw(18)<<ds[i].ns<<setw(20)<<ds[i].dtb;
cout<<"
";
}
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro