You are on page 1of 5

Bi tp thc hnh C++: Vit chng trnh thc hin: To 1 struct Student nh sau: Cc thuc tnh: StudentID StudentName

Gender MarkofMaths MarkofPhysics MarkofChemistry vi kiu d liu tu chn Chng trnh c menu nh sau: 1. Nhp 1 sinh vin mi 2. Hin th danh sch sinh vin 3. Sp xp danh sch sinh vin theo tng im tng dn 4. Kim tra danh sch sinh vin c sp xp tng dn theo tng im 5. Tm kim sinh vin theo tng im 6. Sa tn ca sinh vin theo M sinh vin (StudentID) nhp t bn phm 7. Xo 1 sinh vin c m = M sinh vin (StudentID) nhp t bn phm 8. Chn 1 sinh vin vo danh sch sinh vin c sp xp 9. Thot (Gi : khai bo 1 mng objStudent lu tr danh sch sinh vin)

// btc.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream.h" #include "conio.h" typedef struct Student_{ char studentID[10]; char studentName[30]; int Gender; float MathofMaths; float MarkofPhysics; float MarkofChemistry; }STUDENT; STUDENT objStudent[20]; int ncount=0; int menu() { int chon; cout<<"1. Nhap 1 sinh vien: "<<endl; cout<<"2. Hien thi danh sach sinh vien: "<<endl; cout<<"3. Sap xep dssv theo tong diem tang dan: "<<endl; cout<<"4. Kiem tra dssv da dc sap xep tang dan theo tong diem: "<<endl; cout<<"5. Tim kiem sv theo tong diem: "<<endl; cout<<"6. Sua ten cua sv theo MSV(StudentID) nhap tu ban phim: "<<endl; cout<<"7. Xoa 1 sv co ma=MSV(StudentID) nhap tu ban phim: "<<endl; cout<<"8. Chen 1 sv vao dssv da dc sap xep: "<<endl; cout<<"9. Thoat."<<endl; cin>>chon; return chon; } void Nhap(){ STUDENT sv; cout<<"Nhap msv: "; cin>>sv.studentID; cout<<"Nhap ten: ";

cin>>sv.studentName; cout<<"Gioi tinh: "; cin>>sv.Gender; cout<<"Diem toan: "; cin>>sv.MathofMaths; cout<<"Diem ly: "; cin>>sv.MarkofPhysics; cout<<"Diem hoa: "; cin>>sv.MarkofChemistry; if (ncount>=20){ cout<<"Danh sach day roi !"; return; } objStudent[ncount]=sv; ncount++; }; void Hienthi(){ cout<<"---------DANH SACH SINH VIEN--------- "<<endl; for (int i=0;i<ncount;i++) { cout<<"Sinh vien thu: "<<i+1<<" "<<endl; cout<<"MSV: "<<objStudent[i].studentID<<endl; cout<<"Ten sv: "<<objStudent[i].studentName<<endl; cout<<"Gioi tinh: "<<objStudent[i].Gender<<endl; cout<<"Diem toan: "<<objStudent[i].MathofMaths<<endl; cout<<"Diem ly: "<<objStudent[i].MarkofPhysics<<endl; cout<<"Diem hoa: "<<objStudent[i].MarkofChemistry<<endl; cout<<"-------------------------------------"<<endl; } }; void Sapxep(){ STUDENT tg; cout<<"SAP XEP DSSV THEO TONG DIEM TANG DAN"<<endl; float td1,td2; for (int i=0;i<ncount ;i++) td1=objStudent[i].MarkofChemistry+objStudent[i].MarkofPhysics+objStude nt[i].MathofMaths;

td2=objStudent[i+1].MarkofChemistry+objStudent[i+1].MarkofPhysics+obj Student[i+1].MathofMaths; if(td1>td2) { tg=objStudent[i]; objStudent[i]=objStudent[i+1]; objStudent[i+1]=tg; } }; void Kiemtra(){}; void Timkiem(float td){ for (int i=0;i<ncount;i++) if (td==objStudent[i].MathofMaths+objStudent[i].MarkofPhysics+objStudent[ i].MarkofPhysics) cout<<"Tim thay sinh vien"<<i; }; void Sua(){ cout<<"Nhap msv: "; char MSV[10] cin>>MSV; }; void Xoa(){}; void Chen(){}; int main(int arge,char* arger[]) { int ch=menu(); while(ch!=9) { switch(ch){ case 1: Nhap();break; case 2: Hienthi();break; case 3: Sapxep();break; case 4: Kiemtra();break; case 5: Timkiem();break; case 6: Sua();break;

case 7: Xoa();break; case 8: Chen();break; default: break; } ch=menu(); } return 0; }