Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by minhtienbukai501 ( 5 years ago )
#include <iostream>
#include <string>
#include <fstream>
#include <string.h>
using namespace std;
struct SinhVien {
string HoTen;
string MaSinhVien;
int NamSinh;
long long SoDienThoai;
};
struct List {
int n;
SinhVien a[100];
};
void Nhap1ThangSinhVien(SinhVien& sv, List l)
{
cout << "\nNhap ho ten: ";
rewind(stdin);
getline(cin, sv.HoTen);
bool check;
do
{
check = false;
cout << "\nNhap Ma Sinh Vien: ";
rewind(stdin);
getline(cin, sv.MaSinhVien);
for (int i = 0; i < l.n; i++)
{
if (l.a[i].MaSinhVien == sv.MaSinhVien)
{
check = true;
break;
}
}
if (check == true)
{
cout << "\nMa sinh vien bi trung!";
}
} while (check == true);
cout << "\nNhap nam sinh: ";
cin >> sv.NamSinh;
cout << "\nNhap So Dien Thoai: ";
cin >> sv.SoDienThoai;
}
void Xuat1ThangSinhVien(SinhVien sv)
{
cout << "\nHo Ten: " << sv.HoTen;
cout << "\nMa So Sinh Vien: " << sv.MaSinhVien;
cout << "\nNam Sinh: " << sv.NamSinh;
cout << "\nSo Dien Thoai: " << sv.SoDienThoai;
}
void NhapDanhSachSinhVien(List& l)
{
do
{
cout << "\nNhap so luong sinh vien: ";
cin >> l.n;
if (l.n < 0 || l.n > 100)
{
cout << "\nSo luong khong hop le!";
}
} while (l.n < 0 || l.n > 100);
for (int i = 0; i < l.n; i++)
{
cout << "\n\t===NHAP SINH VIEN THU " << i + 1 << "===\n";
Nhap1ThangSinhVien(l.a[i], l);
}
}
// cau a
void XuatDanhSachSinhVien(List l)
{
for (int i = 0; i < l.n; i++)
{
cout << "\n\t===XUAT SINH VIEN THU " << i + 1 << "===\n";
Xuat1ThangSinhVien(l.a[i]);
}
}
// ham cau b;
string ChuanHoaChuoi(string& s)
{
int n = s.length();
for (int i = 0; i < n; i++)
{
if (s[i] == ' ' && s[i + 1] == ' ')
{
s.erase(i, 1);
i--;
n--;
}
}
if (s[0] == ' ')
{
s.erase(0, 1);
n--;
}
if (s[n - 1] == ' ')
{
s.erase(n - 1, 1);
n--;
}
if (s[0] != ' ')
{
if (s[0] >= 'a' && s[0] <= 'z')
s[0] -= 32;
}
for (int i = 1; i < n; i++)
{
if (s[i] != ' ' && s[i - 1] == ' ')
{
if (s[i] >= 'a' && s[i] <= 'z')
{
s[i] -= 32;
}
}
else
{
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] += 32;
}
}
return s;
}
// cau c
void ChuanHoaDanhSach(List &l)
{
for (int i = 0; i < l.n; i++)
{
l.a[i].HoTen = ChuanHoaChuoi(l.a[i].HoTen);
}
}
// cau d
void SapXepTangTheoNamSinh(List& l)
{
for (int i = 0; i < l.n - 1; i++)
{
for (int j = i + 1; j < l.n; j++)
{
if (l.a[i].NamSinh > l.a[j].NamSinh)
{
swap(l.a[i], l.a[j]);
}
}
}
}
// cau e
void Xuat1SinhVienFile(SinhVien sv, ofstream& FileOut)
{
FileOut << "\nHo Ten: " << sv.HoTen;
FileOut << "\nMa So Sinh Vien: " << sv.MaSinhVien;
FileOut << "\nNam Sinh: " << sv.NamSinh;
FileOut << "\nSo Dien Thoai: " << sv.SoDienThoai;
}
void XuatSinhVienCoNamSinhTren2000(List& l, ofstream& FileOut)
{
FileOut << "\n\t===NHUNG SINH VIEN CO NAM SINH TREN 2000 ===\n";
for (int i = 0; i < l.n; i++)
{
if (l.a[i].NamSinh > 2000)
Xuat1SinhVienFile(l.a[i], FileOut);
}
}
int main()
{
List l;
NhapDanhSachSinhVien(l);
XuatDanhSachSinhVien(l);
cout << "\n\t===CHUOI SAU KHI CHUAN HOA===\n";
ChuanHoaDanhSach(l);
XuatDanhSachSinhVien(l);
cout << "\n\t===DANH SACH SAU KHI SAP XEP TANG DAN NAM SINH===\n";
SapXepTangTheoNamSinh(l);
XuatDanhSachSinhVien(l);
ofstream FileOut;
FileOut.open("DL.DAT", ios_base::out);
XuatSinhVienCoNamSinhTren2000(l, FileOut);
FileOut.close();
return 0;
}
Revise this Paste