C言語作成の銀行管理システムのキーコード
25793 ワード
一つの銀行システムの中で、一番重要なのは取引先の口座開設問題です.この部分で一日かかって分かりました.前に勉強したデータ構造がよくできていませんでした.以下はC言語で作成した口座開設です.
#include
#include
#include
#include
#include "head1.h"
#include "head2.h"
void kaihu(User *head)
{
system("cls");
char flag = 'y';
count1 = 1;
User *p1;
FILE *fp2 = NULL; //
user = (User *)malloc( sizeof(struct User)); // user
head->next = user; // user head
if((fp2 = fopen("user.txt","a+")) == NULL)
{
printf("The file open error!!!");
getchar();
exit(0);
}
printf("
\t\t
");
while(flag == 'y' || flag == 'Y')
{
int m=rand();
printf("
\t\t :");
scanf("%s",user->username); //
encrypt(user->userpswd);
/*printf("
\t\t :");
scanf("%s",user->userpswd); // */
srand(time(0)); //
user->userID = m%10000+1000000000; // userID
printf("
\t\t ( 20 ):");
scanf("%f",&user->usermoney); //
printf("
\t\t :");
scanf("%s",user->user_firsttime); //
user->next = NULL; // ,user
fprintf(fp2,"%d %s %f %s %s
",user->userID,user->username,user->usermoney,user->userpswd,user->user_firsttime); // user.txt
printf(" , y, n: ");
scanf(" %c",&flag);
// flag,
if(flag == 'n' || flag == 'N') //
{
printf("
\t\t , :
");
user = head->next; // user,user
while(user) // user
{
printf("
\t\t\t :%s :%d :%.2f
",user->username,user->userID,user->usermoney); // 、 、
user = user->next; //
}
fclose(fp2);
getch();
front1(head);
}
else if(flag == 'y' || flag == 'Y') //
{
count1 ++; //
p1 = (User *)malloc( sizeof(struct User)); // p1
p1->next = NULL; //p1
user->next = p1; //user p1, user p1
user = p1; //p1 user, user p1 ,
}
else // flag y n,
{
if(flag!='Y' && flag!='y'){
printf("
\t\t*** ***
");
exit(0);
}
}
}
}
また、後序完備版の機能コードを添付します.#include
#include
#include
#include
#include
#include
struct bank{
char name[20];
int num;
char pswd[100];
int money;
};
struct bank person[1000];
int i,j,jine,num,k=0;
//-------------------- ----------------------
void setpswd(char pswd[])
{
int x=0;
printf("\t\t\t :");
while(1){
pswd[x]=getch();
if(pswd[x]!='\r'){
printf("*");
++x;
}
else break;
}
pswd[x]='\0';
printf("
");
}
//------------------ ------------------------
int putnum(){
int resultnum=-1;
// char pswd[100];
while(resultnum<0){
printf("\t\t\t :");
scanf("%d",&num);
for(i=0;i<1000;i++){
if(person[i].num==num){
return resultnum=1;
// break; return , , break
}
else if(person[i].num==0){
printf("\t\t\t ,
"); //system("cls");
Sleep(1000);
fflush(stdin);
system("cls");
printf("
");
break;
// return resultnum=-1;
}
}
}
}
//------------------ ----------------------
void putpswd(){
int z=0;
char pswd[100];
fflush(stdin);
while(1){
setpswd(pswd);
if(strcmp(person[i].pswd,pswd)==0)
break;
else{
z++;
if(z==3){
printf("\t\t\t , !
");
for(int i=0;i<3;i++)
{
Sleep(1000);
printf("\t\t\t\t\t %d\r",3-i);
}
exit(0);
}
printf("\t\t\t , !
");
}
}
}
//---------------------- ----------------------
void kaihu(){
system("cls");
printf("
");
printf("\t\t\t :");
scanf("%s",person[k].name);
setpswd(person[k].pswd);
while(1){
printf("\t\t\t ( !):");
scanf("%d",&jine);
fflush(stdin);
if(jine>=1)break;
else printf("\t\t\t , !
");
}
person[k].money+=jine;
// printf("\t\t\t %s
",person[k].pswd);
// scanf("%d",&person[k].pswd);
srand(time(0)); //
int m=rand();
person[k].num=m%10000+1000000000;
printf("\t\t\t :%d
",person[k].num); //
printf("\t\t\t , :
");
printf("\t\t\t %s %d %d
",person[k].name,person[k].num,person[k].money);
printf("\t\t\t !");
k++;
getch();
system("cls");
}
//------------------------ -----------------
void cunkuan(){
system("cls");
printf("
");
int y=putnum(); fflush(stdin);
putpswd();
printf("\t\t\t :");
scanf("%d",&jine);
person[i].money+=jine;
printf("\t\t\t :");
printf("%d
",person[i].money);
printf("\t\t\t !");
getch();
system("cls");
}
//------------------------ -----------------
void chaxun(){
system("cls");
printf("
");
int y=putnum();
putpswd();
printf("\t\t\t :");
printf("%d
",person[i].money);
printf("\t\t\t !");
getch();
system("cls");
}
//------------------------ -----------------
void qukuan(){
system("cls");
printf("
");
int y=putnum();
while(1){
printf("\t\t\t ");
scanf("%d",&jine);
if(jine>person[i].money)
printf("\t\t\t , !
");
else break;
}
person[i].money-=jine;
printf("\t\t\t :");
printf("%d
",person[i].money);
printf("\t\t\t !");
getch();
system("cls");
}
//------------------------ -----------------
int zhuanzhang(){
system("cls");
printf("
");
int num1,c;
putnum();
putpswd();
printf("\t\t\t :");
scanf("%d",&num1);
for(j=0;j<1000;j++){
if(person[j].num==num1)
break;
if(person[j].num==0){
j=0;
printf("\t\t\t , !
");
printf("\t\t\t :");
scanf("%d",&num1);
}
}
if(num!=num1){
while(1){
printf("\t\t\t ");
scanf("%d",&jine);
if(jine>person[i].money)
printf("\t\t\t , !
");
else break;
}
}
else {
printf("\t\t\t , !");
getch();
system("cls");
return 0;
}
printf("\t\t\t :
");
printf("\t\t\t %s %d %d",person[j].name,person[j].num,jine);
printf("
\t\t\t Y/y, N/n");
while(1){
c=getch();
if(c=='N'||c=='n'){
system("cls");
break;
}
if(c=='Y'||c=='y'){
person[i].money-=jine;
person[j].money+=jine;
printf("
\t\t\t , ( Y/y , )");
c=getch();
if(c=='Y'||c=='y'){
printf("\t\t\t :%d",person[i].money);
printf("
\t\t\t !");
getch();
system("cls");break;
}
else system("cls");break;
}
else printf("
\t\t\t , :");
}
}
//--------------------------- -------------------------------
void zhujiemian()
{
int i;
while(1)
{
printf("\t\t************************************************
");
printf("\t\t* *
");
printf("\t\t* *
");
printf("\t\t* *
");
printf("\t\t************************************************
");
printf("\t\t 1.
");
printf("\t\t 2.
");
printf("\t\t 3.
");
printf("\t\t 4.
");
printf("\t\t 5.
");
printf("\t\t 6.
");
printf("\t\t :");
scanf("%d",&i);
if(1<=i&&i<=6){
switch(i)
{
case 1:kaihu();break;
case 2:cunkuan();break;
case 3:chaxun();break;
case 4:qukuan();break;
case 5:zhuanzhang();break;
case 6:exit(0);break;
}break;
}
else{
printf("\t\t\t , !
");
Sleep(1000);
fflush(stdin);
system("cls");
}
}
zhujiemian();
}
//-----------------------main ---------------------------------
int main(void)
{
int j;
system("color 1E");
printf("
");
printf("\t\t\t %c ",1);
printf(" !
");
printf(" , ...
");
printf("===============================================================================\r");
for(j=0;j<80;j++){
Sleep(100);
printf(">");
}
system("cls");
zhujiemian();
return 0;
}