Lesson title
ATM teller machine simulation system
Class setting requirements
- New card registration
- Change Password
- Account balance query
- Withdrawal, deposit and transfer operations
- Input and save simulation data of user consumption record (card number, consumption time, amount, etc.) to file
- Statistics of account consumption records by month, quarter and year
- Report export
Program operation interface
Core code
// SaleDlg.cpp : implementation file // #include "stdafx.h" #include "atm.h" #include "SaleDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSaleDlg dialog CSaleDlg::CSaleDlg(CWnd* pParent /*=NULL*/) : CDialog(CSaleDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSaleDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CSaleDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSaleDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSaleDlg, CDialog) //{{AFX_MSG_MAP(CSaleDlg) ON_BN_CLICKED(IDC_BUTTON8, OnButton8) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_TOTAL, OnTotal) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSaleDlg message handlers void CSaleDlg::OnButton8() { // TODO: Add your control notification handler code here CString year,quarter,month; GetDlgItem(IDC_COMBO1)->GetWindowText(year); GetDlgItem(IDC_COMBO2)->GetWindowText(quarter); GetDlgItem(IDC_COMBO3)->GetWindowText(month); if(year==""||quarter==""||month == "") { MessageBox("Please select a date"); return; } float total=0; int num = readsale(); for(int i =0;i<num;i++) { CString date ; CString dd = sale[i].date; if(quarter=="") { date = year+"/"+month; if(dd.Find(date)!=-1) { total = total+sale[i].money; } } else if(quarter =="1") { date = year+"/1"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/2"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/3"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } } else if(quarter =="2") { date = year+"/4"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/5"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/6"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } } else if(quarter =="3") { date = year+"/7"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/8"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/9"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } } else if(quarter =="4") { date = year+"/10"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/11"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } date = year+"/12"; if(dd.Find(date)!=-1) { total = total+sale[i].money; } } } CString str; str.Format("Consumption amount%0.2f",total); MessageBox(str); } //Read user information int CSaleDlg::readsale() { int i=0; ifstream file; file.open("sale.txt",ios::in); while(!file.eof()) { file>>sale[i].id>>sale[i].date>>sale[i].money; i++; } i--; return i; } void CSaleDlg::OnButton1() { // TODO: Add your control notification handler code here EndDialog(TRUE); } //Read user information int CSaleDlg::read() { int i=0; ifstream file; file.open("data.txt",ios::in); while(!file.eof()) { file>>user[i].id>>user[i].name>>user[i].pid>>user[i].pwd>>user[i].money; i++; } i--; file.close(); return i; } void CSaleDlg::OnTotal() { // TODO: Add your control notification handler code here CString date,money; GetDlgItem(IDC_DATETIMEPICKER1)->GetWindowText(date); GetDlgItem(IDC_EDIT9)->GetWindowText(money); if(date==""||money=="") { MessageBox("Consumption information cannot be empty"); return; } int number = read(); ofstream outfile; outfile.open("data.txt",ios::ate); for(int i=0;i<number;i++) { if(strcmp(myid,user[i].id)==0) { if(user[i].money<atof(money)) { MessageBox("The account balance is insufficient, please reconfirm the consumption amount"); } else { user[i].money=user[i].money-atof(money); } } outfile<<user[i].id<<" "<<user[i].name<<" "<<user[i].pid<<" "<<user[i].pwd<<" "<<user[i].money<<endl; } outfile.close(); ofstream file; file.open("sale.txt",ios::app); file<<myid.GetBuffer(0)<<" "<<date.GetBuffer(0)<<" "<<atof(money)<<endl; file.close(); MessageBox("Consumption success"); } BOOL CSaleDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here GetDlgItem(IDC_EDIT1)->SetWindowText(myid); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }Sea bombardment 155 original articles published, praised 103, visited 50000+ Private letter follow