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

📄 function1

📁 这是一个银行账户的管理程序
💻
字号:
#include "avlTree.h"

bool checkpass(Item & user,int pw)
{
	if(user.password==pw)
		return true;
	else return false;
}

bool getMoney(Item & user, double finteres, double uinteres, int currentmonth)
{
	int num;
	user.Display();
	printf("please enter the amount of money that you want to get:\n");
	scanf("%d",&num);
	bool flag;
	if(user.type=='u')//定期
	{
		flag=user.DrawMoney(num,uinteres, currentmonth);
	
		if(flag==true)
			printf("success!\n");
		return flag;
	}
	else//活期
	{
		flag=user.DrawMoney(num,finteres,currentmonth);
	
		if(flag==true)
			printf("success!\n");
		return flag;
	}
}

bool saveMoney(Item & user, double finteres, double uinteres, int currentmonth)
{
	int plus;
	bool flag;
	printf("please enter the amount of money that you want to save:\n");
	scanf("%d",&plus);
	if(user.GetType()=='f')
		flag=user.AddMoney(plus,finteres,currentmonth);
	else
		flag=user.AddMoney(plus,uinteres,currentmonth);
	if(flag)
		printf("success!\n");
	else
		printf("The operation failed,please try again!\n");
	return flag;
}

void Check(Item & user, int currentmonth)//查看信息
{
	printf("Your account is:%d\n",user.account);
	printf("Your deposit is:%.2lf\n",user.deposit);
	printf("The type of your deposit is:%c\n",user.type);
	printf("The time of your deposit is:%d months\n",currentmonth-user.month);

}

void store(FILE* b, avlNode * pNode,Item & user)
{
	user.Fout((pNode->value).pos,b);
	return;
}

bool changeTime(int &month)
{
	if(month<0)
	{
		printf("The time is illegal,please check the database!\n");
		return false;
	}
	month++;
	printf("A month has passed...\n");
	return true;
}

bool addUser(FILE* data, avlTree & root, int curmon)
{
	int acc;
	while(1){
		printf("Please input a new account:");
		scanf("%d",&acc);
		if(acc>=1000000000)
			printf("Please input a account within 9 digits\n");
		else 
			break;
	}
	Index tmp;//临时查找变量,account是被查的值,pos内容不关心
	tmp.account=acc;
	avlNode *tmp1;
	tmp1=root.findValue(tmp);//找到变量
	if(tmp1){
		printf("The account has already existed,return...\n");
		return false;
	}

	Item tmp2;//新增加的帐号
	int tmp3;//确认密码
	int tmp4;
	while(1){
		while(1){
			printf("Please input a password:");
			scanf("%d", &tmp3);
			if(tmp3>=1000000)
				printf("Please input a password within 6 digits\n");
			else break;
		}
		printf("Please input the password again:");
		scanf("%d",&tmp4);
		if(tmp4==tmp3){
			tmp2.password=tmp4;
			printf("The password has been set.\n");
			break;
		}
		else
			printf("The second time input is not identical with the first one!\n");
	}
	while(1){
		printf("Please input the type of the deposit: 'u' for unfixed deposit && 'f' for fixed deposit:");
		char tmp5[10];
		scanf("%s",tmp5);
		if(tmp5[0]=='f' || tmp5[0]=='u'){
			tmp2.type=tmp5[0];
			break;
		}
		else
			printf("The type is not right!\n");
	}

	tmp2.account=acc;
	tmp2.deposit=0;
	tmp2.month=curmon;
	fseek(data,0,SEEK_END);//加在最后
	int pos=ftell(data)/LENGTH;//应该的位置,LENGTH在Item里定义
	tmp2.Fout(pos,data);//写入database

	//插入avl树中
	Index tmp6;
	tmp6.account=acc;
	tmp6.pos=pos;
	root.add(tmp6);
	printf("The insert operation succeed!");
	return true;
}


bool deleteUser(FILE* data, avlTree & root)
{
	printf("Please input the account of the user you want to delete:");
	int acc;
	scanf("%d",&acc);
	Index tmp;//临时查找变量,account是被查的值,pos内容不关心
	tmp.account=acc;
	avlNode *tmp1;
	tmp1=root.findValue(tmp);//找到变量
	if(!tmp1){
		printf("The account is not existed!\n");
		return false;
	}
	int pos=(tmp1->value).pos;

	if(root.remove(tmp)){//从索引中删除
		Item tmp2;
		tmp2.account=999999999;tmp2.password=0;tmp2.deposit=0;tmp2.type='u';tmp2.month=0;
		tmp2.Fout( pos,data);
		printf("The delete operation succeed!\n");
		return true;
	}
	else{
		printf("The delete operation did not succeed!\n");
		return false;
	}
}

void findUser(FILE* a,avlNode* pNode,Item & user)//还是直接写到函数里
{
	user.Fin((pNode->value).pos,a);
	return;
}


bool changePW(Item & user)
{
	bool success;
	int pass1,pass2;
	printf("Please input the original password:\n");
	scanf("%d",&pass1);
	if(user.CheckPass(pass1)==true)
	{
		while(1){
			while(1){
				printf("Please input a new password:\n");
				scanf("%d",&pass1);
				if(pass1>=1000000)
					printf("please input a password within 6 digits\n");
				else
					break;
			}
			printf("Please input the password again:\n");
			scanf("%d",&pass2);
			if(pass1!=pass2){
				printf("The second time input is not identical with the first one!\n");
				continue;
			}
			else
				success=user.ChangePass(pass1);
			if(success==true)
			{
				printf("Succeed!\n");
				return true;
			}
			else
			{
				printf("Something wrong with the system,The password has not changed! please try later.\n");
				return false;
			}
		}
	}
	else
		printf("The original password is wrong!\n");
	return false;
}

void ReBuildIndex(FILE* a, avlNode * root)
{
	if(root==NULL)
		return;
	ReBuildIndex(a, root->leftptr);
	fprintf(a, "%d %d\n",(root->value).account,(root->value).pos);
	ReBuildIndex(a, root->rightptr);
}

void ChangeInterestTxt(int adaccount, int adpassword, double interestForFix, double interestForUnfix, int currentmonth)
{
	FILE* e=fopen("interest.txt","w+");
	fprintf(e,"%d\n",adaccount);
	fprintf(e,"%d\n",adpassword);
	fprintf(e,"%lf\n",interestForFix);
	fprintf(e,"%lf\n",interestForUnfix);
	fprintf(e,"%d\n",currentmonth);
	fclose(e);
}

void displayAll(FILE* infile, FILE* out, avlNode *root)
{
	if(root->leftptr!=NULL)
		displayAll(infile, out, root->leftptr);
	Item tmp;
	tmp.Fin( (root->value).pos, infile);
	fprintf(out, "%09d %.2lf %c %d\n",tmp.account ,tmp.deposit ,tmp.type ,tmp.month);
	if(root->rightptr!=NULL)
		displayAll(infile, out, root->rightptr);
	
}

⌨️ 快捷键说明

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