Think:
姑且算是 第一个 完整的 小应用程序吧TAT。。。 主要的函数都写在blog里了
。对于 账户合法的判定 我是直接写在输入后, 没有单独 写函数, 新手多多见谅啦~
PS
我没有将 运行结果输出为文本格式, 也就是说 这是一次性的, 如果有需求可自行增加输出文本。运行的颜色贼难看, 颜色你们自行修改吧~~~
颜色查询的 方法是 system(“color 0#ffff”);
这几周都会更新一些小程序 例如
1.黑白棋 2.推箱子 3.飞行棋
主要用到的头文件有
- #include 《stdio.h》——————使用一般输入输出函数
- #include 《string.h》——————使用字符串函数对录入的字符串数据进行节选或转化类型等操作
- #include “windows.h” ——————使用光标移动函数或转化程序界面函数等完成一半特效
主要用到的函数有:
- strcpy(a, b) ———— 字符串比较函数
- Sleep(50) ————— 是本程序停止运行50ms
- system(“cls”) ————清屏
- system(“pause”) ————按任意键继续
- system(“color 9E”) ————— 运行9E颜色
基本框架如下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include<iostream>
using namespace std;
struct User
{
int IDcard; //卡号
char Username[20]; //开户名
char Password[20]; //开户密码
double Money; //余额
int status; //开户状态
} users[100]; //100 users
int cnt; //标记用户ID数
void Welcome(); //欢迎界面
void DISPLAY(); //功能界面
void Addnewcount(); //开户界面
void ChangeMoney(); //登陆银行ID
void newpage(int i); //金额改动界面 包括(存款,取款,转账,查询)
void Distroyacount();//销户界面
void loseacount(); //挂失和解挂界面
int END();//结束界面
案例需求
储蓄业务越来越走进人们的生活。代发工资、代缴水电费、代缴电话费等业务极大的方便了人们的日常生活。越来越多的人们也开始使用银行业务、储蓄业务,同时银行储蓄客户越来越多。银行还在使用手工记帐,由于手工记帐工作效率非常低,通常有储户等待,排成长龙的现象,同时这给工作人员增加了非常大的负担和额外的工作负荷,也给银行的发展带来了严重的制约和压力,银行储蓄信息化已经到了不解决不行的地步。
系统的具体需求:
银行操作员输入用户名密码后,登录本系统(默认银行操作员用户名密码都为admin)。
银行操作员通过本系统为储蓄用户进行开户操作。
银行操作员根据储蓄用户要求,通过本系统存入存款。
银行操作员根据储蓄用户要求,通过本系统完成取款业务操作。
银行操作员通过本系统查询储蓄用户的余额。
银行操作员根据储蓄用户要求,通过本系统完成销户业务操作。
储蓄用户的帐户信息保存到文件
完整代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include<iostream>
using namespace std;
struct User
{
int IDcard; //卡号
char Username[20]; //开户名
char Password[20]; //开户密码
double Money; //余额
int status; //开户状态
} users[100]; //100 users
int cnt; //标记用户ID数
void Welcome(); //欢迎界面
void DISPLAY(); //功能界面
void Addnewcount(); //开户界面
void ChangeMoney(); //登陆银行ID
void newpage(int i); //金额改动界面 包括(存款,取款,转账,查询)
void Distroyacount();//销户界面
void loseacount(); //挂失和解挂界面
int END();//结束界面
int main()
{
cnt = 0;
system("color 9E");
Welcome();
return 0;
}
void Welcome()
{
int percent = 0;
char a[105];
char PW[105];
printf("************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请输入您的信息 **\n");
printf("** **\n");
printf("************************************\n");
printf("请输入管理员名:");
scanf("%s",a);
printf("请输入管理员密码:");
scanf("%s",PW);
if(strcmp(a,"admin") != 0 || strcmp(PW,"admin") != 0)
printf("用户不存在或密码错误\n");
else
{
printf(" Loading \n");
while(1)
{
percent ++;
Sleep(10);
if(percent % 20 == 0)
printf("***");
if (percent == 100)
break;
}
printf("\n");
system("pause");
system("cls");
DISPLAY();
}
}
void DISPLAY()
{
int key;
printf("************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请输入您的选择 **\n");
printf("** <1>存款 * <4>开户 * <7>挂失 **\n");
printf("** <2>取款 * <5>销户 * <8>解挂 **\n");
printf("** <3>查询 * <6>转账 * <0>退出 **\n");
printf("************************************\n");
printf("请输入您的选择:");
scanf("%d",&key);
if (key == 1 || key == 2 || key == 3 || key == 6)
{
printf("Loading...Please wait.\n");
Sleep(1500);
system("cls");
ChangeMoney();
}
if (key == 4)
{
printf("Loading...Please wait.\n");
Sleep(1500);
system("cls");
Addnewcount();
}
if (key == 5)
{
printf("Loading...Please wait.\n");
Sleep(1500);
system("cls");
Distroyacount();
}
if (key == 7 || key == 8)
{
printf("Loading...Please wait.\n");
Sleep(1500);
system("cls");
loseacount();
}
if (key == 0)
{
printf("Loading...Please wait.\n");
Sleep(1500);
system("cls");
END();
}
}
void Addnewcount()
{
char str[105], str1[105], str2[105];
printf("************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请输入您的开户信息 **\n");
printf("** **\n");
printf("** <0>返回 **\n");
printf("************************************\n");
printf("请输入您的账户名:");
scanf("%s",str);
if(strcmp(str, "0") == 0)
{
printf(" Loading ");
Sleep(2000);
system("pause");
DISPLAY();
}
strcpy(users[cnt].Username , str);
printf("请输入您的密码:");
scanf("%s",str1);
printf("请再次输入您的密码:");
scanf("%s",str2);
if(strcmp(str1, str2) != 0)
{
printf("Wrong Passworld!\n");
system("pause");
Addnewcount();
}
else
users[cnt].status = 1;
users[cnt].IDcard = cnt;
strcpy(users[cnt].Password , str1);
cnt ++;
system("cls");
DISPLAY();
}
void ChangeMoney()
{
int i;
char str[105], str1[105];
printf("******************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请登陆您的银行账号 **\n");
printf("** **\n");
printf("** <0>返回 **\n");
printf("******************************************\n");
printf("请输入您的账户名:");
scanf("%s",str);
for (i = 0; i <= cnt - 1; i ++)
{
if (strcmp(users[i].Username, str) == 0)
break;
}
printf("请输入您的密码:");
scanf("%s",str1);
if (strcmp(users[i].Password, str1) != 0)
{
printf("Wrong Passworld!\n");
system("pause");
ChangeMoney();
}
else
{
newpage(i);
}
if(strcmp(str, "0") == 0)
{
printf(" Loading ");
Sleep(2000);
system("pause");
DISPLAY();
}
}
void newpage(int i)
{
printf("******************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请选择您的金额服务 **\n");
printf("** **\n");
printf("** <1>存款 * <2>取款 * <3>查询 * <4>转账**\n");
printf("** <0>返回 **\n");
printf("******************************************\n");
printf("请选择您的金额服务:");
int n;
scanf("%d", &n);
printf("账号:%d 用户名:%s 余额:%lf\n", users[i].IDcard, users[i].Username, users[i].Money);
if (users[i].status == 1)
printf("状态 正常\n");
else
printf("状态: 异常\n");
if(n == 1)
{
printf("请选择您的存款金额:");
int num;
scanf("%d",&num);
users[i].Money = users[i].Money + num;
printf(" Loading \n");
Sleep(2000);
printf(" 存款成功 \n");
printf("您当前余额:%.2lf\n", users[i].Money);
}
if(n == 2)
{
printf("请选择您的取款金额:");
int num;
scanf("%d",&num);
users[i].Money = users[i].Money - num;
printf(" Loading \n");
Sleep(2000);
printf(" 取款成功 \n");
printf("您当前余额:%lf\n", users[i].Money);
}
if(n == 3)
{
printf(" Loading \n");
Sleep(2000);
printf("您当前余额:%.4lf\n", users[i].Money);
}
if(n == 4)
{
int j, num;
printf("请选择您的转账金额:");
scanf("%d",&num);
printf("请输入转账对象的ID:");
scanf("%d",&j);
users[i].Money = users[i].Money - num;
users[j].Money = users[j].Money + num;
printf(" Loading \n");
Sleep(2000);
printf(" 转账成功 \n");
printf("您当前余额:%.2lf\n", users[i].Money);
}
if(n == 0)
{
printf(" Loading \n");
Sleep(2000);
system("pause");
DISPLAY();
}
printf("\n\n\n\n");
DISPLAY();
}
void Distroyacount()
{
printf("******************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请选择您的销户服务 **\n");
printf("** <0>返回 **\n");
printf("******************************************\n");
int i;
char PW[105];
printf("请输入销户ID:");
scanf("%d",&i);
printf("请输入ID密码:");
scanf("%s",PW);
if(strcmp(PW, users[i].Password) != 0)
{
printf("Wrong password!\n");
system("pause");
Distroyacount();
}
else
{
printf(" Loading \n");
Sleep(3000);
strcpy(users[i].Username , "NULL");
strcpy(users[i].Password , "NULL");
users[i].Money = 0;
printf(" 销户成功 \n");
}
printf("\n\n\n\n");
DISPLAY();
}
void loseacount()
{
int n, i;
char PW[105];
printf("******************************************\n");
printf("** 欢迎使用 **\n");
printf("** 请选择您的挂失服务 **\n");
printf("** <1>挂失 * <2>解挂 * <0>返回 **\n");
printf("******************************************\n");
printf("\n");
printf("选择服务:");
cin >> n;
if(n == 0)
{
printf(" Loading \n");
Sleep(2000);
system("pause");
DISPLAY();
}
else if(n == 1)
{
printf("请输入挂失ID:");
scanf("%d",&i);
printf("请输入ID密码:");
scanf("%s",PW);
if(strcmp(PW, users[i].Password) != 0)
{
printf("Wrong password!\n");
system("pause");
loseacount();
}
else
{
printf(" Loading \n");
Sleep(3000);
users[i].status = 0;
printf(" 挂失成功 \n");
}
}
else if(n == 2)
{
printf("请输入解挂ID:");
scanf("%d",&i);
printf("请输入ID密码:");
scanf("%s",PW);
if(strcmp(PW, users[i].Password) != 0)
{
printf("Wrong password!\n");
system("pause");
loseacount();
}
else
{
printf(" Loading \n");
Sleep(3000);
users[i].status = 1;
printf(" 解挂成功 \n");
}
}
printf("\n\n\n\n");
DISPLAY();
}
int END()
{
printf("******************************************\n");
printf("** 欢迎再次使用 **\n");
printf("** **\n");
printf("** ----By 棺木酥 **\n");
printf("******************************************\n");
system("pause");
return 0;
}