// thisinh.cpp // Ban can bo sung code vao tep nay de giai quyet cac yeu cau // cua Cau 2 (Bai thuc hanh 7) #include #include using namespace std; struct Thisinh{ int maDuThi; string hoten; int diemToan; int diemLy; int diemHoa; }; void nhapThisinh(Thisinh& ts); // Ham in thong tin cua thi sinh duoi dang bang // Neu inDongDau == true thi in ra dong tieu de cac cot, // nguoc lai thi khong in void inThisinh(Thisinh ts, bool inDongDau=false); int main(){ Thisinh ts1 = {1234, "Nguyen Van Bac", 7, 8, 9}; Thisinh ts2; cout << "Nhap thong tin thi sinh 2: " << endl; nhapThisinh(ts2); inThisinh(ts1, true); inThisinh(ts2); cin.get(); return 0; } void nhapThisinh(Thisinh& ts){ cout << "Nhap ma du thi: "; cin >> ts.maDuThi; cout << "Nhap ho va ten: "; cin.ignore(); // bo di dau ENTER trong istream getline(cin, ts.hoten); cout << "Nhap diem toan: "; cin >> ts.diemToan; cout << "Nhap diem ly: "; cin >> ts.diemLy; cout << "Nhap diem hoa: "; cin >> ts.diemHoa; cin.ignore(80, '\n'); } void inThisinh(Thisinh ts, bool inDongDau){ cout.setf(ios::left); if(inDongDau) cout << setw(10) << "Ma" << setw(30) << "Ho ten" << "D.toan\tD.ly\tD.hoa" << endl; cout << setw(10) << ts.maDuThi << setw(30) << ts.hoten << ts.diemToan << "\t" << ts.diemLy << "\t" << ts.diemHoa << endl; }