Untitled

 avatar
unknown
plain_text
4 years ago
3.6 kB
4
Indexable
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

typedef struct {
	string ho;
	string ten_dem;
	string ten;

}ho_ten;
typedef struct {
	string xa;
	string huyen;
	string tinh;
}que_quan;
typedef struct {
	float toan;
	float ly;
	float hoa;

}diem_thi;


class sinh_vien {
protected:
	ho_ten ho_ten;
	que_quan que_quan;
	diem_thi diem_thi;
	string truong;
	int tuoi;
	string sbd;
	float tong;
public:
	sinh_vien() {
		tong = 0;
		tuoi = 0;
		diem_thi.toan = 0;
		diem_thi.ly = 0;
		diem_thi.hoa = 0;
	}
	~sinh_vien() {
		tong = 0;
		tuoi = 0;
		diem_thi.toan = 0;
		diem_thi.ly = 0;
		diem_thi.hoa = 0;
	}

	void nhap() {
		cout << "Nhap ho ten sinh vien:" << endl;
		cin.ignore(1);
		cout << "Ho:             "; getline(cin, ho_ten.ho); 
		cout << "Ten dem:        "; getline(cin, ho_ten.ten_dem); 
		cout << "ten:            "; getline(cin, ho_ten.ten); 
		cout << "\n\n Nhap que quan:" << endl; 
		cout << "Xa:             "; getline(cin, que_quan.xa); ;
		cout << "Huyen:          "; getline(cin, que_quan.huyen); 
		cout << "Tinh:           "; getline(cin, que_quan.tinh); 
		cout << "\n Nhap truong:   "; getline(cin, truong); 
		cout << "Nhap tuoi:      "; cin >> tuoi; cin.ignore(1);
		cout << "\n Nhap SBD:      "; getline(cin, sbd); 
		cout << "\n\n Nhap diem thi:" << endl; 
		cout << "Nhap diem toan: "; cin >> diem_thi.toan; 
		cout << "Nhap diem ly:   "; cin >> diem_thi.ly; 
		cout << "Nhap diem hoa:  "; cin >> diem_thi.hoa; 


	}
	float sum() {
		tong = diem_thi.toan + diem_thi.ly + diem_thi.hoa;
		return tong;
	}
	void show() {
		cout << setw(8) << left << ho_ten.ho << setw(8) << left << ho_ten.ten_dem << setw(8) << left << ho_ten.ten << setw(12) << left << que_quan.xa << setw(12) << left << que_quan.huyen << setw(12) << left << que_quan.tinh << setw(10) << left << truong << setw(10) << left << sbd << setw(12) << left << diem_thi.toan << setw(12) << left << diem_thi.ly << setw(12) << left << diem_thi.hoa << endl;
	}
};

int main() {
	int n;
	cout << "Nhap so luong sinh vien: "; cin >> n;
	sinh_vien* SV = new sinh_vien[n];
	cout << "----------------------------------Nhap thong tin sinh vien ---------------------------------------" << endl;
	for (int i = 0; i < n; i++) {
		cout << "Nhap thong tin sinh vien thu " << i + 1 << ": " << endl;
		SV[i].nhap();
		SV[i].sum();

	}

	cout << "\n\n----------------------------------Danh sach sinh vien ---------------------------------------\n\n";
	cout << setw(8) << left << "Ho" << setw(8) << left << "Ten Dem" << setw(8) << left << "Ten" << setw(12) << left << "Xa" << setw(12) << left << "Huyen" << setw(12) << left << "Tinh" << setw(10) << left << "Truong" << setw(10) << left << "SBD" << setw(12) << left << "Diem toan" << setw(12) << left << "Diem ly" << setw(12) << left << "Diem hoa"<<endl;
	for (int i = 0; i < n; i++) {
		SV[i].show();
	}

	cout << "\n\n-------------------------------------Danh sach sinh vien co tong diem lon hon 15-------------------------------------" << endl;
	
	cout << setw(8) << left << "Ho" << setw(8) << left << "Ten Dem" << setw(8) << left << "Ten" << setw(12) << left << "Xa" << setw(12) << left << "Huyen" << setw(12) << left << "Tinh" << setw(10) << left << "Truong" << setw(10) << left << "SBD" << setw(12) << left << "Diem toan" << setw(12) << left << "Diem ly" << setw(12) << left << "Diem hoa" << endl;
	for (int i = 0; i < n; i++) {
		
		if (SV[i].sum() > 15) {
			
			SV[i].show();
		}
		else {
			continue;
		}
	}
	return 0;
}
Editor is loading...