Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- struct Sinhvien //tạo 1 truong thuoc tinh sinh vien
- {
- string masv;
- string tensv;
- string lop;
- double diem;
- };
- void Themsinhvien(); //khai bao ham
- Sinhvien arrSv[50]; // khai bao mang sinh vien voi toi da 50 sinh vien de luu tru .
- int ind = 0;//chi so mang de xem so luong sinh vien da them
- void Lietketatcasinhvien();
- void Timkiemsinhvien(string masv);
- void Xoasinhvien(string masv);
- void Lietkesinhvientheolop(string lop);
- void Chinhsuathongtin();
- bool kiemtra(string masv, int vitri); //kiem tra su tom tai sinh vien trong mang
- int main()
- {
- int luachon;
- while (true)
- {
- do
- {
- cout<< " Chuong trinh quan li sinh vien"<<endl;
- cout<< " 1. Them sinh vien"<<endl;
- cout<< " 2. Tim kiem sinh vien"<<endl;
- cout<< " 3. Chinh sua thong tin sinh vien "<<endl;
- cout<< " 4. Xoa sinh vien "<<endl;
- cout<< " 5.Liet ke danh sach sinh vien theo lop"<<endl;
- cout<< " 6.Liet ke danh sach tat ca sinh vien "<<endl;
- cout<< " 7. Thoat "<<endl;
- cout<< " Lua chon: ";
- cin>>luachon;
- system("clear");
- }
- while (luachon < 1 || luachon>7);
- switch(luachon)
- {
- case 1:
- {
- Themsinhvien();
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 2:
- { string msv;
- cout<<"Nhap ma: ";
- getline(cin,msv);
- cin.ignore();
- Timkiemsinhvien(msv);
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 3:
- { string msv;
- cout<<" Chinh sua thong tin sinh vien "<<endl;
- cin.ignore();
- cout<<"Nhap ma sinh vien";
- getline(cin, msv);
- Chinhsuathongtin();
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 4:
- { string masv;
- cout<<" Xoa sinh vien "<<endl;
- cin.ignore();
- cout<<"Nhap ma sinh vien";
- getline(cin,masv);
- Xoasinhvien(masv);
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 5:
- { string lop;
- cin.ignore();
- cout<<"Nhap lop: ";
- getline(cin,lop);
- Lietkesinhvientheolop( lop);
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 6:
- { Lietketatcasinhvien();
- cout<<"Back";
- system("PAUSE>NULL");
- break;
- }
- case 7:
- exit(1);
- }
- }
- return 0;
- }
- void Themsinhvien ()
- { // tạo đối tượng cho lớp sinh viên
- int n;
- cout<<"Nhap so sinh vien can them:"<<endl;
- cin>>n;
- for (int i=0;i<n;i++)
- {
- Sinhvien tmpsv;// sinh vien gan cho bien temp
- cin.ignore();
- cout<<"Nhap ma sinh vien: ";
- getline(cin, tmpsv.masv);
- cout<<"Nhap ten sinh vien: ";
- getline(cin, tmpsv.tensv);
- cout<<"Nhap lop: ";
- getline(cin, tmpsv.lop);
- cout<<"Nhap diem: ";
- cin>>tmpsv.diem;
- arrSv[ind] = tmpsv;
- ind++;
- }
- }
- void Lietketatcasinhvien()
- {
- cout<<"Danh sach tat ca cac sinh vien"<<endl;
- cout<<"Ma sinh vien"<<" "<<"Ten sinh vien"
- <<" "<<"Lop"<<" "<<"Diem"<<endl;
- for (int i =0; i <ind;i++)
- cout<<arrSv[i].masv<<" "<<arrSv[i].tensv<<" "
- <<arrSv[i].lop<<" "<<arrSv[i].diem<<endl;
- }
- void Timkiemsinhvien(string masv)
- {
- for (int i=0; i < ind; i++)
- {
- if (masv == arrSv[i].masv)
- {
- cout<<"Ten sinh vien: "<<arrSv[i].tensv<<endl;
- cout<<"Lop: "<<arrSv[i].lop<<endl;
- cout<<"Diem: "<<arrSv[i].diem<<endl;
- return ;
- }
- }
- cout<<"khong co ma sinh vien nay";
- }
- void Xoasinhvien(string masv)
- {
- for (int i =0; i<ind; i++)
- {
- if (masv == arrSv[i].masv)
- {
- for (int j=0; j< ind -1; j++)
- arrSv[j] = arrSv[j+1];
- ind --; // sau khi xoa phantu thì giam tong di 1 sinh vien
- cout<<"Da xoa"<<endl;
- return;
- }
- }
- cout<<"khong tim thay sinh vien"<<endl;
- }
- void Lietkesinhvientheolop(string lop)
- {
- int count = 0;
- for (int i =0; i<ind; i++)
- {
- if (lop == arrSv[i].lop)
- {
- cout<<arrSv[i].masv<<arrSv[i].tensv<<arrSv[i].lop<<arrSv[i].diem<<endl;
- }
- }
- if(count==0 )
- cout<<"Sinh vien khong thuoc lop nay"<<endl;
- }
- void Chinhsuathongtin(){};
- bool kiemtra(string masv, int vitri)
- {
- bool check = false;
- for (int i=0;i< ind;i++)
- {
- if(masv == arrSv[i].masv)
- {
- vitri=i;
- check = true;
- break;
- }
- break ;
- }
- }
Add Comment
Please, Sign In to add comment