You are on page 1of 3

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class SinhVien
{
private:
int MaSo;
string HoTen;
float TKLG, LTHDT, KTMT;
float DTB;

public:

SinhVien(int MaSo, string HoTen, float TKLG, float LTHDT, float KTMT)
{
this->MaSo = MaSo;
this->HoTen = HoTen;
this->TKLG = TKLG;
this->LTHDT = LTHDT;
this->KTMT = KTMT;
this->DTB = TinhTrungBinh();
}

SinhVien()
{
this->MaSo = 0;
this->HoTen = "";
this->TKLG = -1;
this->LTHDT = -1;
this->KTMT = -1;
this->DTB = TinhTrungBinh();
}

void nhap()
{
cout << "Ma so sinh vien:";
cin >> MaSo;
cout << "Ho va Ten:";
cin.ignore();
getline(cin, HoTen);
cout << "Vi dieu khien:";
cin >> TKLG;
cout << "Lap trinh huong doi tuong:";
cin >> LTHDT;
cout << "Kien truc may tinh:";
cin >> KTMT;
DTB = TinhTrungBinh();
}

float TinhTrungBinh()
{
return (LTHDT + TKLG + KTMT) / 3;
}

void xuat()
{
cout << MaSo << "\t" << HoTen << "\t" << TKLG << "\t" << LTHDT << "\t"
<< KTMT << "\t" << DTB;
}
friend istream& operator>>(istream& is, SinhVien& sv)
{
sv.nhap();
return is;
}
friend ostream& operator<<(ostream& os, SinhVien& sv)
{
sv.xuat();
return os;
}
};
class MENU
{
private:
vector <SinhVien> sv;
int SiSo;

public:
void nhapDS()
{
cout << "Nhap so sv:";
cin >> SiSo;
sv.resize(SiSo);
for (int i = 0; i < SiSo; i++)
cin >> sv[i];
}

void xuatDS()
{
cout << "\nMSSV\tTen\tVDK\tHDT\tKTMT\tDTB\n";
for (int i = 0; i < sv.size(); i++)
{
cout << sv[i];
cout << "\n";
}
cout << "\n\n\n";
system("pause");
}
void inMenu()
{
char option;
do
{
system("cls");
cout << "\n===== MENU =====";
cout << "\n1. Nhap danh sach";
cout << "\n2. Xuat danh sach";
cout << "\nNhap lua chon:";
cin >> option;
switch (option)
{
case '1': nhapDS(); break;
case '2': xuatDS(); break;
}
} while (option != '0');
}
};
int main()
{
MENU menu1;
menu1.inMenu();
}

You might also like