ATM.cpp - #include <iostream> using namespace std#include <string.h>#include <conio.h>#define MAX 100 typedef struct ATM int STK char HoTen[100 float

ATM.cpp - #include <iostream> using namespace std#include...

This preview shows page 1 - 3 out of 3 pages.

#include <iostream> using namespace std; #include <string.h> #include <conio.h> #define MAX 100 typedef struct ATM { int STK; char HoTen[100]; float Tien; char NganHang[15]; //ACB, BIDV }; void nhap1ATM(ATM &a) { cout<<"------------ NHAP 1 ATM -----------"<<endl; cout<<"So TK: "; cin>>a.STK; cin.ignore(1); cout<<"Ho ten KH: "; gets(a.HoTen); cout<<"Tien: "; cin>>a.Tien; cin.ignore(1); cout<<"Ngan hang: "; gets(a.NganHang); } void nhapMang(ATM a[], int &n) { char tt; do { nhap1ATM(a[n++]); cout<<"Nhap KH moi? ('y' hoac 'Y' de tiep tuc:)"<<endl; tt=getch(); }while(tt == 'y' || tt == 'Y'); } void xuatMang(ATM a[], int n) { for(int i=0; i<n; i++) { cout<<a[i].STK<<"\t"; cout<<a[i].HoTen<<"\t"; cout<<a[i].Tien<<"\t"; cout<<a[i].NganHang<<"\n"; } } void ghiFile(ATM a[], int n) { FILE *f=fopen("atm.txt", "wb"); //write binary if(f==NULL) { cout<<"Khong mo duoc file"<<endl; return; } fwrite(a, sizeof(ATM), n, f); fclose(f); } void docFile(ATM a[], int &n) {
Image of page 1

Subscribe to view the full document.

FILE *f=fopen("atm.txt", "rb"); //read binary
Image of page 2
Image of page 3

Unformatted text preview: if(f==NULL) { cout&lt;&lt;&quot;Khong mo duoc file&quot;&lt;&lt;endl; return; } n=0; while(!feof(f))//khi chua het file { if(fread(&amp;a[n], sizeof(ATM), 1, f)) //doc duoc n++; } fclose(f); } void TuyenTinh_Ten(ATM a, int n) { char tenCanTim[100]; cout&lt;&lt;&quot;Vui long nhap vao Ho ten can tim: &quot;; gets(tenCanTim); for(int i=0; i&lt;n; i++) { if(strcmp(a[i].HoTen, tenCanTim) == 0) { cout&lt;&lt;&quot;Tim thay ban &quot;&lt;&lt;tenCanTim&lt;&lt;&quot; tai vi tri &quot; &lt;&lt; i+1&lt;&lt;endl; return; } } cout&lt;&lt;&quot;KHONG tim thay ban &quot;&lt;&lt;tenCanTim&lt;&lt;endl; } void InsertionSort_Ten(ATM a, int n) { int pos; for(int i=1; i&lt;n; i++) { ATM x = a[i]; pos = i-1; while(pos &gt;= 0 &amp;&amp; strcmp(a[pos].HoTen, x.HoTen)&gt; 0) { a[pos+1] = a[pos]; pos --; } a[pos+1] = x; } } int main() { ATM a[100]; int n=0; //nhapMang(a, n); //ghiFile(a, n); docFile(a, n); xuatMang(a, n); cout&lt;&lt;&quot;Sau khi SX: &quot;&lt;&lt;endl; InsertionSort_Ten(a, n); xuatMang(a, n); }...
View Full Document

  • Spring '15
  • Thuy Do

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes