Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct sinhvien
- {
- string ten;
- int mssv;
- float dtb;
- };
- typedef sinhvien SV;
- void LuuDS(SV a[],int n)// luu file
- {
- ofstream FileOut;
- FileOut.open("DoAn.txt");
- if (FileOut.is_open())
- {
- for (int i = 0; i < n; i++)
- {
- FileOut << a[i].ten << ",";
- FileOut << a[i].mssv << ",";
- FileOut << a[i].dtb << endl;
- }
- }
- FileOut.close();
- }
- void DocDs(SV a[], int n)// doc file
- {
- ifstream Filein;
- Filein.open("DoAn.txt");
- string ch;
- cout << "doc danh sach" << endl;
- if (Filein.is_open())
- {
- for (int i = 0; i < n; i++)
- {
- getline(Filein, a[i].ten, ',');
- cout << a[i].ten << endl;
- Filein >> a[i].mssv;
- cout << a[i].mssv << endl;
- Filein >> a[i].dtb;
- cout << a[i].dtb << endl;
- getline(Filein, ch, '\n');
- }
- }
- Filein.close();
- }
- void nhapSV(SV a[], int n)
- {
- cin.ignore('\n', 10);
- for (int i = 0; i < n; i++)
- {
- cout << "nhap ten sinh vien: ";
- getline(cin, a[i].ten);
- cout << "nhap MSSV: ";
- cin >> a[i].mssv;
- cout << "nhap DTB: ";
- cin >> a[i].dtb;
- cin.ignore('\n', 10);// tranh truong hop nhận enter là tên ( không tin xoá thử để biết :))) )
- }
- }
- void main()
- {
- SV a[100];
- int n;
- cout << "nhap so luong danh sach sinh vien: ";
- cin >> n;
- nhapSV(a,n);
- LuuDS(a, n);
- DocDs(a, n);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement