Code thông tin Sinh viên trong C++
Code:
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <math.h>
struct hoten
{
char ho[10];
char tendem[10];
char ten[10];
};
struct quequan
{
char xa[20];
char huyen[20];
char tinh[20];
};
struct ngaysinh
{
int ngay;
int thang;
int nam;
};
struct sv
{
hoten ht;
ngaysinh ns;
quequan qq;
float diem;
};
sv Z[150];
typedef sv mangsv[150];
void nhap(sv &X)
{
cout<<" nhap thong tin sinh vien :\n";
cin.ignore();
cout<<" Ho: ";cin.getline(X.ht.ho,10);
cout<<" Ten dem: ";cin.getline(X.ht.tendem,10);
cout<<" Ten: ";cin.getline(X.ht.ten,10);
cout<<" ngay sinh: ";cin>>X.ns.ngay;
cout<<" thang sinh: ";cin>>X.ns.thang;
cout<<" nam sinh: ";cin>>X.ns.nam;
cout<<" Que quan:\n";
cin.ignore();
cout<<" xa: ";cin.getline(X.qq.xa,20);
cout<<" huyen: ";cin.getline(X.qq.huyen,20);
cout<<" tinh: ";cin.getline(X.qq.tinh,20);
cout<<" Diem : ";cin>>X.diem;
}
void xuat(sv &X)
{
cout<<X.ht.ho<<"\t"<<X.ht.tendem<<"\t"<<X.ht.ten<<"\t"<<X.ns.ngay<<"/"<<X.ns.thang<<"/"<<X.ns.nam<<"\t"<<X.qq.xa<<" - "<<X.qq.huyen<<" - "<<X.qq.tinh<<"\t"<<X.diem;
}
void main()
{
int i,n;
char c;
cout<<"Nhap so sinh vien :\n";cin>>n;
for (i=0;i<n;i++)
{
nhap(Z[i]);
}
sv tg;
for (i=0;i<n-1;i++)
for (int j=i+1;j<n;j++)
{
if (Z[i].ht.ten<Z[j].ht.ten)
{
tg=Z[i];Z[i]=Z[j];Z[j]=tg;
}
}
cout<<" danh sach sinh vien :\n";
for (i=0;i<n;i++)
{
cout<<i+1 ;
xuat(Z[i]);
}
cout<<"tim kiem sinh vien:\n";
cout<<" nhap chu cai dau tien ten sinh vien: ";cin>>c;
cout<<" nhung sinh vien can tim la: ";
for (i=0;i<n;i++)
{
if (Z[i].ht.ten[0]==c)
xuat(Z[i]);
}
}
0 Response to "Code thông tin Sinh viên trong C++"
Đăng nhận xét