Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.6 kB
1
Indexable
Never
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;
#define MAXN 100

struct SinhVien {
    char MASV[10];
    char HoTen[100];
    char NgaySinh[12];
    char GioiTinh;
    float DiemToan, DiemLy, DiemHoa, DTB;
};

void tinhdtb(SinhVien &sv) {
    sv.DTB = (sv.DiemToan + sv.DiemLy + sv.DiemHoa)/3;
}
void Nhap( SinhVien A[], int &n) {
  cout << "Nhap so luong: ";
    cin >> n;
  cout << "\n";
    for (int i = 0; i < n; i++) {   
        cout << "Nhap mssv: ";
    cin >> A[i].MASV;
        cout << "\n";
    cout << "Nhap ho ten: ";
    cin >> A[i].HoTen;
        cout << "\n";
    cout << "Nhap ngay sinh: ";
    cin >> A[i].NgaySinh;
        cout << "\n";
    cout << "Nhap gioi tinh: ";
    cin >> A[i].GioiTinh;
        cout << "\n";
    cout << "Nhap diem toan: ";
    cin >> A[i].DiemToan;
        cout << "\n";
    cout << "Nhap diem ly: ";
    cin >> A[i].DiemLy;
        cout << "\n";
    cout << "Nhap diem hoa: ";
    cin >> A[i].DiemHoa;
        cout << "\n";
    tinhdtb(A[i]);
}
}
void Xuat(SinhVien A[MAXN], int &n) {
    for (int i = 0; i < n; i++) {
    cout << A[i].MASV << "    ";
    cout << A[i].HoTen << "    ";
    cout << A[i].NgaySinh << "    ";
    cout << A[i].GioiTinh << "    ";
    cout << A[i].DiemToan << "    ";
    cout << A[i].DiemLy << "    ";
    cout << A[i].DiemHoa << "    ";
    cout << setprecision(3) << A[i].DTB;
    }
}
int main() {
    SinhVien A[MAXN];
    int n;
    Nhap(A, n);
    Xuat(A, n);
    return 0;
}