⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kh.cpp

📁 关于银行管理系统的开户模块
💻 CPP
字号:
#include <iostream.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h> 
#include <shlobj.h> 
#include <time.h>
#include <conio.h> 
#include <time.h>
class zh//定义账户类及其成员
{      
    public:
     char ID[19];
     char Name[9];
     float Money;
     char Password[7];
     int year;
     int month;
     int day; 
     
};//实例化对象
zh p,p2;
bool inputId()   //身份证号码验证         
{
     cout<<"请输入身份证号:";
     cin>>p.ID;
     if(strlen(p.ID)!=18)
	 {
          cout<<"输入有误!\n";
          return true;
	 }
    // return false; 
     int i=0;
     while(p.ID[i])
	 {
          if(!isdigit(p.ID[i]))
		  {  
			  if(p.ID[17]=='x')
			  {
	             return false;
			  }
          cout<<"存在非法字符!\n";
          return true;
	  }
       else
	   {
		   i++;
            continue;
	   }
	   
	 }
	 return false;	 
}
bool inputName()//姓名验证
{
     cout<<"请输入姓名:";
     cin>>p.Name;
     if(strlen(p.Name)>8)
	 {
      cout<<"姓名长度有误!";
      return true;
	 }
     return false;
}
bool inputPassword()//密码验证
{
     cout<<"请输入密码:";
	 cin>>p.Password;        //密码
     if(strlen(p.Password)>6)
	 {
       cout<<"Password长度有误";
       return true;
	 }
     //return false;
	 cout<<"请再次输入密码以确认:";
	 char pwd[7];
     cin>>pwd;
     if(strcmp(p.Password,pwd))
	 {
       cout<<" 确认密码有误!";
       return true;
	 }
     return false;
}
bool inputMoney()//开户金额验证
{
      cout<<"请输入开户金额:";
      cin>>p.Money;
      if(p.Money<10)
	  {
       cout<<"开户金额不足!";
       return true;
	  }
      return false;
}
void getTime()//获取系统时间
{
     time_t t;
	 t=time(NULL);
	 tm *T=gmtime(&t);
	 int year=T->tm_year+1900;
	 int month=T->tm_mon+1;
	 int day=T->tm_mday;
	 int hour=T->tm_hour+8;
	 int min=T->tm_min;
	 int sec=T->tm_sec;
	 cout<<"开户时间:"<<endl;
	 cout<<year<<"年"<<month<<"月"<<day<<"日"<<hour<<":"<<min<<":"<<sec<<endl;
}
void main()
{	
   system("cls"); //	清屏
   bool xh;
   do 
       xh=inputId();//输入身份证号并验证
   while (xh);    
   do 
       xh=inputName();//输入姓名并验证      
	while (xh);
   do 
       xh=inputPassword();//输入密码并验证确认
   while (xh);
   do 
       xh=inputMoney();//输入开户金额
   while (xh);//验证当前身份证是否开户
   FILE *f; 
   f=fopen("C:\\aa.txt","r"); 
   if(f==NULL)
   {
        f=fopen("C:\\aa.txt","a");
        fwrite(&p,sizeof(zh),1,f);
        fclose(f);
        MessageBox(0,"开户成功!","提示",0);
        return;
   }
   while(!feof(f))
   {
        fread(&p2,sizeof(zh),1,f);
        if(!strcmp(p.ID,p2.ID))
		{
            MessageBox(0,"此帐号已开户","提示",0);
            fclose(f);
            return;
		}  
   }
   f=fopen("C:\\aa.txt","a");
   fwrite(&p,sizeof(zh),1,f);
   fclose(f);   
   getTime();//获取系统当前日期
   MessageBox(0,"开户成功!","提示",0);
  //exit;                 
                      
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -