C++ ATM机大作业 文件写入报错
build函数报错,代码未编完,我只是想试试刚刚编的一部分(build和log_in)能不能用,我贴图,问的比较仓促,不清楚的我可以详细解释我的问题。程序代码:
#include <iostream> #include<string> #include<string.h> #include<stdlib.h> #include<fstream> #include<stdio.h> using namespace std; class ATM { public: void build(); //建立账户 int log_in(); //登录账户 void deposit(); //存款 void withdrawal(); //取款 void balance_enquiry(); //余额查询 void interest(); //利率计算 ATM(string acc,string pas,string nam,char g,string addr,string pho,string id,double s): account(acc),password(pas),name(nam),gender(g),address(addr),phone(pho),ID_num(id),sum(s) {} protected: string account; string password; string name; char gender; string address; string phone; string ID_num; double sum; }; void ATM::build() //新建账户 { cout<<"!!!"; int flag=1; ofstream outfile_account("d0.dat"),outfile_password("d1.dat"); ofstream outfile_name("d2.dat"),outfile_gender("d3.dat"); ofstream outfile_address("d4.dat"),outfile_phone("d5.dat"); ofstream outfile_idnum("d6.dat"),outfile_sum("d7.dat"); cout<<"@@@"; if(!outfile_account) {cerr<<"open d0.dat error"<<endl; exit(1);} if(!outfile_password) {cerr<<"open d1.dat error"<<endl; exit(1);} if(!outfile_name) {cerr<<"open d2.dat error"<<endl; exit(1);} if(!outfile_gender) {cerr<<"open d3.dat error"<<endl; exit(1);} if(!outfile_address) {cerr<<"open d4.dat error"<<endl; exit(1);} if(!outfile_phone) {cerr<<"open d5.dat error"<<endl; exit(1);} if(!outfile_idnum) {cerr<<"open d6.dat error"<<endl; exit(1);} if(!outfile_sum) {cerr<<"open d7.dat error"<<endl; exit(1);} cout<<"&&&"; typedef struct user { string account; string password; string name; char gender; string address; string phone; string ID_num; double sum; }USER; USER users[30]={0}; for(int i=0;flag==1;i++) {cout<<"请输入要创建的银行卡账号:"; cin>>users[i].account; outfile_account<<users[i].account<<" "; cout<<"请输入要创建的银行卡密码:"; cin>>users[i].password; outfile_password<<users[i].password<<" "; cout<<"请输入您的姓名:"; cin>>users[i].name; outfile_name<<users[i].name<<" "; cout<<"请输入您的性别:"; cin>>users[i].gender; outfile_gender<<users[i].gender<<" "; cout<<"请输入您的现住址:"; cin>>users[i].address; outfile_address<<users[i].address<<" "; cout<<"请输入您的电话或手机号码:"; cin>>users[i].phone; outfile_phone<<users[i].phone<<" "; cout<<"请输入您的身份证号:"; cin>>users[i].ID_num; outfile_idnum<<users[i].ID_num<<" "; users[i].sum=0; outfile_sum<<users[i].sum<<" "; } } int ATM::log_in() //输入账号和密码对应后登录成功,最多尝试输入3次 { string account1="0" , password1; ifstream infile_account ("d0.dat",ios::in),infile_password("d1.dat",ios::in); int n=3,flag=1,m; cout<<"请输入银行账户的账号:"; cin>>account; for(int i=0;i<9999 ;i++) // !!!!!!!!!!!!!!!缺少条件 { infile_account>>account1; if(account1==account) { m=i; flag--; break; } } if(flag==1) cout<<"无此账号",exit(1); if(flag==0) cout<<"下一步,"; for(; n>=0;) { cout<<"请输入密码:"; cin>>password; infile_password>>password1; if(password==password1) { cout<<"登录成功"<<endl; break; } else { cout<<"账号与密码不匹配,你还有"<<n<<"次尝试次数"<<endl; n--; if(n<0) { cout<<"次数用尽"<<endl; return 0; } } } } void ATM::deposit() { int add; cout<<"请输入要存入ATM机的钱数(仅支持人民币的面额为100元,即输入整百的数字):"; cin>>add; sum=sum+add; } void ATM::withdrawal() { int add; cout<<"请输入要取出ATM机的钱数(仅支持人民币的面额为100元,即输入整百的数字):"; cin>>add; sum=sum-add; } void ATM::balance_enquiry() { cout<<"您的余额为:"<<sum<<"元"<<endl; } void ATM::interest() { int a,income; double in,time; cout<<"0.返回"<<endl; cout<<"1.活期存款-0.35%"<<endl; cout<<"2.定期存款三个月-1.10%"<<endl; cout<<"3.定期存款半年-1.30%"<<endl; cout<<"4.定期存款一年-1.50%"<<endl; cout<<"5.定期存款二年-2.10%"<<endl; cout<<"6.定期存款三年-2.75%"<<"\n"<<endl; cout<<"请选择存款类型"<<endl; cin>>a; switch(a){ case 0 :in=0;break; case 1: in=0.0035;break; case 2: in=0.011,time=0.25;break; case 3: in=0.013,time=0.5;break; case 4: in=0.015,time=1;break; case 5: in=0.021,time=2;break; case 6: in=0.0275,time=3;break; } cout<<"请输入存入钱数:"; cin>>income; if(in==0) ; else cout<<"可获利息"<<income*in*time<<"元"<<endl; } int main() { ATM a1("1","1","1",'1',"1","1","1",1); a1.build(); a1.log_in(); return 0; }[local]2[/local]
新建文本文档.zip
(2.17 KB)