?? function.h
字號:
#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(please input the integers):\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(please input the integers):\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 origin 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 + -