File lớp học.h
PHP Code:
#ifndef lophoc_h
#define lophoc_h
#include "sinhvien.h"
class LopHoc
{
private:
SinhVien sv[50];
int sosv;
public:
LopHoc()
{ sosv = 0; }
~LopHoc()
{ delete []sv; sosv = 0; }
void themmon(MonHoc mh);
void capnhatmon(char masv[],char mamh[],float diem);
void themsinhvien(SinhVien a);
void xoasv(char ma[]);
void ghitenmon();
friend ostream& operator<<(ostream& cout,LopHoc& lh);
friend istream& operator>>(istream& cin ,LopHoc& lh);
};
istream& operator>>(istream& cin,LopHoc& lh)
{
cout<<" Nhap so luong hoc sinh trong lop ";
cin>>lh.sosv;
for(int i = 0;i < lh.sosv;i++)
{
cout<<"sinh vien thu "<<(i+1)<<endl;
cin>>lh.sv[i];
}
return cin;
}
ostream& operator<<(ostream& cout,LopHoc& lh)
{
cout<<"Danh sach cua lop hien gio gom co "<<lh.sosv<<" sinhvien "<<endl;
for(int i = 0;i < lh.sosv;i++)
{
cout<<lh.sv[i];
}
return cout;
}
void LopHoc::xoasv(char ma[])
{
for(int i = 0;i < sosv;i++)
{
if(strcmp(sv[i].getma(),ma)==0)
{
for(int j = i;j < sosv;j++)
sv[j] = sv[j+1];
sosv--;
}
}
}
void LopHoc::themsinhvien(SinhVien a)
{
bool co=true;
for(int i = 0;i < sosv;i++)
{
if(strcmp(sv[i].getma(),a.getma())==0)
co=false;
}
if(co)
sv[sosv++] = a;
}
void LopHoc::capnhatmon(char masv[],char mamh[],float diem)
{
for(int i=0;i<sosv;i++)
{
if(strcmp(sv[i].getma(),masv)==0)
sv[i].capnhatdiem(mamh,diem);
}
}
void LopHoc::themmon(MonHoc mh)
{
for(int i = 0;i < sosv;i++)
{
sv[i].getbang().chenmon(mh);
}
}
void LopHoc::ghitenmon()
{
ofstream ghi("Monhoc.Dat",ios::binary|ios::app);
if(ghi.fail())
{
cout<<"\nkhong ket noi dc voi file "<<endl;
}
else
{
MonHoc a;
char name[20],ma[20];
int n;
cout<<"Moi ban Nhap so luong cac mon cua lop ";
cin>>n;
for(int i = 0;i < n;i++)
{
cout<<"nhap mon thu "<<(1+i)<<endl<<endl;
cout<<"\t ten mon ";
gets(name);
cout<<"\t ma mon ";
gets(ma);
a.setmonhoc(ma,name,0);
ghi.write((char*) &a, sizeof a);
}
ghi.close();
}
}
#endif