Bài tập lập trình ngôn ngữ C++

5 1.4K 23
Bài tập lập trình ngôn ngữ C++

Đang tải... (xem toàn văn)

Thông tin tài liệu

Đề bài: Anh chị hãy lập trình giải bài toán về quản lý học sinh- Sinh viên bằng ngôn ngữ C++ #include<conio.h> #include<iostream.h> #include<iomanip.h> #include<string.h> class nguoi { private: char ho[10],ten[10]; int lop,gioitinh,ns; public: void nhap() { cout<<"\n nhap ho cua sinh vien :"; cin.ignore(1); cin.get(ho,10); cout<<"\n nhap ten cua sinh vien :"; cin.ignore(1); cin.get(ten,10); cout<<"\n nhap lop sinh vien dang hoc"; cin>>lop; cout<<"\n nhap nam sinh :"; cin>>ns; cout<<"\n nhap gioi tinh"; while(1)//---->warning : funtion containing while are not expanded inline { cin>>gioitinh; if((gioitinh==0)||(gioitinh==1)) break; else cout<<"\n nhap lai gioi tinh"; } } void hien() { cout<<setw(10)<<ho<<setw(10)<<ten<<setw(5)<<gioitinh<<setw(5)<<ns<<setw(5)<<lop; { int traveten() { return ten(); } }; class diem { private: float csdl,mmt,ctdl,java,trituent,lthdt,moncs,moncn; public: void nhap() { cout<<"nhap diem mon co so du lieu"; cin>>csdl; cout<<"nhap diem mon mang may tinh"; cin>>mmt; cout<<"nhap diem mon cau truc du lieu"; cin>>ctdl; cout<<"nhap diem mon java"; cin>>java; cout<<"nhap diem mon lap trinh huong doi tuong: "; cin>>lthdt; cout<<"nhap diem mon tri tue nhan tao"; cin>>trituent; *moncs=mmt+lthdt+ctdl; *moncn=java+trituent+csdl; } void hiends() { cout<<setw(5)<<mmt<<setw(5)<<lthdt<<setw(5)<<ctdl<<moncs<<setw(5)<<java<<setw(5)<<tritue nt<<setw(5)<<csdl<<setw(5)<<moncn; } float travediemmoncs() { return moncs; } float travediemmoncn() { return moncn; } int kq() { if(moncs>=5)&&(moncn>=5)//--->expreesion syntax; { return 1; return 0; } }//statament mising; }; class sinhvien: public nguoi,diem { private: char masv[5],dieukientotnghiep[20]; public: void nhap() { cout<<"\n nhap ma sinh vien"; cin.ignore(1); cin.get(masv,5); nguoi::nhap(); diem::nhap(); if(kq==1) strcpy(dieukientotngiep,"tot nghiep"); else strcpy(dieukientotngiep,"khong tot nghiep"); } void hien() { cout<<setw(5)<<masv; nguoi::hien; diem::hien; cout<<setw(20)<<dieukientotnghiep; } int timkiemten(char t[]) { if(strcpy(traveten(),t)==0) return 1; return 0; } void sxtheoten(sinhvien *sv1,sinhvien *sv2) { sinhvien tam; if(strcpy(sv1->traveten(),sv2->traveten())>0) { tam=*sv1; *sv1=*sv2; *sv2=tam; } } void sapxeptheodiemmoncs(sinhvien *sv1,sinhvien *sv2) { sinhvien tam; if(sv1->diem.moncs<sv2->diem.moncs) { tam=*sv1; *sv1=*sv2; *sv2=tam; } } void them(sinhvien *sv,int *n,sinhvien tam) { sv[*n]=tam; *n=*n+1; } void xoa(sinhvien *sv,int *n,int vt) { int i; for(i=vt-1;i<*n;i++)//---->warning : funtion containing while are not expanded inline sv=sv[i+1]; *n=*n-1; } void sua(sinhvien *sv) { sinhvien tam; cout<<"\n nhap thong tin can sua"; tam.nhap(); *sv=tam; } void hiends(sinhvien *sv,int n) { int i; for(i=0;i<n;i++) { cout<<"\n"<<setw(4)<<i+1; sv.hiends();//--->funtion 'hien'should have protype } getch(); } void main() { sinhvien *sv,tam; int i,j,m,vt; char t[10]; clrscr(); cout<<"\n nhap so luong sinh vien:"; cin>>m; sv=new sinhvien[m]; cout<<"\n nhap danh sach sinh vien"; for(i=0;i<n;i++)//--->undefined symbol 'n'l { cout<<"\n nhap sinh vien thu :"<<i+1; sv.nhap(); } cout<<"\n danh sach thi sinh vua nhap : "; for(i=0;i<n;i++) { cout<<"\n"<<i+1; sv.hiends(); } cout<<"\n nhap ten can tim : "; cin.ignore(1;) cin.get(i,10); cout<<"\n danh sach thi sinh co ten "<<t<<"la : \n"; for(i=0;i<n;i++) if(sv,timkiemten(t)==1)//-->funtion 'timkiemten' should have protype { cout<<"\n"; sv.hiends(); } for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) { sapxeptheodiemmoncs(&sv,&sv[j]); cout<<"”\n danh sach sinh vien vua duoc sap xep theo diem mon co so: ”"; hiends(sv,m); for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) sapxeptheodiemmoncn(&sv,&sv[j]); cout<<"”\n danh sach sinh vien vua duoc sap xep theo diem mon chuyen nganh: ”"; hiends(sv,m); for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) sapxeptheoten(&sv,&sv[j]); cout<<"”\n danh sach sinh vien vua duoc sap xep theo ten: ”"; hiends(sv,m); cout<<"”\n nhap cac thong tin ve sinh vien can nhap them : ”"; tam.nhap(); them(sv,&m,tam); cout<<"\n danh sach sinh vien vua duoc them vao : "; hiends(sv,m); cout<<"\n nhap vi tri can sua:"; cin>>vt; sua(&sv[vt-1]); cout<<"\n danh sach sinh vien vua duoc dua doi : "; hiends(sv,m); cout<<"\n nhap vi tri can xoa"; cin>>vt; xoa(&sv,&m,vt); cout<<"\n danh sach sinh vien vua xoa : "; hiends(sv,m); getch(); delete sv; } } . Đề bài: Anh chị hãy lập trình giải bài toán về quản lý học sinh- Sinh viên bằng ngôn ngữ C++ #include<conio.h> #include<iostream.h>

Ngày đăng: 19/10/2013, 06:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan