?? function.h
字號(hào):
#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("please accept the money!\n");
return flag;
}
else//活期
{
flag=user.DrawMoney(num,finteres,currentmonth);
if(flag==true)
printf("please accept the money!\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("The money has been added into your account!\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 try again!\n");
return false;
}
month++;
printf("A month has passed...\n");
return true;
}
bool addUser(FILE* data, avlTree & root, int curmon)
{
printf("Please enter the new account:\n");
int acc;
scanf("%d",&acc);
Index tmp;//臨時(shí)查找變量,account是被查的值,pos內(nèi)容不關(guān)心
tmp.account=acc;
avlNode *tmp1;
tmp1=root.findValue(tmp);//找到變量
if(tmp1){
printf("The account has already existed,return...\n");
return false;
}
Item tmp2;//新增加的帳號(hào)
int tmp3;//確認(rèn)密碼
int tmp4;
while(1){
printf("Please input the password:");
scanf("%d", &tmp3);
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:\n");
char tmp5;
scanf("%c",&tmp5);
if(tmp5=='f' || tmp5=='u'){
tmp2.type=tmp5;
break;
}
else
printf("The type is not proper!\n");
}
tmp2.account=acc;
tmp2.deposit=0;
tmp2.month=curmon;
fseek(data,0,SEEK_END);//加在最后
int pos=ftell(data)/LENGTH;//應(yīng)該的位置,LENGTH在Item里定義
tmp2.Fout(pos,data);//寫入database
//插入avl樹中
Index tmp6;
tmp6.account=acc;
tmp6.pos=pos;
root.add(tmp6);
printf("The insert operation succeed!\n");
return true;
}
bool deleteUser(FILE* data, avlTree & root)
{
printf("Please input the account of the user you want to delete:\n");
int acc;
scanf("%d",&acc);
Index tmp;//臨時(shí)查找變量,account是被查的值,pos內(nèi)容不關(guān)心
tmp.account=acc;
avlNode *tmp1;
tmp1=root.findValue(tmp);//找到變量
if(!tmp1){
printf("The account is not existed!\n");
return false;
}
if(root.remove(tmp)){//從索引中刪除
Item tmp2;
tmp2.account=999999999;tmp2.password=0;tmp2.deposit=0;tmp2.type='u';tmp2.month=0;
tmp2.Fout( (tmp1->value).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)//還是直接寫到函數(shù)里
{
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){
printf("Please input the new password:\n");
scanf("%d",&pass1);
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!You can choose the operations youwant to do.\n");
return true;
}
else
{
printf("The password has not changed!\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);
fscanf(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);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -