#pragma once
#include<iostream>
#include <string>
using namespace std;
class Bngay
{
private:
int ngay, thang,nam;
public:
friend istream&operator>>(istream&is,Bngay &a);
friend ostream&operator<<(ostream&os,Bngay a);
};
class thisinh
{
protected:
string SBD;
string hoten;
Bngay ngaysinh;
float tongdiem;
public:
friend istream&operator>>(istream&is,thisinh &d);
friend ostream&operator<<(ostream&os,thisinh d);
};
class thsinhB: public thisinh
{
private:
float van,su ,dia;
public:
friend istream&operator>>(istream&is,thsinhB &s);
friend ostream&operator<<(ostream&os,thsinhB s);
};
class thsinhA: public thisinh
{
private:
float toan,ly ,hoa;
public:
friend istream&operator>>(istream&is,thsinhA &p);
friend ostream&operator<<(ostream&os,thsinhA p);
};
#include "Bngay.h"
istream&operator>>(istream&is,Bngay &a)
{
cout<<"\nnhap ngay ";
is>>a.ngay;
cout<<"\nnhap nam ";
is>>a.thang;
cout<<"\nnhap nam ";
is>>a.nam;
return is;
}
ostream&operator<<(ostream&os,Bngay a)
{
os<<"\n"<<a.ngay<<"/"<<a.thang<<"/"<<a.nam;
return os;
}
#include "Bngay.h"
istream&operator>>(istream&is,Bngay &a)
{
cout<<"\nnhap ngay ";
is>>a.ngay;
cout<<"\nnhap nam ";
is>>a.thang;
cout<<"\nnhap nam ";
is>>a.nam;
return is;
}
ostream&operator<<(ostream&os,Bngay a)
{
os<<"\n"<<a.ngay<<"/"<<a.thang<<"/"<<a.nam;
return os;
}
#include "thsinhA.h"
istream&operator>>(istream&is,thsinhA &p)
{
thisinh*tam=static_cast<thisinh*>(&p);
is>>*tam;
cout<<"\n nhap diem toan: ";
is>>p.toan;
cout<<"\n nhap diem ly";
is>>p.ly;
cout<<"\nnhap diem hoa:";
is>>p.hoa;
p.tongdiem=p.toan+p.ly+p.hoa;
return is;
}
ostream&operator<<(ostream&os,thsinhA p)
{
thisinh tam=static_cast<thisinh>(p);
os<<tam;
os<<"\ndiemtoan: "<<p.toan<<"\ndiem ly: "<<p.ly<<"\ndiem hoa: "<<p.hoa;
return os;
}
#include "thsinhB.h"
istream&operator>>(istream&is,thsinhB &p)
{
thisinh*tam=static_cast<thisinh*>(&p);
is>>*tam;
cout<<"\n nhap diem toan: ";
is>>p.van;
cout<<"\n nhap diem ly";
is>>p.su;
cout<<"\nnhap diem hoa:";
is>>p.dia;
p.tongdiem=p.van+p.su+p.dia;
return is;
}
ostream&operator<<(ostream&os,thsinhB p)
{
thisinh tam=static_cast<thisinh>(p);
os<<tam;
os<<"\ndiemvan: "<<p.van<<"\ndiem su: "<<p.su<<"\ndiem dia: "<<p.dia;
return os;
}
và main
#include "Bngay.h"
#include "thisinh.h"
#include "thsinhA.h"
#include "thsinB.h"
#include "vector"
using namespace std;
void main()
{
int n1,n2,tuychon,i,j;
thsinhA tsa;
thsinhB tsc;
vector <thsinhA> v1;
vector <thsinhB> v2;
do
{
cout<<"\n--------MENU--------";
cout<<"\n 1.NHAP THI SINH KHOI A";
cout<<"\n 2.NHAP THI SINH KHOI B";
cout<<"\n 0. THOAT CHUONG TRINH";
do
{
cout<<"\n NHAP TUY CHON 0,1,2";
cin>>tuychon;
if (tuychon<0 || tuychon>2)
cout<<"\n Nhap Tuy chon sai nhap lai nha......";
}
while( tuychon<0 || tuychon>2);
if (tuychon == 1 )
{
cout <<" Nhap so thi sinh khoi A:";
cout<<n1;
for (i=0;i<n1;i++)
{
cin>>tsa;
v1.push_back(tsa);
}
}
if (tuychon == 2)
{
cout<<"Nhap so thi sinh khoi B \n:";
cin>>n2;
for(j=0;j<n2;j++)
{
cin>>tsc;
v2.push_back(tsc);
}
}
}
while(tuychon!=0);
if(n1>0)
{
cout<<"\n DANH SACH THI SINH THI KHOI A:";
for(i=0;i<v1.size();i++)
cout<<v1[i];
}
if(n2>0)
{
cout<<"\n DANH SACH THI SINH THI KHOI B:";
for(i=0;i<v2.size();i++)
cout<<v2[i];
}
system("PAUSE");
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?