课设题目
ATM柜员机模拟系统
课设要求
- 新卡注册
- 修改密码
- 账户余额查询
- 取款、存款及转账操作
- 用户消费记录(卡号、消费时间、金额等)模拟数据的录入并保存到文件
- 按月、季度、年统计账户消费记录
- 报表导出
程序运行界面
核心代码
// 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("请选择日期");
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("消费金额%0.2f",total);
MessageBox(str);
}
//读取用户信息
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);
}
//读取用户信息
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("消费信息不能为空");
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("账户余额不足,请重新确认消费金额");
}
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("消费成功");
}
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
}
项目源码
需要源码的小伙伴请前往
微信公众号:海轰Pro
回复: 海轰
O(∩_∩)O哈哈~