Code:
#include "stdio.h"
#include "conio.h"
typedef struct PhongHoc{
unsigned char ChieuDai;
unsigned char ChieuRong;
unsigned int SoHocVien ;
};
typedef struct PhongHoc * ptrPhongHoc;
//nhap 1 phong hoc
PhongHoc Nhap() {
PhongHoc nT;
printf("\tNhap chieu dai: ");
scanf("%d",&nT.ChieuDai);
printf("\tNhap chieu rong: ");
scanf("%d",&nT.ChieuRong);
printf("\tNhap so hoc vien : ");
scanf("%d",&nT.SoHocVien );
return nT;
}
//nhap n phong hoc
ptrPhongHoc Nhap(unsigned int n) {
ptrPhongHoc temp = new PhongHoc[n];
for(unsigned int i = 0; i<n; i++)
{
printf("Nhap phong hoc thu %d: \n",i);
temp[i] = Nhap();
}
return temp;
}
//xuat 1 phong hoc
void Xuat(PhongHoc nT)
{
printf("{%d,%d,%d}\t",nT.ChieuDai,nT.ChieuRong,nT.SoHocVien );
}
//xuat n phong hoc
void Xuat(ptrPhongHoc temp, unsigned int n) {
for(unsigned int i = 0; i<n; i++)
{
Xuat(temp[i]);
}
}
//chuong trinh chinh
void main()
{
clrscr();
ptrPhongHoc p;
unsigned int n;
printf("Nhap vao so phong hoc n = ");
scanf("%d",&n);
p = Nhap(n);
printf("Danh sach phong hoc vua nhap:\n");
Xuat(p,n);
getch();
}