Code:
#include "stdafx.h" #include "string.h" struct date { int ngay; int thang; int nam; }ngaysinh; typedef struct sv { char mssv[10]; char hoten[50]; struct date ngaysinh; int diemtoana1; int diemlya1; int diem********; float diemTB; }sv; typedef struct tagdnode { sv info; struct tagdnode*pnext; struct tagdnode*pprev; }dnodesv; typedef struct tagdlist { dnodesv*phead; dnodesv*ptail; }dlistsv; void createlist(dlistsv &l) { l.phead=l.ptail=NULL; } dnodesv *creatednodesv() { dnodesv *p; sv t; p=new dnodesv; if(p==NULL) return NULL; else { printf("\nnhap MSSV: "); fflush(stdin); gets_s(t.mssv); strcpy_s(p->info.mssv,t.mssv); printf("nhap ten sinh vien: "); fflush(stdin); gets_s(t.hoten); strcpy_s(p->info.hoten,t.hoten); printf("ngay sinh(dd/mm/yyyy): "); scanf_s("%d %d %d",&t.ngaysinh.ngay,&t.ngaysinh.thang,&t.ngaysinh.nam); p->info.ngaysinh.ngay=t.ngaysinh.ngay; p->info.ngaysinh.thang=t.ngaysinh.thang; p->info.ngaysinh.nam=t.ngaysinh.nam; printf("nhap diem toan A1: "); scanf_s("%d",&t.diemtoana1); p->info.diemtoana1=t.diemtoana1; printf("nhap diem ly A1: "); scanf_s("%d",&t.diemlya1); p->info.diemlya1=t.diemlya1; printf("nhap diem ngoai ngu: "); scanf_s("%d",&t.diem********); p->info.diem********=t.diem********; p->info.diemTB=float(((t.diemtoana1+t.diemlya1+t.diem********)/3.0)); p->pnext=NULL; p->pprev=NULL; return p; } } void addend(dlistsv &l,dnodesv *p) { if(l.phead==NULL) l.phead=l.ptail=p; else { p->pprev=l.ptail; l.ptail->pnext=p; p=l.ptail; } } void nhapsv(dlistsv &l) { int n,i; dnodesv *p; p=l.phead; printf("so sinh vien can nhap: "); scanf_s("%d",&n); for(i=0;i<n;i++) { printf("\nsinh vien thu %d",i+1); addend(l,creatednodesv()); } } void inds(dlistsv l) { dnodesv *p; p=l.phead; printf("\n+---------------------+-------------------+"); printf("\n|TEN SINH VIEN | NGAY SINH |"); printf("\n+---------------------+-------------------+"); while(p!=NULL) { printf("\n|%-20s | %-2d/%-2d/%-4d |",p->info.hoten,p->info.ngaysinh.ngay,p->info.ngaysinh.thang,p->info.ngaysinh.nam); printf("\n+----------------+---------------+----------------+---------------+"); printf("\n| DIEM TOAN A1 | DIEM LY A1 | DIEM NGOAI NGU | DIEM LY TB |"); printf("\n+----------------+---------------+----------------+---------------+"); printf("\n| %2d %2d %2d %2.2f |",p->info.diemtoana1,p->info.diemlya1,p->info.diem********,p->info.diemTB); printf("\n+----------------+---------------+----------------+---------------+"); p=p->pnext; } } void main() { dlistsv l; createlist(l); nhapsv(l); inds(l); }
Comment