fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define ll long long
  7. #define fast() ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  8.  
  9. struct NhanVien{
  10. string ma,ten;
  11. float hsluong,luongcb,phucap;
  12.  
  13. };
  14.  
  15. void nhap(vector<NhanVien> ds,const string& file){
  16. ofstream fileOut(file);
  17. if(fileOut.is_open()){
  18. for(auto it : ds){
  19. fileOut << it.ma << "\n";
  20. fileOut << it.ten << "\n";
  21. fileOut << it.hsluong << "\n";
  22. fileOut << it.luongcb << "\n";
  23. fileOut << it.phucap << "\n";
  24. }
  25. fileOut.close();
  26. }
  27. }
  28.  
  29. void doc(vector<NhanVien> &ds,const string &file){
  30. ifstream fileIn(file);
  31. if(fileIn.is_open()){
  32. NhanVien nv;
  33. while(fileIn >> nv.ma){
  34. fileIn.ignore();
  35. getline(fileIn,nv.ten);
  36. fileIn >> nv.hsluong >> nv.luongcb >> nv.phucap;
  37. ds.pb(nv);
  38. }
  39. fileIn.close();
  40. }
  41. }
  42.  
  43. void solve(vector<NhanVien> &ds, const string& file){
  44. for(auto nv : ds){
  45. float tongluong = nv.luongcb * nv.hsluong + nv.phucap;
  46. cout << nv.ma << " " << nv.ten << " " << tongluong << "\n";
  47. }
  48. }
  49.  
  50. int main(){
  51. fast();
  52. vector<NhanVien> ds;
  53. string file = "nhanvien.txt";
  54. for(int i = 0 ; i < 10 ; i++){
  55. NhanVien nv;
  56. cin >> nv.ma;
  57. cin.ignore();
  58. getline(cin,nv.ten);
  59. cin >> nv.hsluong >> nv.luongcb >> nv.phucap;
  60. ds.pb(nv);
  61. }
  62. nhap(ds,file);
  63. ds.clear();
  64. doc(ds,file);
  65. solve(ds,file);
  66. }
  67.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty