zoukankan      html  css  js  c++  java
  • 活期储蓄账目管理系统

    基本要求:实现储户开户、销户、存入、支出等活动。要求能查找储户的账户,实现存款、
    取款、插入、删除等操作。具体功能如下:
    (1)实现储户开户。
    (2)实现储户销户。
    (3)向某账户存款。
    (4)从某账户取款。
    (5)排序显示所有账户信息。
    (6)查询某账户余额。
    (7)查询某账户交易记录。

      1 #include<iostream>
      2 #include<fstream>
      3 #include<iomanip>
      4 #include<string.h>
      5 using namespace std;
      6 #include<windows.h>
      7 #define MAX 500
      8 
      9 struct record
     10 {
     11     char name[20];
     12     char cardno[20];
     13     int card;
     14     char money[20];
     15 };
     16 
     17 //用户类,包含用户的姓名,卡号,密码,账户余额
     18 class account
     19 {
     20 public:
     21     char name[50];
     22     int card;
     23     int password;
     24     float balance;
     25     account(){card=0;password=123456;balance=0;};
     26     friend istream& operator >>(istream& in,account &temple);
     27     friend ostream& operator <<(ostream& out,account &temple);
     28 };
     29 
     30 //重载输入运算符
     31 istream& operator >>(istream& in,account &temple)
     32 {
     33     cout<<"姓名    卡号     密码   开户金额"<<endl;
     34     in>>temple.name>>temple.card>>temple.password>>temple.balance;
     35     cout<<endl;
     36     return in;
     37 }
     38 
     39 //重载输出运算符
     40 ostream& operator <<(ostream& out,account &temple)
     41 {
     42     out<<temple.name<<setw(8)<<temple.card<<setw(10)<<temple.password<<setw(8)<<temple.balance<<endl;
     43     return out;
     44 }
     45 
     46 //显示所有账户的信息
     47 void display(account user[],int total)
     48 {
     49     int i,j;
     50     account templeuser;
     51     if(total==0)
     52     {
     53         cout<<"无账户信息"<<endl<<endl;
     54     }
     55     else
     56     {
     57         cout<<"所有用户信息:"<<endl;
     58         for(i=0;i<total-1;i++)
     59         {
     60             for(j=0;j<total-1-i;j++)
     61             {
     62                 if(user[j].card>user[j+1].card)
     63                 {
     64                     templeuser=user[j];
     65                     user[j]=user[j+1];
     66                     user[j+1]=templeuser;
     67                 }
     68             }
     69         }
     70         for(i=0;i<total;i++)
     71         {
     72             cout<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<""<<endl;
     73         }
     74     }
     75 }
     76 
     77 //查找卡号
     78 int searchcard(account user[],int total,int templecard)
     79 {
     80     int i=0;
     81     while((i<total)&&(user[i].card!=templecard))
     82     {
     83         i++;
     84     }
     85     if(i>total-1)
     86     {
     87         return -1;
     88     }
     89     else
     90     {
     91         return i;
     92     }
     93 }
     94 
     95 int main()
     96 {
     97     system("color f3");
     98     record c[MAX];
     99     int i,total=0,templecard,k,m;
    100     float money,templemoney;
    101     account temple,user[MAX];
    102     int select=0;
    103     do
    104     {
    105          system("cls");
    106          cout<<"*******************************"<<endl;
    107          cout<<"*     活期储蓄账目管理系统    *"<<endl;
    108          cout<<"*******************************"<<endl;
    109          cout<<"*1--------------------储户开户*"<<endl;
    110          cout<<"*2--------------------储户销户*"<<endl;
    111          cout<<"*3------------------------存款*"<<endl;
    112          cout<<"*4------------------------取款*"<<endl;
    113          cout<<"*5------------显示所有账户信息*"<<endl;
    114          cout<<"*6--------------------查询余额*"<<endl;
    115          cout<<"*7----------------查询交易记录*"<<endl;
    116          cout<<"*0------------------------退出*"<<endl;
    117          cout<<"*******************************"<<endl<<endl;
    118          cout<<"请输入您的选择:";
    119          cin>>select;
    120          switch(select)
    121          {
    122              case 1:cout<<endl<<"开户:"<<endl;
    123                     cout<<"请输入您的基本信息:"<<endl;
    124                     cin>>temple;
    125                     i=0;
    126                     while((i<total)&&(user[i].card!=temple.card))
    127                     {
    128                         i++;
    129                     }
    130                     if(i>total-1)
    131                     {
    132                         user[total]=temple;
    133                         system("cls");
    134                         cout<<"您已经成功开户!"<<endl<<"您的基本信息为:"<<endl;
    135                         cout<<"姓名    卡号    密码   账户余额"<<endl;
    136                         cout<<user[total];
    137                         total++;
    138                         system("pause");
    139                         system("cls");
    140                         {
    141                             ofstream out("user.txt",ios::app);//打开输出文件流
    142                             if(out)//如果打开成功
    143                             {
    144                                 out<<"姓名:"<<temple.name<<' '<<"卡号:"<<temple.card<<' '<<"密码:"<<temple.password<<' '<<"余额:"<<temple.balance<<""<<endl;//向文件输入信息
    145                                 out.close();//关闭
    146                             }
    147                         }
    148                         {
    149                             ofstream out("record.txt",ios::app);
    150                             if(out)
    151                             {
    152                                 out<<"姓名:"<<temple.name<<' '<<"卡号:"<<' '<<temple.card<<' '<<"存入"<<temple.balance<<""<<endl;
    153                                 out.close();
    154                             }
    155                         }
    156                     }
    157                     else
    158                     {
    159                         system("cls");
    160                         cout<<"账户已经存在,开户失败!!"<<endl;
    161                         system("pause");
    162                     }
    163                 break;
    164              case 2:cout<<endl<<"销户:"<<endl;
    165                     cout<<"请输入要注销的卡号:";
    166                     cin>>templecard;
    167                     k=searchcard(user,total,templecard);
    168                     if(k==-1)
    169                     {
    170                         system("cls");
    171                         cout<<"输入有误,账户不存在"<<endl;
    172                         system("pause");
    173                     }
    174                     else
    175                     {
    176                         system("cls");
    177                         cout<<"您的账户已经成功注销!并返还您"<<user[k].balance<<"元."<<endl;
    178                         system("pause");
    179                         {
    180                             ofstream out("record.txt",ios::app);
    181                             if(out)
    182                             {
    183                                 out<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"注销账户,并返还"<<user[k].balance<<"元."<<endl;
    184                                 out.close();
    185                             }
    186                         }
    187                         for(i=k+1;i<total;i++)
    188                         {
    189                             user[i-1]=user[i];
    190                         }
    191                         total--;
    192                         {
    193                             ofstream out("user.txt");
    194                             if(out)
    195                             {
    196                                 for(i=0;i<total;i++)
    197                                 {
    198                                     out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<""<<endl;
    199                                     out.close();
    200                                 }
    201                             }
    202                         }
    203                     }
    204                     cout<<endl;
    205                 break;
    206              case 3:cout<<endl<<"存款:"<<endl;
    207                     cout<<"请输入您的卡号:";
    208                     cin>>templecard;
    209                     k=searchcard(user,total,templecard);
    210                     if(k==-1)
    211                     {
    212                         system("cls");
    213                         cout<<"输入有误,账户不存在"<<endl;
    214                         system("pause");
    215                     }
    216                     else
    217                     {
    218                         cout<<"请输入要存入的金额:";
    219                         cin>>money;
    220                         user[k].balance=user[k].balance+money;
    221                         system("cls");
    222                         cout<<"您已经成功存入"<<money<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
    223                         {
    224                             ofstream out("record.txt",ios::app);
    225                             if(out)
    226                             {
    227                                 out<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"存入"<<money<<""<<endl;
    228                                 out.close();
    229                             }
    230                         }
    231                         {
    232                             ofstream out("user.txt");
    233                             if(out)
    234                             {
    235                                 for(i=0;i<total;i++)
    236                                 {
    237                                     out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<""<<endl;
    238                                 }
    239                                 out.close();
    240                             }
    241                         }
    242                         system("pause");
    243                     }
    244                 break;
    245              case 4:cout<<endl<<"取款:"<<endl;
    246                     cout<<"请输入您的卡号:";
    247                     cin>>templecard;
    248                     k=searchcard(user,total,templecard);
    249                     if(k==-1)
    250                     {
    251                         system("cls");
    252                         cout<<"输入有误,账户不存在"<<endl;
    253                         system("pause");
    254                     }
    255                     else
    256                     {
    257                         cout<<"请输入要取的金额:";
    258                         cin>>money;
    259                         if(user[k].balance<money)
    260                         {
    261                             cout<<"您的账户仅余"<<user[k].balance<<""<<endl;
    262                             cout<<"是否继续领取?(是按1,否按0):";
    263                             cin>>m;
    264                             if(m==0)
    265                             {
    266                                 cout<<endl;
    267                                 break;
    268                             }
    269                             else
    270                             {
    271                                 templemoney=user[k].balance;
    272                                 user[k].balance=0;
    273                                 {
    274                                     ofstream out("record.txt",ios::app);
    275                                     if(out)
    276                                     {
    277                                         out<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"取出"<<templemoney<<""<<endl;
    278                                     }
    279                                     out.close();
    280                                 }
    281                                 {
    282                                     ofstream out("user.txt");
    283                                     if(out)
    284                                     {
    285                                         for(i=0;i<total;i++)
    286                                         {
    287                                             out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<""<<endl;
    288                                         }
    289                                         out.close();
    290                                     }
    291                                 }
    292                                 system("cls");
    293                                 cout<<"您已成功取出"<<templemoney<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
    294                                 system("pause");
    295                             }
    296                         }
    297                         else
    298                         {
    299                             user[k].balance=user[k].balance-money;
    300                             {
    301                                 ofstream out("record.txt",ios::app);
    302                                 if(out)
    303                                 {
    304                                     out<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"取出"<<money<<""<<endl;
    305                                     out.close();
    306                                 }
    307                             }
    308                             {
    309                                 ofstream out("user.txt");
    310                                 if(out)
    311                                 {
    312                                     for(i=0;i<total;i++)
    313                                     {
    314                                         out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<""<<endl;
    315                                     }
    316                                     out.close();
    317                                 }
    318                             }
    319                             system("cls");
    320                             cout<<"您已成功取出"<<money<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
    321                             system("pause");
    322                         }
    323                     }
    324                 break;
    325              case 5:system("cls");
    326                     display(user,total);
    327                     system("pause");
    328                 break;
    329              case 6:cout<<endl<<"查询余额:"<<endl;
    330                     cout<<"请输入您的卡号:";
    331                     cin>>templecard;
    332                     k=searchcard(user,total,templecard);
    333                     if(k==-1)
    334                     {
    335                         system("cls");
    336                         cout<<"输入有误,账户不存在"<<endl;
    337                         system("pause");
    338                     }
    339                     else
    340                     {
    341                         system("cls");
    342                         cout<<"您的账户余额为:"<<user[k].balance<<""<<endl;
    343                         system("pause");
    344                     }
    345                 break;
    346              case 7:cout<<endl<<"查询交易记录:"<<endl;
    347                     cout<<"请输入要查询的卡号:";
    348                     cin>>templecard;
    349                     k=searchcard(user,total,templecard);
    350                     if(k==-1)
    351                     {
    352                         system("cls");
    353                         cout<<"输入有误,账户不存在"<<endl;
    354                         system("pause");
    355                     }
    356                     else
    357                     {
    358                         ifstream in("record.txt",ios::app);//打开输入文件流
    359                         if(in)//如果打开成功
    360                         {
    361                             for(i=0;i<MAX;i++)
    362                             {
    363                                 in>>c[i].name>>c[i].cardno>>c[i].card>>c[i].money;//从文件读取信息
    364                             }
    365                             system("cls");
    366                             for(i=0;i<MAX;i++)
    367                             {
    368                                 if(c[i].card==templecard)
    369                                 {
    370                                     cout<<c[i].name<<' '<<' '<<c[i].cardno<<c[i].card<<' '<<' '<<c[i].money<<endl;//显示
    371                                 }
    372                             }
    373                             in.close();//关闭
    374                             system("pause");
    375                         }
    376                     }
    377                 break;
    378          }
    379     }while(select!=0);
    380     system("cls");
    381     cout<<"欢迎使用本系统!!"<<endl;
    382     return 0;
    383 }
  • 相关阅读:
    sql server 如何查看这个数据库有多少张表并具体显示出来
    SQL Server2008 SP1安装 查找安装媒体怎么解决
    检测到在集成的托管管道模式下不适用的 ASP.NET 设置。
    sql不记得用户名跟密码怎么办
    必背系列之数据库常用语法
    select * from 多张表的用法
    SAP与Oracle ERP
    with as的用法
    IIS启动网站--HTTP错误500.21
    SqlServer2012--备份介质集不完整 ,介质集有2个介质簇但只提供了1个
  • 原文地址:https://www.cnblogs.com/xautlmx/p/3493417.html
Copyright © 2011-2022 走看看